On Tue, 2011-12-13 at 10:31 -0800, Kenneth Lo wrote:
> Searching old archive I find this topic:
> 
> http://groups.google.com/group/puppet-users/browse_thread/thread/187ee3897a26ae2a/32fea612e79dda80?hl=en&lnk=gst&q=puppet+case+statement+in+file+resource#32fea612e79dda80
> 
> 
> I understand that  "case statements must be outside of resource
> statements" per that discussion and I understand the usage for the
> selector in-statement solution, however that's just for assignment
> though.
> 
> Consider this simple file resource, I just want to have a external
> variable that control whether I need the file in the system:
> 
> file { "somefile" :
> 
>         case ${hasfile} {
>            "true": { ensure => present }
>            default: { ensure => absent }
>         }
>         source => "puppet:///somefile",
>         owner => "root",
>         .
>         .
>         .
> }
> 
> 
> Obviously I had a syntax error here because case statement is not
> happy within the resource.

That's why the documentation says to use a selector.

> So, what's a recommended puppet way to do something like this? thx in
> advance.

file { 
  "somefile" :
    ensure => $hasfile ? {
                "true"  => present,
                default  => absent
              },
    source => "puppet:///somefile",
    owner => "root",
}

Please note that "true" is not strictly equivalent to the bareword true
in the puppet language :)
-- 
Brice Figureau
Follow the latest Puppet Community evolutions on www.planetpuppet.org!

-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.

Reply via email to