Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Puppet: Multiple files based on templates

Tags:

puppet

I have several files which I need to be created by Puppet, all based on templates. As an example:

/etc/my-project/a.ini
/etc/my-project/b.ini
/etc/my-project/c.ini

What I would like to do is to ensure all these files using one statement in Puppet. Something like this:

define myFile {
  file { "/ect/init.d/$name.ini":
    ensure  => file,
    content => template("myProject/myFiles/$name.erb"),
  }
}

myFile { ['a', 'b', 'c']: }

However, this does not seem to work (inspired by How to iterate over an array in Puppet). What am I missing there? How can I access the file name and use it, if not as $name?

like image 439
Pavel S. Avatar asked Dec 09 '13 16:12

Pavel S.


1 Answers

Your array declaration is fine, but you're actually trying to create multiple templates, all with a different filename $name.erb. You should change it to a fixed template name, like template.erb.

Another thing to make sure is that your template file is located correctly.

  • If your manifest is in a module, the template should be located at module_name/templates/template.erb and called as template("module_name/file_under_template_directory")

  • If it's a standalone manifest, you have to put the full path instead, template("fully_qualified_path_to_template_file").

Finally, if you're still encountering errors, you should update your question with the error message so we can narrow down the cause.

like image 141
xiankai Avatar answered Oct 29 '22 16:10

xiankai