Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a class in a module:

# File: modules/selinux/tools.pp
class selinux::tools {
        $packages = ['policycoreutils-python',]

        package { $packages:
                ensure => installed
        }
}

Then, my default node:

# File: manifests/nodes/default.pp
node default {
        if $selinux {
                include selinux::tools
        }
}

I restart puppetmaster and the puppet agent. However, the package gets installed in the node even though the selinux fact is false:

$ facter -p selinux
false

What am I missing here?

share|improve this question

1 Answer 1

up vote 6 down vote accepted

The "true" or "false" in the selinux fact is just a string to Puppet, it doesn't treat the contents of the string as a boolean. The correct thing to do is just to compare it to another string:

if $selinux == "true" {
    include selinux::tools
}

There is a feature request to change the behavior so that Facter booleans are properly treated as Puppet booleans.

share|improve this answer
    
Is this mis-documentation then? –  Belmin Fernandez Dec 4 '11 at 15:09
    
It works! Thanks. Still, according to their documentation, at least some facts are interpreted as bool values. How would I know which are strings and which are bool? –  Belmin Fernandez Dec 4 '11 at 15:13
    
Nope - I think that documentation is wrong. Try it for yourself - even 'false' would come up as a positive. –  Ken Barber Dec 5 '11 at 12:30
    
Agreed, though it sort of gives the reasoning in the next section. I've filed #11183 as I think the example deserves a big warning and to properly compare how the variable should be tested. –  m0dlx Dec 5 '11 at 22:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.