Istvan
Istvan

Reputation: 8562

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")
    }

  }
}

Upvotes: 1

Views: 658

Answers (1)

Peter Souter
Peter Souter

Reputation: 5190

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?

Upvotes: 1

Related Questions