Can anyone tell me why this is legal: file { "/etc/cron.d": owner => "root", group => "root", mode => $operatingsystem ? { ''Solaris'' => "0755", default => "0700", } } ...And yet if I have any resource attributes below the "mode" selector statement, it will not parse? (Am I doing the right thing by having a selector in my file resource? I have a large amount of files to validate, and attributes change for many of the files, depending on the OS.) -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
Steven VanDevender
2013-Aug-05 18:12 UTC
[Puppet Users] Selector within a resource -- location & syntax
root writes: > > Can anyone tell me why this is legal: > > file { "/etc/cron.d": > owner => "root", > group => "root", > mode => $operatingsystem ? { > ''Solaris'' => "0755", > default => "0700", > } > } > > > ...And yet if I have any resource attributes below the "mode" selector > statement, it will not parse? No comma after the conditional? Like this: mode => $operatingsystem ? { ''Solaris'' => "0755", default => "0700", }, All resource attributes use comma as a separator. You can optionally leave off the final comma (although style recommendations suggest you should always end an attribute specification with a comma, mainly so that you don''t have to remember to add it if you add additional attribute specifications). > (Am I doing the right thing by having a selector in my file resource? I > have a large amount of files to validate, and attributes change for many of > the files, depending on the OS.) That is certainly one way to manage the OS-specific differences in your resources. If you have a lot of things that are always mode 755 in one OS and mode 700 in another, it may be somewhat more concise to declare a variable and use that: $dirmode = $operatingsystem ? { "Solaris" => 0755, default => 0700, } ... file { "/etc/cron.d": owner => "root", group => "root", mode => $dirmode, } -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
root
2013-Aug-08 12:00 UTC
Re: [Puppet Users] Selector within a resource -- location & syntax
This of course was the answer, thanks. It did not look "right" to me to have that comma after the closing bracket, but that is what the language requires. On Monday, August 5, 2013 2:12:38 PM UTC-4, Steven VanDevender wrote:> > > > No comma after the conditional? Like this: > > mode => $operatingsystem ? { > ''Solaris'' => "0755", > default => "0700", > }, > > All resource attributes use comma as a separator. You can optionally > leave off the final comma (although style recommendations suggest you > should always end an attribute specification with a comma, mainly so > that you don''t have to remember to add it if you add additional > attribute specifications). > > > (Am I doing the right thing by having a selector in my file resource? > I > > have a large amount of files to validate, and attributes change for > many of > > the files, depending on the OS.) > > That is certainly one way to manage the OS-specific differences in your > resources. If you have a lot of things that are always mode 755 in one > OS and mode 700 in another, it may be somewhat more concise to declare a > variable and use that: > > $dirmode = $operatingsystem ? { > "Solaris" => 0755, > default => 0700, > } > > ... > > file { "/etc/cron.d": > owner => "root", > group => "root", > mode => $dirmode, > } >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.