Ask Your Question
0

Puppet Basic error: str2bool(): Unknown type of boolean given in manifest

asked 2013-12-03 20:17:14 -0500

knock2puppet gravatar image

updated 2013-12-04 01:50:06 -0500

spuder gravatar image

Hello Puppet Gurus, I am repeatedly getting same error for a simple manifest, please help. Below is manifest code:

============

 if str2bool("$operatingsystem") {
    notice {"just tetsing this stuff":}
 }

=================

And error is as below Error: str2bool(): Unknown type of boolean given at

Thanks

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
1

answered 2013-12-04 01:56:22 -0500

spuder gravatar image

updated 2013-12-05 11:40:14 -0500

The facter fact $operatingsystem returns a value such as Cent or Ubuntu.

Try the following syntax

  case $operatingsystem {
    CentOS,RedHat: {     
        notify {"the os is Cent/RHEL":}       
    }   
    Debian,Ubuntu: {
        notify {"the os is Ubuntu/Debian:}   
    }
    default:{ 
        fail("Operating System not supported") 
    }
  }

Update

The str2bool is only intended to work on "boolean-like" things https://forge.puppetlabs.com/puppetlabs/stdlib

str2bool This converts a string to a boolean. This attempt to convert strings that contain things like: y, 1, t, true to 'true' and strings that contain things like: 0, f, n, false, no to 'false'.

Type: rvalue

In your example, Every server ... (more)

edit flag offensive delete link more
0

answered 2013-12-04 13:37:44 -0500

knock2puppet gravatar image

Thanks for your reply, however I was thinking that should work because as per puppet language "Empty strings are false; all other strings are true. " So if $operatingsystem returns a non-empty string then it should execute the code inside if block.

edit flag offensive delete link more

Comments

I've updated my answer

spuder gravatar imagespuder ( 2013-12-04 18:34:14 -0500 )edit
0

answered 2013-12-05 16:32:19 -0500

fnaard gravatar image

The fact $::operatingsystem is pretty much guaranteed to be set, no matter what. Sticking to your example, try:

  if $::operatingsystem { notify { 'hello': } }

To see it be false, use a non-existent fact

  if $::fluxcapacitor { notify { 'hello': } }
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2013-12-03 20:17:14 -0500

Seen: 705 times

Last updated: Dec 05 '13