"node.rb foreman2.mydomain.com" execution failed

Problem:
I have 2 puppetservers in my network (one in foreman and other standalone as a smart-proxy) with names: foreman2.mydomain.com and foreman2-proxy1.mydomain.com

Execution of “puppet agent --test” in hosts (more than 100) goes OK but failed if i execute in both puppetservers.

Expected outcome:

“puppet agent --test” in both puppetservers finishes ok without errors.

Foreman and Proxy versions:
both servers: foreman 2.4 with puppet 6.19.1

Foreman and Proxy plugin versions:
n/a

Distribution and version:
both servers Debian10.7

Other relevant data:

Execution of ‘puppet agent --test’ in foreman2.mydomain.com:
Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Failed when searching for node foreman2.mydomain.com: Failed to find foreman2.mydomain.com via exec: Execution of ‘/etc/puppetlabs/puppet/node.rb foreman2.mydomain.com’ returned 1:

Execution of ‘/etc/puppetlabs/puppet/node.rb foreman2.mydomain.com
Error retrieving node foreman2.mydomain.com: Net::HTTPPreconditionFailed

Logs:
2021-06-09T09:55:27 [I|app|12de6673] Started GET “/node/foreman2.mydomain.com?format=yml” for 194.30.16.34 at 2021-06-09 09:55:27 +0200
2021-06-09T09:55:27 [I|app|12de6673] Processing by HostsController#externalNodes as YML
2021-06-09T09:55:27 [I|app|12de6673] Parameters: {“name”=>“foreman2.mydomain.com”}
2021-06-09T09:55:27 [W|app|12de6673] Failed to generate external nodes for foreman2.mydomain.com
2021-06-09T09:55:27 [I|app|12de6673] Backtrace for ‘Failed to generate external nodes for foreman2.mydomain.com’ error (NoMethodError): undefined method name' for nil:NilClass* *Unnamed:1:in get_binding’

I’ve disable safemode_render setting in foreman but no luck.

certs issue? I have checked both the web interface and the CLI (puppetserver ca list --all) and apparently the certificates of the two servers are signed and correct

database names for this hosts problem? in ‘hosts’ table, fields ‘certname’, ‘name’ and ‘lookup_value_matcher’ are correct.

It seems that foreman can’t find these two hosts.

Thank You!

It looks like something fails on the Foreman side, but I’m not sure where. Isn’t there more of a backtrace?

Do you by any chance use ERB in a parameter? I think that may fail. Something where it calls .name on some nil object.