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
?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With