Thank you for the explanation Garrett.  I've seen similar things like that 
in my web searches but failed to put it all together.

I'll roll with this until we upgrade to 4.0

Cheers,

Mike

On Tuesday, April 12, 2016 at 6:31:47 PM UTC-7, Garrett Honeycutt wrote:
>
> On 4/12/16 2:53 PM, Mike Reed wrote: 
> > Hello all, 
> > 
> > I've recently experienced some inconsistencies around referencing 
> > Boolean values within a puppet manifest.  We've written some custom 
> > Boolean facts and we look to the true/false values within our manifests 
> > to help make decisions on what should or shouldn't be done. 
> > 
> > The issue I have is the different behavior I see when referencing the 
> > fact value.  For instance, in some cases I have to reference the Boolean 
> > value with quotes (ie.. 'true') in order to get things working right. 
> >  In other cases, removing the quotes returns the results I would expect. 
> > 
> > I understand that this is most likely due to what the fact is returning 
> > but I was wondering if there's a 'best practice' for approaching 
> > something like this.  I've also played around with stringify_facts and 
> > achieved varied results (in terms of referencing the Boolean values) and 
> > that may have only confused me.   
> > 
> > We're currently running: Puppet v:3.8.6/Hiera v:1.3.4 
> > 
> > I realize this question touches on a few different things but does 
> > anybody have a brief explanation for how I might consistently reference 
> > these Boolean values throughout our puppet infrastructure?   
> > 
> > Here's an example of a custom fact that we use: 
> > 
> > require 'facter' 
> > 
> > Facter.add(:nvidia_installed) do 
> >   setcode do 
> >     tools_test = Facter::Util::Resolution.exec("/usr/bin/nvidia-smi") 
> >     if tools_test 
> >       nvidia_installed = true 
> >     else 
> >       nvidia_installed = false 
> >     end 
> >   end 
> > end 
> > 
> > In order to reference this particular value within my manifest, I have 
> > to reference the value without quotes:   elsif ($::class == 
> > 'render_workstation') and ($::nvidia_installed == false) { 
> > 
> > As always, thank you in advance for the help and support. 
> > 
> > Cheers, 
> > 
> > Mike 
> > 
>
> Hi Mike, 
>
> Booleans such as true vs. stringified booleans such as 'true' have long 
> been a sore spot within the Puppet ecosystem. 
>
> You want to set stringify_facts = false in your puppet.conf. This will 
> allow you to have other data types as facts such as booleans, arrays, 
> and hashes. 
>
> Recommend using this design pattern to deal with stringified booleans in 
> Puppet v3. 
>
>   if is_string($my_param) == true { 
>     $my_param_bool = str2bool($my_param) 
>   } else { 
>     $my_param_bool = $my_param 
>   } 
>   validate_bool($my_param_bool) 
>
> So given the param, $my_param, this will ensure it is an actual boolean. 
> In your code you reference $my_param_bool instead of $my_param. 
>
>
> Best regards, 
> -g 
>
> -- 
> Garrett Honeycutt 
> @learnpuppet 
> Puppet Training with LearnPuppet.com 
> Mobile: +1.206.414.8658 
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/a3a388d6-c037-4029-bdf3-d4abed521f1e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to