Re: [Puppet Users] Re: Conditional Creates Attribute

2014-06-03 Thread jcbollinger


On Monday, June 2, 2014 9:05:55 AM UTC-5, Henrik Lindberg wrote:

 On 2014-29-05 19:59, jcbollinger wrote: 
  
  You want 
  
 creates = undef 
  
  for that approach (no quotes).  That's an affirmative declaration of not 
  specifying any value, even an empty one, for the given parameter. 
  
 To be pedantic, it means use the default value. 



I like my characterization better, but it amounts to much the same thing 
because the default value -- if there is one -- will be used if no value is 
declared for the parameter.

Also, one must be careful here to be clear about *which* default applies: 
it is whatever is built in to the resource type, as opposed to any 
DSL-declared resource default that may be in scope.  One of the uses of 
declaring a parameter undef is to override a resource default of the latter 
kind.

 

 You do not need the conditional construct around the resource, simply 
 use 

 creates = $creates 

 Since, if $creates is undefined, so will creates parameter be. 
 (at least in theory, but may depend on the impl of the exec resource 
 type). 



Really?  It is my perhaps imperfect recollection that that didn't work, on 
account of the reference to an undefined variable being evaluated as an 
empty string.  Perhaps indeed that varies by resource type, but if so, I 
find that disturbing.  Will this be consistent in Puppet 4, one way or the 
other?


John

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/deebfad1-f73c-4d0d-8567-b1ab0bfe5bc9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Puppet Users] Re: Conditional Creates Attribute

2014-06-02 Thread Henrik Lindberg

On 2014-29-05 19:59, jcbollinger wrote:



On Thursday, May 29, 2014 9:23:54 AM UTC-5, Mark McFate wrote:

I'm probably going about this all wrong, but I have an instance
where I've employed a Puppet module and need to _sometimes_ add a
creates attribute to one of the exec's defined there.  My code
(below) is probably all wrong, but I think you'll see what I am
trying to do...

   if $creates != nil {



I think you can spell that as

if $creates { [...]

(See the docs on truthiness
http://docs.puppetlabs.com/puppet/3/reference/lang_datatypes.html#automatic-conversion-to-boolean.)

Alternatively, you could take advantage of the fact that interpolating
an unset variable gets you the empty string:

if $creates == '' { [...]

 exec { drush-${title} :
   command = drush ${command} ${root_option} ${uri_option}
${force_option} ${additional_options},
   path= [ '/bin', '/usr/bin' ],
   creates = $creates,
 }
   } else {
 exec { drush-${title} :
   command = drush ${command} ${root_option} ${uri_option}
${force_option} ${additional_options},
   path= [ '/bin', '/usr/bin' ],
 }
   }

This doesn't work and neither does specifying an empty or nil
attribute, like creates = '' or creates = nil.



You want

   creates = undef

for that approach (no quotes).  That's an affirmative declaration of not
specifying any value, even an empty one, for the given parameter.


To be pedantic, it means use the default value.

You do not need the conditional construct around the resource, simply
use

   creates = $creates

Since, if $creates is undefined, so will creates parameter be.
(at least in theory, but may depend on the impl of the exec resource type).

- henrik


--

Visit my Blog Puppet on the Edge
http://puppet-on-the-edge.blogspot.se/

--
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/lmi0bc%24jjo%241%40ger.gmane.org.
For more options, visit https://groups.google.com/d/optout.