3

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?

1 Answer 1

8

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.

4
  • Is this mis-documentation then? Dec 4, 2011 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? Dec 4, 2011 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, 2011 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. Dec 5, 2011 at 22:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .