facts: os is not a hash or array

asked 2015-10-02 02:34:48 -0500

alexandre gravatar image

I have a node and a master. Everything is OK, I can apply catalog. Now I would like to use Facts but it seems that the results of Facts are always stringify.

In one of my module, I have this line:

$test = $os['name']

I'm running Puppet 3.8.2 (community edition), so on the node, in the file /etc/puppet.conf, I added this line:


After adding this line, I restarted Puppet on this node:

# service puppet restart

On the node, I can run this command:

# facter --puppet os
{"name"=>"Debian", "family"=>"Debian", "release"=>{"major"=>"7", "minor"=>"8", "full"=>"7.8"}, "lsb"=>{"distcodename"=>"wheezy", "distid"=>"Debian", "distdescription"=>"Debian GNU/Linux 7.8 (wheezy)", "distrelease"=>"7.8", "majdistrelease"=>"7", "minordistrelease"=>"8"}}

However, when I apply the catalog I have this error:

Error: Could not retrieve catalog from remote server: Error 400 on SERVER: os is not a hash or array when accessing it with name

Instead, if in my module I'm considering "os" as a string, then it is working:

$test = $os
# and in my template I can print the long string with <%= @test %>

I also added stringify_facts=false to the Master, but that doesn't solve my issue.

I also created my custom facts returning a hash, but still same issue.

Is there any setting that I'm missing?

Facter version: 2.4.1

edit retag flag offensive close merge delete


Is there any difference in behavior if the referece is fully qualified: `$::os['name']`? I'm wondering if there is another `os` variable in your module scope.

csharpsteen gravatar imagecsharpsteen ( 2015-10-02 10:01:22 -0500 )edit

Same error with $::os['name']. About another 'os' variable, I was thinking the same thing, that's why I tested with my own custom fact returning a hash, but still same issue.

alexandre gravatar imagealexandre ( 2015-10-04 21:57:31 -0500 )edit

Hmm. Are you also using a fact cache on the master, such as PuppetDB? There are some situations where agent facts will get round-tripped through the cache and be converted to strings.

csharpsteen gravatar imagecsharpsteen ( 2015-10-05 01:03:32 -0500 )edit

Actually, a good way to settle the client problem vs. server problem question would be to `puppet apply` a test manifest that uses `$::os['name']` directly on the agent node and see if the same error pops up.

csharpsteen gravatar imagecsharpsteen ( 2015-10-05 01:05:05 -0500 )edit

thanks for your suggestion, I will try it. One question: I didn't set "parser = future", may it be the cause of the problem?

alexandre gravatar imagealexandre ( 2015-10-13 20:35:23 -0500 )edit