According to the documentation at http://docs.puppetlabs.com/puppet/2.7/reference/lang_conditional.html#if-statements, you can test for truth with syntax like this: if $is_virtual == ''true'' { AFAICT that''s not the case. The quotes around ''true'' make the comparison always fail. Here''s my test case class users { define u($managehome=true) { notice("The value is: ${managehome}") # <== says it''s true if $managehome == ''true'' { notice("...yes, it is true") # <== not reached } else{ notice("...no, it is false") # <== this prints } } @u { mytest: managehome => false, } } include users realize Users::U[mytest] and these are the results $ puppet apply test.pp notice: Scope(Users::U[mytest]): The value is: true notice: Scope(Users::U[mytest]): ...no, it is false Removing the single quotes in the == comparison make the code work as expected. This is with 2.7.18. Am I misunderstanding something, or is this a problem in the documentation? -- 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+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
R.I.Pienaar
2013-Sep-12 19:58 UTC
Re: [Puppet Users] testing for truth, are the docs correct?
----- Original Message -----> From: "Kevin G." <kgoess@bepress.com> > To: puppet-users@googlegroups.com > Sent: Thursday, September 12, 2013 3:56:30 PM > Subject: [Puppet Users] testing for truth, are the docs correct? > > According to the documentation at > http://docs.puppetlabs.com/puppet/2.7/reference/lang_conditional.html#if-statements, > you can test for truth with syntax like this: > > if $is_virtual == ''true'' { > > AFAICT that''s not the case. The quotes around ''true'' make the comparison > always fail. Here''s my test caseis_virtual is a fact, all facts are strings so in this case ''true'' is exactly what is needed :( -- 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+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
Kevin G.
2013-Sep-12 20:11 UTC
Re: [Puppet Users] testing for truth, are the docs correct?
> > if $is_virtual == ''true'' { > > is_virtual is a fact, all facts are strings so in this case ''true'' is > exactly > what is needed :( >That''s helpful, thanks, now I understand why it works in that case and why in my case this is what is needed: if $managehome == true { Since the documentation page is talking about conditional statements *in general*, and not just with facts. I might suggest that making that clear might avoid confusion on the part of people coming to that page looking to find how to make conditional comparisons in puppet. Who would I make that suggestion to, or this this the right forum for that? “If” Statements *“If” statements* take a boolean<http://docs.puppetlabs.com/puppet/2.7/reference/lang_datatypes.html#booleans> condition and an arbitrary block of Puppet code, and will only execute the block if the condition is true. -- 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+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
Seemingly Similar Threads
- Could not evaluate: Could not retrieve information from environment production source(s) for one module, for other is ok
- facter-1.6.0 incorrectly identifies hardware node as virtual
- is_virtual selector
- facter 1.5.7 all lsb* items missing
- lsbdistcodename and Debian Squeeze