Selector within a resource -- location & syntax

41 views
Skip to first unread message

root

unread,
Aug 5, 2013, 2:02:42 PM8/5/13
to puppet...@googlegroups.com
 
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.) 


 

Steven VanDevender

unread,
Aug 5, 2013, 2:12:38 PM8/5/13
to puppet...@googlegroups.com
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,
}

root

unread,
Aug 8, 2013, 8:00:15 AM8/8/13
to puppet...@googlegroups.com, ste...@uoregon.edu

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. 
Reply all
Reply to author
Forward
0 new messages