Puppet fact in foreman puppet ENC configuration not resolved on the first puppet run

Problem: It seems that when using a puppet fact in the Foreman puppet ENC configuration, the fact is not resolved during the first puppet run.

For example, if on a host’s ENC configuration a puppet parameter is set to:

dnat-healthcheck-lb:
  args: "<%= @host.facts['networking::interfaces::eth1::ip'] %>:22"

Then after the first puppet run the resulting configuration file contains and empty IP

:22

instead of

10.0.84.69:22

The following puppet run does set the proper IP in the file.

I’ve tested this behavior a few times on a test VM (deleting the host and recreating it in Foreman to clear the host’s facts) and can confirm the behavior.

Is this “by design” or is it a bug ?

Expected outcome: Foreman puppet ENC values based on puppet facts are resolved even on the first puppet run (since puppet facts are gathered prior to catalogue compilation).

Foreman and Proxy versions: 3.18

“by design” as the ENC runs first to compile the catalog. If a value is not known to it yet it can not included in the ENC and the facts are collected only during the run. This is why your problem is fixed after the first run by itself.

You could avoid this by using not the reported fact, but the configured value. You should have access to all interfaces. I recommend looking at the Template DSL or API documentation available on the About page (I have no access to my system at the moment).

@Dirk Thank you for confirming the workflow.

Just to clarify what we’re doing:

In some cases it is quite convenient to be able to use a fact value directly in a Foreman puppet ENC parameter, for instance:

the caveat being that on the first puppet run the resulting Foreman puppet ENC parameter doesn’t yet have the expected value.

We do not provision hosts from Foreman but only manage their puppet configuration, so before the first puppet run Foreman has no data about the host.