Duplicate facts from discovery and Puppet

Already reported this as a bug, but since this may well be a misconception on my part (and because there was no response to the bug :slight_smile: ), I’m asking here, too:

Problem:

We use Foreman (currently 3.11.2) with the “foreman_puppet” plugin (7.0.0). After the first regular puppet run on a newly provisioned bare metal host, the Foreman database contains a number of facts for the host that have the same name, but different name types (“DiscoveryFactName” and “PuppetFactName”) and, crucially, different values. When querying the Foreman API for hosts by fact values, Foreman seems to arbitrarily use either of the two values for the fact name, leading to inconsistent results.

I’m not sure what the error here is (maybe there is a mistake on our side).

  • Should the facts from discovery be removed from the host at some point?
  • Should the puppet facts replace discovery facts of the same name?
  • Should there be a consistent precedence among the different fact types when querying?

Expected outcome: API queries consistently use recently collected fact values.

Foreman and Proxy versions: 3.11.2

Foreman and Proxy plugin versions:

  • foreman_discovery: 24.0.1
  • foreman_puppet: 7.0.0
  • puppetdb_foreman: 6.0.2

Distribution and version: Debian 11.11 (Bullseye)

Other relevant data:

Example database contents:

# select fn.id as name_id, fn.name, fn.type, fv.id as value_id, fv.value, fv.updated_at from fact_values fv join hosts h on fv.host_id = h.id join fact_names fn on fv.fact_name_id = fn.id where h.name = hostname and fn.name = 'os::release::major';
 name_id |        name        |       type        | value_id | value |         updated_at
---------+--------------------+-------------------+----------+-------+----------------------------
 5300939 | os::release::major | DiscoveryFactName | 32717847 | 8     | 2024-07-23 12:26:33.211309
    3586 | os::release::major | PuppetFactName    | 33177684 | 12    | 2024-09-17 11:11:56.556702

The PuppetFactName value is the correct one in this case.

Hi,

Should the facts from discovery be removed from the host at some point?

Yes. They are sent to the Foreman when the machine is booted from the discovery ISO and reported to the Foreman, waiting for the provisioning process. After the machine is provisioned, they are not needed anymore and can be deleted.

Should the puppet facts replace discovery facts of the same name?

Yes, the puppet facts represent information for already provisioned and running machines and are more up-to-date, so they are more factual.

Should there be a consistent precedence among the different fact types when querying?

Puppet facts > Discovery facts.

Thanks, that all sounds reasonable. But what is the solution to our problem, then? Is it a bug/missing functionality in Foreman that the facts from discovery are not deleted once the host has been provisioned? Or is this expected behavior that we have to take care of ourselves?

I would say it’s something Foreman should take care of, specifically the foreman_discovery plugin.