Error 500 Unable to fetch my node definition

We are using Foreman to provision a server which it does successfully however when running puppet agent -t on the provisioned server the puppet agent shows the following error.

Warning: Unable to fetch my node definition, but the agent run will continue:
Warning: Error 500 on SERVER: Server Error: Failed to find server.domain.com via exec: Execution of ’ /etc/puppetlabs/puppet/node.rb server.domain.com’ returned 1:
Info: Retrieving pluginfacts
Info Retrieving plugin
Info: Retrieving locales
Info: Loading Facts
Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Failed when searching for node server.domain.com: Failed to find server.domain.com via exec: Execution of ‘/etc/puppetlabs/puppet/node.rb server.domain.com’ returned 1:
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run

The server.domain.com.yaml is saved properly in the /opt/puppetlabs/server/data/puppetserver/yaml/facts but it does not appear in /opt/puppetlabs/server/data/puppetserver/yaml/foreman
When we manually copy another .yaml that is in the /opt/puppetlabs/server/data/puppetserver/yaml/foreman folder and change the server name etc. then the agent can connect and can run the puppet agent -t

We would like the puppet agent -t to pass without having to manually create a .yaml file in the foreman folder. We have confirmed that :puppetdir in /etc/puppetlabs/puppet/foreman.yaml is set to “/opt/puppetlabs/server/data/puppetserver”

The certificat is also successfully automatically approved and appears in both the server and agent.

Puppet Agent:
1

Foreman and Proxy versions:
Puppet Agent Version: 5.4.0
Puppet Master Version: I am not sure
Foreman Version: 1.18.2

Here is the puppet.conf on the puppet server:

And this is the main section of the puppet.conf on the puppet server:

Could the problem be that the ssldir is different? If so how could I correct it? Thank you for the help and sorry for the multiple posts. I am only allowed one image per post as a new user.

Did you ever get to the bottom of this?
I am seeing the same thing, existing nodes are working.
Adding new hosts results as above, copying an existing .yaml, in /opt/puppetlabs/server/data/puppetserver/yaml/foreman, an naming it according to the new node works.