I was wondering if it is possible to do a conditional inside a selector to test for the existence of a file. I currently have something like this (just an excerpt): file { smbshares: path => "/etc/samba/shares.conf", source => $hostname ? { nodename1 => "puppet:///samba/shares/nodename1.conf", nodename2 => "puppet:///samba/shares/nodename2.conf", default => "puppet:///samba/shares/default.conf", }; } The smb.conf does an include on /etc/samba/shares.conf so in order to add or create custom shares I drop a file in modules/samba/files/shares named after the hostname of the target machine and then place the corresonding line in the file block above. It works pretty well, but since the file is named after the hostname I was thinking it would be pretty slick if that part were a little more dynamic. Logically speaking it would look something like this: source => $hostname ? { [ -f puppet:///samba/shares/$hostname.conf ] => "puppet:///samba/shares/$hostname.conf", default => "puppet:///samba/shares/default.conf", }; I just can''t quite seem to come up with what the syntax would need to look. The shell syntax above is just to convey the logic I''m looking for. Any ideas, or is there a better way to do this? 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 -~----------~----~----~----~------~----~------~--~---
Thomas Bellman
2008-Nov-19 14:01 UTC
[Puppet Users] Re: existence test inside a selector ?
Robert Foreman wrote:> Logically speaking it would look something like this: > > source => $hostname ? { > [ -f puppet:///samba/shares/$hostname.conf ] => > "puppet:///samba/shares/$hostname.conf", > default => "puppet:///samba/shares/default.conf", > }; > > I just can''t quite seem to come up with what the syntax would need to > look. The shell syntax above is just to convey the logic I''m looking for. > > Any ideas, or is there a better way to do this?You need to read the documentation for the source parameter of the file type. It already supports what you want to do. /Thomas 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 -~----------~----~----~----~------~----~------~--~---
Robert Foreman
2008-Nov-19 15:11 UTC
[Puppet Users] Re: existence test inside a selector ?
Found it. Thanks. I thought I had read something like that somewhere, but I got hung with using a selector. file { "/path/to/my/file": source => [ "/nfs/files/file.$host", "/nfs/files/file.$operatingsystem", "/nfs/files/file" ] } On Wed, Nov 19, 2008 at 9:01 AM, Thomas Bellman <bellman@nsc.liu.se> wrote:> > Robert Foreman wrote: > > > Logically speaking it would look something like this: > > > > source => $hostname ? { > > [ -f puppet:///samba/shares/$hostname.conf ] => > > "puppet:///samba/shares/$hostname.conf", > > default => "puppet:///samba/shares/default.conf", > > }; > > > > I just can''t quite seem to come up with what the syntax would need to > > look. The shell syntax above is just to convey the logic I''m looking for. > > > > Any ideas, or is there a better way to do this? > > You need to read the documentation for the source parameter of the file > type. > It already supports what you want to do. > > > /Thomas 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 -~----------~----~----~----~------~----~------~--~---
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi Robert, I''m only new to puppet so I''m not sure if this is what you are after but would the folowing work? file { smbshares: path => "/etc/samba/shares.conf", source => $hostname ? { nodename1 => ["puppet:///samba/shares/nodename1.conf", "puppet:///samba/shares/default.conf"], nodename2 => ["puppet:///samba/shares/nodename2.conf", "puppet:///samba/shares/default.conf"], default => "puppet:///samba/shares/default.conf", }; } This way it would check for the file called nodename1.conf then failing that it would look for the default. Cheers, Henry Robert Foreman wrote:> I was wondering if it is possible to do a conditional inside a selectorto test for the existence of a file.> > I currently have something like this (just an excerpt): > > file { > smbshares: > path => "/etc/samba/shares.conf", > source => $hostname ? { > nodename1 => "puppet:///samba/shares/nodename1.conf", > nodename2 => "puppet:///samba/shares/nodename2.conf", > default => "puppet:///samba/shares/default.conf", > }; > } > > The smb.conf does an include on /etc/samba/shares.conf so in order toadd or create custom shares I drop a file in modules/samba/files/shares named after the hostname of the target machine and then place the corresonding line in the file block above. It works pretty well, but since the file is named after the hostname I was thinking it would be pretty slick if that part were a little more dynamic.> > Logically speaking it would look something like this: > > source => $hostname ? { > [ -f puppet:///samba/shares/$hostname.conf ] =>"puppet:///samba/shares/$hostname.conf",> default => "puppet:///samba/shares/default.conf", > }; > > I just can''t quite seem to come up with what the syntax would need tolook. The shell syntax above is just to convey the logic I''m looking for.> > Any ideas, or is there a better way to do this? > > Thanks. > > > > >-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkklHGQACgkQ9EJQnSAhy1AEoACePEs2hSThFwEueT+tiPc/eU5I vI8AnAp8WfYO+XURwHfs0rQU2DvQRB/p =b+ea -----END PGP SIGNATURE----- --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Robert Foreman
2008-Nov-20 14:20 UTC
[Puppet Users] Re: existence test inside a selector ?
I don''t know if that would work or not, but it turns out I was over complicating things. All I needed to do was this: file { smbshares: path => "/etc/samba/shares.conf", source => [ "puppet:///samba/shares/$hostname.conf", "puppet:///samba/shares/default.conf", ]; } As Thomas Bellman pointed out the file type already supports this. If you specify multiple file sources for a file then the first source that exists will be used. On Thu, Nov 20, 2008 at 3:14 AM, Henry Jenkins <henry@henryjenkins.name>wrote:> > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Hi Robert, > > I''m only new to puppet so I''m not sure if this is what you are after but > would the folowing work? > > file { > smbshares: > path => "/etc/samba/shares.conf", > source => $hostname ? { > nodename1 => ["puppet:///samba/shares/nodename1.conf", > "puppet:///samba/shares/default.conf"], > nodename2 => ["puppet:///samba/shares/nodename2.conf", > "puppet:///samba/shares/default.conf"], > default => "puppet:///samba/shares/default.conf", > }; > } > > This way it would check for the file called nodename1.conf then failing > that it would look for the default. > > Cheers, > > Henry > > > > Robert Foreman wrote: > > I was wondering if it is possible to do a conditional inside a selector > to test for the existence of a file. > > > > I currently have something like this (just an excerpt): > > > > file { > > smbshares: > > path => "/etc/samba/shares.conf", > > source => $hostname ? { > > nodename1 => "puppet:///samba/shares/nodename1.conf", > > nodename2 => "puppet:///samba/shares/nodename2.conf", > > default => "puppet:///samba/shares/default.conf", > > }; > > } > > > > The smb.conf does an include on /etc/samba/shares.conf so in order to > add or create custom shares I drop a file in modules/samba/files/shares > named after the hostname of the target machine and then place the > corresonding line in the file block above. It works pretty well, but > since the file is named after the hostname I was thinking it would be > pretty slick if that part were a little more dynamic. > > > > Logically speaking it would look something like this: > > > > source => $hostname ? { > > [ -f puppet:///samba/shares/$hostname.conf ] => > "puppet:///samba/shares/$hostname.conf", > > default => "puppet:///samba/shares/default.conf", > > }; > > > > I just can''t quite seem to come up with what the syntax would need to > look. The shell syntax above is just to convey the logic I''m looking for. > > > > Any ideas, or is there a better way to do this? > > > > Thanks. > > > > > > > > > > > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.9 (GNU/Linux) > Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org > > iEYEARECAAYFAkklHGQACgkQ9EJQnSAhy1AEoACePEs2hSThFwEueT+tiPc/eU5I > vI8AnAp8WfYO+XURwHfs0rQU2DvQRB/p > =b+ea > -----END PGP SIGNATURE----- > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---