简体   繁体   中英

Iterating over files in Puppet (3.1)

I am looking for a dry version of the following:

Ideally it could be just an array and a loop. What is the way to go in Puppet?

class hive_cdh4::configs inherits hive_cdh4 {

  define hive_configs () {

    file { "/etc/hive/conf.rr/hive-site.xml": 
      owner   => root,
      group   => root,
      mode    => 664,
      ensure  => present,
      content => template("hive_cdh4/hive-site.xml.erb")
    }

    file { "/etc/hive/conf.rr/hive-exec-log4j.properties": 
      owner   => root,
      group   => root,
      mode    => 664,
      ensure  => present,
      content => template("hive_cdh4/hive-exec-log4j.properties.erb")
    }

    file { "/etc/hive/conf.rr/hive-log4j.properties": 
      owner   => root,
      group   => root,
      mode    => 664,
      ensure  => present,
      content => template("hive_cdh4/hive-log4j.properties.erb")
    }

  }
}

How about something like this:

define hive_config ($file_name = $title, $format = 'properties') {

  file { "/etc/hive/conf.rr/$file_name.$format":
    owner   => root,
    group   => root,
    mode    => '0664',
    ensure  => present,
    content => template("hive_cdh4/$file_name.$format.erb")
  }

}

hive_config {'hive-site':}
hive_config {'hive-exec-log4j':}
hive_config {'hive-log4j':
   format   => 'xml'
}

I tested it quickly in a Vagrant provision, and it seems to work?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM