In regard to: Re: [Puppet Users] new user: need Conditional statement...:

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 :)

Ah, perfect segue.  I had been meaning to follow up to John Bollinger
when he earlier posted something similar that also had 'true' quoted.

I've been through the style guide and several other areas in the
documentation and I can't find any recommendations on whether it's better
to use bare

        true
        false

or whether it's better to quote them.  This is specifically for use in
parameterized classes.  For example:

foo.bar.edu.pp:

node 'foo.bar.edu' {

  class {'rhel':
    version      => '5',
    ipv6_enabled => true,
  }
}

rhel/manifests/init.pp:

class rhel($version, $ipv6_enabled='default') {
  include rhel::common

  case $ipv6_enabled {
    true: {
        class {'network': ipv6 => true }
    }
    false: {
        class {'network': ipv6 => false }
    }
    default: {
      case $version {
        '5': {
            class {'network': ipv6 => false }
        }
        '6': {
            class {'network': ipv6 => true }
        }
        default: { fail("only version 5 and 6 of rhel are currently supported")}
      }
    }
  }
}


In other words, our default for RHEL 5 is ipv6 disabled, on RHEL 6 it's
ipv6 enabled, but the default can be overridden for either.

The problem is that we had to be very careful to make certain that we
didn't quote true or false in some places and leave them as barewords
elsewhere, or it just wouldn't work.  Mixing quoted & nonquoted gave us
unreliable and unexpected results.

This brings me back to the questions: where in the docs is this covered,
and what are the recommendations for whether we should (or shouldn't) be
quoting true & false when passing them around into parameterized classes
and testing them in selectors?

Thanks much,

Tim
--
Tim Mooney                                             tim.moo...@ndsu.edu
Enterprise Computing & Infrastructure                  701-231-1076 (Voice)
Room 242-J6, IACC Building                             701-231-8541 (Fax)
North Dakota State University, Fargo, ND 58105-5164

--
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