Nigel Kersten
2011-Mar-28 23:53 UTC
[Puppet Users] RFC on #5158: Make source/content parameters and the file/template functions consistent.
We''ve gone back and forth on this for a while, I''d like us to
get an
implementation agreed upon.
If the topic doesn''t instantly make sense to you, please visit the bug
for
an overview of our current inconsistent behavior:
http://projects.puppetlabs.com/issues/5158
Whenever an array is specified for source *or* content, we are employing the
“find first existing” heuristic.
e.g. this will use foo-$hostname if it exists, otherwise will use
foo-generic.
file { "/tmp/foo":
ensure => file,
source => ["puppet:///modules/$module_name/foo-$hostname",
"puppet:///modules/$module_name/foo-generic",],
}
We now apply the same thing to content. You can supply an array for content,
and if an element is evaluated as empty, the next element is evaluated.
file { "/tmp/foo":
ensure => file,
content => [template("$module_name/foo-$hostname.erb",
template("$module_name/foo-generic.erb",],
}
*Note*: Unlike the source => [ …] syntax, if all elements evaluate to an
empty string, we’ll create the file with an empty string for content.
You can also choose to use the file function like this (imagine we’ve solved
the problem with file() only taking absolute paths):
file { "/tmp/foo":
ensure => file,
content => [file("$module_name/foo-$hostname",
file("$module_name/foo-generic",],
}
and yes, this means you can mix and match template() and file() and explicit
strings in an array.
We’re also going to introduce a concatenation function called “cat”.
You can use it with any of the functions that return data to concatenate,
and you can use it with content like this:
file { "/tmp/foo":
ensure => file,
content => cat(template("header.erb"), "some content",
template("footer.erb")),
}
Note that there are some important differences between
cat(template("a.erb"), template("b.erb")
and
template(“a.erb”, “b.erb”)
The latter will allow you assign variables and define methods in a.erb that
are accessible to b.erb
When we provide a replacement for that functionality we will deprecate the
latter syntax.
--
Nigel Kersten
Product, Puppet Labs
@nigelkersten
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to
puppet-users+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/puppet-users?hl=en.