Chris Hirsch
2011-Nov-30 20:29 UTC
[Puppet Users] Can I serve a template depending on if it exists like I can a source?
Hi all, I''m trying to figure out if I can serve a certain template that matches a hostname or serve the default like I could if this was just a file. Works: file { ''/etc/yum.conf'': ensure => file, source => ["puppet://puppet/yum/yum.conf.$hostname", "puppet://puppet/yum/yum.conf"], } Trying to figure out: file {''/etc/yum.conf'': ensure => file, content => ["template("yum/yum.conf.$hostname.erb"), " template("yum/yum.conf.erb")], } There is this issue http://projects.puppetlabs.com/issues/5158 that seems related but I can''t figure out if this is possible. Thanks! -- 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.
Bryant Taylor
2011-Dec-02 00:54 UTC
Re: [Puppet Users] Can I serve a template depending on if it exists like I can a source?
This works on our mysql configs with an erb file { "cluster.conf": name => "/etc/cluster/cluster.conf", owner => root, group => root, mode => 640, content => template("nmysql/cluster.conf.erb"), # notify => Service["rgmanager"], require => Package["rgmanager"], } On Wed, Nov 30, 2011 at 12:29 PM, Chris Hirsch <chris@base2technology.com>wrote:> Hi all, > > I''m trying to figure out if I can serve a certain template that matches a > hostname or serve the default like I could if this was just a file. > > Works: > file { ''/etc/yum.conf'': > ensure => file, > source => ["puppet://puppet/yum/yum.**conf.$hostname", > "puppet://puppet/yum/yum.conf"**], > } > > Trying to figure out: > file {''/etc/yum.conf'': > ensure => file, > content => ["template("yum/yum.conf.$**hostname.erb"), > " template("yum/yum.conf.erb")], > } > > There is this issue http://projects.puppetlabs.**com/issues/5158<http://projects.puppetlabs.com/issues/5158>that seems related but I can''t figure out if this is possible. > > Thanks! > > -- > 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 <puppet-users%2Bunsubscribe@googlegroups.com>. > For more options, visit this group at http://groups.google.com/** > group/puppet-users?hl=en<http://groups.google.com/group/puppet-users?hl=en> > . > >-- 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.
Darren Chamberlain
2012-Jan-05 19:04 UTC
Re: [Puppet Users] Can I serve a template depending on if it exists like I can a source?
It''s been a while since you asked this, but I didn''t see a followup; forgive the noise if you''ve already got an answer. Wolf Noble <wnoble@datapipe.com> posted a solution to this problem in September that I''ve been holding onto because I think it''s elegant: * Wolf Noble <wnoble at datapipe.com> [2011/09/01 18:45]: > Here''s what I''ve been doing, fwiw: > > file { ''nsswitch.conf'': > path => ''/etc/nsswitch.conf'', > content => inline_template( > file( > "/etc/puppet/modules/dist/ldapclient/templates/etc/nsswitch.conf.$hostname.erb", > "/etc/puppet/modules/dist/ldapclient/templates/etc/nsswitch.conf.$deviceid.erb", > "/etc/puppet/modules/dist/ldapclient/templates/etc/nsswitch.conf.$clientid.erb", > "/etc/puppet/modules/dist/ldapclient/templates/etc/nsswitch.conf.erb")), > ensure => file, > owner => root, group => 0, mode => 0644; > } > > > not sure about the elegance or lack thereof, contained within, > but it seems to work until there''s a "better way" to do it The file() function returns the contents of the first of its arguments that exists, and ignores the rest of the argument list, so this effectively does what you''re asking for. The one downside to this is that it doesn''t honor puppet:// parameters, but you could get around that by using a separate file { } resource. * Chris Hirsch <chris at base2technology.com> [2011/11/30 13:29]:> Hi all, > > I''m trying to figure out if I can serve a certain template that > matches a hostname or serve the default like I could if this was > just a file. > > Works: > file { ''/etc/yum.conf'': > ensure => file, > source => ["puppet://puppet/yum/yum.conf.$hostname", > "puppet://puppet/yum/yum.conf"], > } > > Trying to figure out: > file {''/etc/yum.conf'': > ensure => file, > content => ["template("yum/yum.conf.$hostname.erb"), > " template("yum/yum.conf.erb")], > } > > There is this issue http://projects.puppetlabs.com/issues/5158 that > seems related but I can''t figure out if this is possible.-- If you want to change the world then start by changing the world around you. -- Andy Wardley -- 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.