puppetredhatrocky-os

Puppet Unknown variable: 'osfamily' on Rocky 9


I am seeing the following error...

Error: Evaluation Error: Unknown variable: 'osfamily'. (file: /etc/puppetlabs/code/environments/production/manifests/print_text.pp, line: 1, column: 4) on node mgmtserver.mydomain.com

...when attempting to run a manifest on the Puppet Server...

puppet apply /etc/puppetlabs/code/environments/production/manifests/print_text.pp

The manifest is:

if $osfamily == 'RedHat' {
   notice("A test message")
}

The following returns results...

puppet facts osfamily

{
  "osfamily": "RedHat"
}

...as does the following:

facter osfamily

RedHat

The Puppet Server is:

puppetserver.service (master) is running on the host but puppet.service (agent) is not.

Any suggestions?


Solution

  • If you are attempting to resolve a fact, then you would need to access the fact's value. The syntax $osfamily would instead attempt to resolve a value assigned to the variable osfamily which is undefined in your accessible scope. This can be accomplished with the following syntax:

    if $facts['os']['family'] == 'RedHat' {
      notice("A test message")
    }
    

    Note the documentation also contains this as an example.