Search code examples
memorypuppetfacter

Puppet on FreeBSD 13.1: Missing Memory Facts


I'm running a server on FreeBSD 13.1. The configuration is managed by puppet. The last pkg upgrade replaced puppet6 with puppet7, which does not work for our setup based on Puppet 6 (~60 servers). So I decided to build Ruby 2.7 from source, and installed puppet as a Ruby Gem, which worked fine.

However, when I run the puppet agent, the following fact won't resolve

$::memory['system']['total']

When I run:

$ sudo puppet agent --test
Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Resource Statement, Evaluation Error: Operator '[]' is not applicable to an Undef Value. [...]

Therefore, I defined the following custom fact in $HOME/facter.d/memory.json:

{
    "memory":
    {
        "system":
        {
            "total" : "32.00 GiB",
            "total_bytes" : 34359738368
        }
    }
}

Which seems to work:

$ facter --external-dir $HOME/facter.d
[...]
memory => {
  system => {
    total => "32.00 GiB",
    total_bytes => 34359738368
  }
}
[...]

So I extended my puppet config (at /etc/puppetlabs/puppet/puppet.conf) by the following line:

factpath=/home/me/facter.d:/opt/puppetlabs/puppet/cache/lib/facter

With /home/me being my $HOME used above.

However, I still get the exact same error as above.

What is wrong here?

Update

I now downgraded to facter version 2.5.7 and use ::memorysize. This works, but when running sudo pupept agent --test, I get a new error message:

Error: Failed to apply catalog: Resource type 'Ssh_authorized_key' was not found

Solution

  • There are a few issues here. The first is that the fact is being referenced as a global variable instead of as a fact. It should be referenced with the correct syntax and with correct accessing of values within hashes (which you already did in your example):

    $facts['memory']['system']['total']
    

    As for the fact you created, it is an external fact and not a custom fact. It is also not the correct procedure for deploying an external fact. It should also probably be either a custom fact or dynamic external fact since the value of the memory may change in the future. If you want it to be an external fact, then it is placed in the <MODULEPATH>/<MODULE>/facts.d/ path for pluginsync deployment.

    For the final issue, you probably need to verify the correct Puppet and Facter gems are being utilized by the agent. Since the root cause here is

    The last pkg upgrade replaced puppet6 with puppet7, which does not work for our setup based on Puppet 6 (~60 servers).

    it would actually probably be easiest to use the latest Puppet AIO package with Puppet 6 included. Building Ruby 2.7 and installing Puppet as a gem on each server, and ensuring compatibility in the future on your Puppet server, will probably be a lot of extra work for you.