Linux – Puppet conditional include based on selinux fact not working

centoslinuxpuppet

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?

Best Answer

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.