Marc Zampetti
2010-Aug-31 15:21 UTC
[Puppet Users] File selection for template() similar to source
I want to be able to have Puppet determine which file to use as the source of a template() call in a manner similar to the source parameter. Basically, I want to have a file resource that will use the most appropriate file for a template. While I can do: file { "file.conf" : source => [ "puppet:///module/file.conf.${hostname}", "puppet://module/file.conf.${groupname}", "puppet:///module/file.conf"], } I cannot do: file { "file.conf" : content => [ template("module/file.conf.${hostname}"), template("module/file.conf.$ {groupname}"), template("module/file.conf")] } This fails in 0.25.5 if the first file for the template call does not exist. I know I can use a case statement or selector to set a variable name, but that won''t do what I want. Basically, I want puppet to use the first file it finds for the source of the template() call, just like the source version. For some nodes, or some groups, there will be such a file, and in other cases, the default file will be used. Anyone know how to do this? The alternative would be to have some way to test if the file exists in the paths. Anyone know how to do that? This isn''t a test to see if the file exists on the client, but in the puppet repo, so in client/server mode, this would be testing if the file exists on the server. Any suggestions are greatly appreciated. -- 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.
Thomas Bellman
2010-Aug-31 15:35 UTC
Re: [Puppet Users] File selection for template() similar to source
On 2010-08-31 17:21, Marc Zampetti wrote:> I cannot do: > > file { "file.conf" : > content => [ template("module/file.conf.${hostname}"), > template("module/file.conf.$ > {groupname}"), > template("module/file.conf")] > }You can use the file() and inline_template() functions in combination: $tmpl = file("/etc/puppet/modules/mymodule/file.conf.${hostname}", "/etc/puppet/modules/mymodule/file.conf.${groupname}", "/etc/puppet/modules/mymodule/file.conf") file { "file.conf": content => inline_template($tmpl); } Note however that file() requires absolute pathnames. It does not look up files in your module path or anything, so it isn''t very convenient. I *think* there is a feature request for adding that functionality to file(), though, but I don''t have time to search for it at the moment. /Bellman -- 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.
Jeff McCune
2010-Aug-31 16:58 UTC
Re: [Puppet Users] File selection for template() similar to source
On Tue, Aug 31, 2010 at 11:35 AM, Thomas Bellman <bellman@nsc.liu.se> wrote:> On 2010-08-31 17:21, Marc Zampetti wrote: > >> I cannot do: >> >> file { "file.conf" : >> content => [ template("module/file.conf.${hostname}"), >> template("module/file.conf.$ >> {groupname}"), >> template("module/file.conf")] >> } > > You can use the file() and inline_template() functions in combination: > > $tmpl = file("/etc/puppet/modules/mymodule/file.conf.${hostname}", > "/etc/puppet/modules/mymodule/file.conf.${groupname}", > "/etc/puppet/modules/mymodule/file.conf") > file { > "file.conf": > content => inline_template($tmpl); > }You could also do this directly in the ERB template itself using File.exists? and __FILE__ as a reference point. This feels like a hack though. template() already supports concatenation, so it would be difficult to add a feature to "search" for the right file, but it would also be possible to implement a custom function to do this. -- Jeff McCune http://www.puppetlabs.com/ -- 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.
R.I.Pienaar
2010-Aug-31 17:13 UTC
Re: [Puppet Users] File selection for template() similar to source
----- "Jeff McCune" <jeff@puppetlabs.com> wrote:> You could also do this directly in the ERB template itself using > File.exists? and __FILE__ as a reference point. This feels like a > hack though. > > template() already supports concatenation, so it would be difficult > to > add a feature to "search" for the right file, but it would also be > possible to implement a custom function to do this.Ticket 1818 deals with this and I''ve written such a function http://pastie.org/666728 See recent list discussion though for fixing that pastie code for 2.6 compatibility -- R.I.Pienaar -- 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.