Boolean in hiera... problems again

1,581 views
Skip to first unread message

Jakov Sosic

unread,
Mar 5, 2013, 3:08:44 PM3/5/13
to puppet...@googlegroups.com
Hi...

I've been trying to set up boolean values in Hiera, but with no luck.

For example, I'm using puppetlabs-haproxy module, and this is a code
snippet:

class haproxy (
$manage_service = true,
...
) inherits haproxy::params {
...

if $manage_service {
}
}

Now, this is how I set up values in hiera:

haproxy::manage_service: false


But, it seems that $manage_service is always true... I tried by single
quoting 'false', capital letter False, but nothing helps...

Only thing so far I've found out is to change the manifest code to look
like this:

if $manage_service == 'true' {
}


Any ideas?

Peter Brown

unread,
Mar 5, 2013, 10:29:29 PM3/5/13
to puppet-users
Getting booleans from hiera to puppet is not currently not functioning like you would expect.
There is a bug reported for it and they are working on it but it's still in progress last I looked.



--
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...@googlegroups.com.
To post to this group, send email to puppet...@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.



Richard Clark

unread,
Mar 6, 2013, 4:15:48 AM3/6/13
to puppet...@googlegroups.com
On Wed, Mar 06, 2013 at 01:29:29PM +1000, Peter Brown wrote:
> Getting booleans from hiera to puppet is not currently not functioning like
> you would expect.
> There is a bug reported for it and they are working on it but it's still in
> progress last I looked.
>
>

Would this > http://projects.puppetlabs.com/issues/16178 be the report?
If so, I'm really hoping that it's solved in 3.0.2 as running into the
same issue myself :(

--
Richard Clark
ric...@fohnet.co.uk
signature.asc

Keith Burdis

unread,
Mar 6, 2013, 4:59:46 AM3/6/13
to puppet-users
I am running 3.1.0 and hiera booleans appear to be working fine.

  - Keith

Jakov Sosic

unread,
Mar 6, 2013, 11:20:55 AM3/6/13
to puppet...@googlegroups.com
On 03/06/2013 10:59 AM, Keith Burdis wrote:
> I am running 3.1.0 and hiera booleans appear to be working fine.

I am running 3.1.0 and still have problems...

Peter Brown

unread,
Mar 6, 2013, 9:10:13 PM3/6/13
to puppet-users
Last I tried I still had problems in 3.1.0.


llowder

unread,
Mar 7, 2013, 8:41:51 AM3/7/13
to puppet...@googlegroups.com


On Thursday, March 7, 2013 6:38:52 AM UTC-6, Ahmed Kamal wrote:
I'm on 3.1, and I'm finding that "true" works as expected, but "false" does not! I think "false" is interpreted as "undef" or so, thus taking value from the module's default params

False is being treated as the lookup function itself returning false - which then means nil is used and the next level of looking for a default (either the next level of hierarchy, the next backend or the defaults defined with the class.

I think this is supposed to be fixed in hiera 1.2, which just had rc1 released, but I am not positive.

Jakov Sosic

unread,
Mar 7, 2013, 2:28:23 PM3/7/13
to puppet...@googlegroups.com
On 03/07/2013 02:41 PM, llowder wrote:
>
>
> On Thursday, March 7, 2013 6:38:52 AM UTC-6, Ahmed Kamal wrote:
>
> I'm on 3.1, and I'm finding that "true" works as expected, but
> "false" does not! I think "false" is interpreted as "undef" or so,
> thus taking value from the module's default params
>
>
> False is being treated as the lookup function itself returning false -
> which then means nil is used and the next level of looking for a default
> (either the next level of hierarchy, the next backend or the defaults
> defined with the class.
>
> I think this is supposed to be fixed in hiera 1.2, which just had rc1
> released, but I am not positive.

A-ha! Thank you guys, so it's not me doing something wrong after all...

Nick Fagerlund

unread,
Mar 7, 2013, 3:43:26 PM3/7/13
to puppet...@googlegroups.com


On Thursday, March 7, 2013 11:28:23 AM UTC-8, Jakov Sosic wrote:
On 03/07/2013 02:41 PM, llowder wrote:
>
>
> On Thursday, March 7, 2013 6:38:52 AM UTC-6, Ahmed Kamal wrote:
>
>     I'm on 3.1, and I'm finding that "true" works as expected, but
>     "false" does not! I think "false" is interpreted as "undef" or so,
>     thus taking value from the module's default params
 
Yeah it's definitely a bug, but I think it's http://projects.puppetlabs.com/issues/17105 -- not sure when it'll be fixed, but I know they're working on it and consider it serious.

If you need it to work today, you can use the "sloppy bools" pattern, and use a string (instead of a real bool) in your hiera data:

class myclass ($myparam) {
  $myparam_real = str2bool("$myparam")
  #... use $myparam_real everywhere below here.
}

---
myclass::myparam: "false"


This will make it so $myparam can be a string, a real boolean, or a number (0/1), and still work fine. Note the quotes in the str2bool call; those make it so you can later change the hiera data to a real bool (after the bug is fixed) without changing your code.

Peter Brown

unread,
Mar 7, 2013, 6:16:32 PM3/7/13
to puppet-users
Awesome!
I was attempting to think of a quick fix for the problem but hadn't gotten around to it.
My solution was to set the vars in each node definition but this idea is nicer

Thanks Nick!

Nick Fagerlund

unread,
Mar 7, 2013, 7:57:07 PM3/7/13
to puppet...@googlegroups.com
OH, I should mention: the str2bool function is from puppetlabs/stdlib (http://forge.puppetlabs.com/puppetlabs/stdlib)

Richard Clark

unread,
Mar 8, 2013, 10:55:02 AM3/8/13
to puppet...@googlegroups.com
On Thu, Mar 07, 2013 at 12:43:26PM -0800, Nick Fagerlund wrote:
>
> Yeah it's definitely a bug, but I think it's
> http://projects.puppetlabs.com/issues/17105 -- not sure when it'll be
> fixed, but I know they're working on it and consider it serious.
>
> If you need it to work today, you can use the "sloppy bools" pattern, and
> use a string (instead of a real bool) in your hiera data:
>
> class myclass ($myparam) {
> $myparam_real = str2bool("$myparam")
> #... use $myparam_real everywhere below here.
> }
>
> ---
> myclass::myparam: "false"
>
> This will make it so $myparam can be a string, a real boolean, or a number
> (0/1), and still work fine. Note the quotes in the str2bool call; those
> make it so you can later change the hiera data to a real bool (after the
> bug is fixed) without changing your code.


Yeah that appears to be the bug report, and is to be limited to
auto-lookups from parameterized classes/data binding.

In the YAML spec, similar to many languages (including puppet DSL),
true/false must be unquoted. Otherwise 'true' = a string containing the
word true, which evaluates to true, as does the string 'false'.


Classy workaround sir, I will apply liberally.



--
Richard Clark
ric...@fohnet.co.uk
signature.asc
Reply all
Reply to author
Forward
0 new messages