Foreman 2.1.2 + salt 3001: undefined method `merge’ for nil:NilClass

Hello,

I’ve seen this problem already reported but i didn’t found any solution.
I can accept a salt key in foreman smart proxy, but the salt_minion host is not created when salt_master execute foreman-node

It 's OK if i run foreman-node my-salt-minion-host-name manually or if i run salt-call --grains from salt-minion host.

Foreman and Proxy versions:

foreman-installer.noarch                                1:2.1.2-1.el8                                    @foreman
foreman.noarch                                          2.1.2-1.el8                                      @foreman
foreman-proxy.noarch                                    2.1.2-1.el8                                      @foreman

Foreman and Proxy plugin versions:

rubygem-foreman_salt.noarch                             13.2.3-1.fm2_1.el8                               @foreman-plugins 
rubygem-smart_proxy_salt.noarch                         3.1.2-3.fm2_1.el8                                @foreman-plugins 
rubygem-smart_proxy_salt_core.noarch                    0.0.3-1.el8                                      @foreman-plugins

Distribution and version:

CentOS Linux release 8.1.1911 (Core)

Other relevant data:

2020-09-09 12:29:55,999 [salt.loaded.int.module.cmdmod:854 ][ERROR   ][8429] Command '['/usr/bin/foreman-node', 'sphynx.ac-test.fr']' failed with return code: 1
2020-09-09 12:29:56,000 [salt.loaded.int.module.cmdmod:856 ][ERROR   ][8429] stdout: Could not get grains: undefined method `merge' for nil:NilClass
Couldn't retrieve ENC data: Could not send facts to Foreman: exit
2020-09-09 12:29:56,000 [salt.loaded.int.module.cmdmod:860 ][ERROR   ][8429] retcode: 1
2020-09-09 12:29:56,000 [salt.loaded.int.module.cmdmod:1218][ERROR   ][8429] Command '/usr/bin/foreman-node sphynx.ac-test.fr' failed with return code: 1
2020-09-09 12:29:56,001 [salt.loaded.int.module.cmdmod:1223][ERROR   ][8429] output: Could not get grains: undefined method `merge' for nil:NilClass
Couldn't retrieve ENC data: Could not send facts to Foreman: exit
2020-09-09 12:29:56,001 [salt.loaded.int.pillar.puppet:31  ][CRITICAL][8429] YAML data from /usr/bin/foreman-node failed to parse

It seems grains cache is created after the script foreman-node tries to get it.
Is there a timeout or something else i can configure ?

Looks like, no grains can be gathered from salt.
Can you try to use the following command to get the cached grains for the minion specified with

salt-run -l quit --output=json cache.grains <minion>
1 Like

I’ve already tried this and i have the same problem :
salt-key -a <minion> -y && salt-run -l quiet --output=json cache.grains <minion>
If i wait some seconds after that, cache is built (/var/cache/salt/master/<minion>/data.p file).
I’ve written a dirty bash script to see if this is a cache problem and replace foreman-node by it in ext_pillar config and it works :

#!/bin/bash
/usr/bin/salt "$1" -l quiet --out no_out_quiet saltutils.sync_grains
/usr/bin/foreman-node $1

In this case, I would suggest to try

1 Like

Thanks, but how can i install rubygem-msgpack ?

Try this: https://yum.theforeman.org/plugins/nightly/el7/x86_64/tfm-rubygem-msgpack-1.3.3-1.el7.x86_64.rpm if possible

I’ll try with https://yum.theforeman.org/releases/nightly/el8/x86_64/foreman-release.rpm because there is dependency problem.
I’ve installed foreman with https://yum.theforeman.org/releases/2.1/el8/x86_64/foreman-release.rpm

It’s the same problem :

2020-09-16 12:28:20,774 [salt.loaded.int.module.cmdmod:854 ][ERROR   ][29748] Command '['/usr/bin/foreman-node', 'sphynx.ac-test.fr']' failed with return code: 1
2020-09-16 12:28:20,774 [salt.loaded.int.module.cmdmod:856 ][ERROR   ][29748] stdout: Could not get grains: No such file or directory @ rb_sysopen - /var/cache/salt/master/minions/sphynx.ac-test.fr/data.p
Couldn't retrieve ENC data: Could not send facts to Foreman: exit
2020-09-16 12:28:20,775 [salt.loaded.int.module.cmdmod:860 ][ERROR   ][29748] retcode: 1

After a few seconds, the data.p file is created, but it’s too late.
For both get_grains_from_saltrun and get_grains_from_filecache, it should wait a little if cache is not ready immediatly, don’t you think ?