Hi, I''m trying get Puppet to manage my snmpd instances. I have a "base" snmpd.conf constructed from a template, but some hosts require additional config. My plan was to have something like snmpd.conf.$hostname.erb in the templates directory and concatenate this with the base template. However, for the majority of hosts this file will not be present and in those cases I will get a "Could not find template" error. Is there a method to test for the presence of a file in the template directory, so I can build my template() command accordingly? Thanks, Alan -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/GSI-4uLTQXQJ. 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.
* GriffaA10 <alan.griffiths at interoute.com> [2012/06/29 05:35]:> I''m trying get Puppet to manage my snmpd instances. I have a > "base" snmpd.conf constructed from a template, but some hosts > require additional config. My plan was to have something like > snmpd.conf.$hostname.erb in the templates directory and > concatenate this with the base template. However, for the majority > of hosts this file will not be present and in those cases I will > get a "Could not find template" error.The file() function returns the content of the first file that exists, so you can use it with inline_template(): file { "/etc/snmpd.conf": ensure => "present", content => inline_template( file( "puppet:///modules/snmp/snmpd.conf.$::hostname.erb", "puppet:///modules/snmp/snmpd.conf.erb", ) ), } -- Darren Chamberlain <darren@boston.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.
----- Darren Chamberlain <darren@boston.com> wrote:> > The file() function returns the content of the first file that > exists, so you can use it with inline_template(): > > file { > "/etc/snmpd.conf": > ensure => "present", > content => inline_template( > file( > "puppet:///modules/snmp/snmpd.conf.$::hostname.erb", > "puppet:///modules/snmp/snmpd.conf.erb", > ) > ), > } >That is a wonderful tip, Darren. 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.
Great, that''s done the trick, thanks Just one thing to note. file() takes an absolute file path (i.e. /etc/puppet/modules/snmp/templates/snmpd.conf.erb). Spent a few minutes trying to figure out the error I was getting before finally RTFM. On Friday, June 29, 2012 2:04:06 PM UTC+1, Darren Chamberlain wrote:> > > * GriffaA10 <alan.griffiths at interoute.com> [2012/06/29 05:35]: > > I''m trying get Puppet to manage my snmpd instances. I have a > > "base" snmpd.conf constructed from a template, but some hosts > > require additional config. My plan was to have something like > > snmpd.conf.$hostname.erb in the templates directory and > > concatenate this with the base template. However, for the majority > > of hosts this file will not be present and in those cases I will > > get a "Could not find template" error. > > The file() function returns the content of the first file that > exists, so you can use it with inline_template(): > > file { > "/etc/snmpd.conf": > ensure => "present", > content => inline_template( > file( > "puppet:///modules/snmp/snmpd.conf.$::hostname.erb", > "puppet:///modules/snmp/snmpd.conf.erb", > ) > ), > } > > -- > Darren Chamberlain <darren@boston.com> >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/2PbYFufZmD4J. 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.
----- Original Message -----> From: "GriffaA10" <alan.griffiths@interoute.com> > To: puppet-users@googlegroups.com > Sent: Friday, June 29, 2012 3:37:29 PM > Subject: Re: [Puppet Users] Optional template files? > > Great, that''s done the trick, thanks > > Just one thing to note. file() takes an absolute file path (i.e. > /etc/puppet/modules/snmp/templates/snmpd.conf.erb). Spent a few > minutes trying to figure out the error I was getting before finally > RTFM.indeed, not ideal especially with environments. Ages ago I wrote a little function to bring to template() the same behaviour as source => [] I dont know if it still works on modern puppet but it was handy http://p.devco.net/27/ -- 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.