Default Hostgroup not matching on any custom facts, always hits default

Using the default hostgroup plugin to put nodes in hostgroups based on a custom fact. However, the fact value is never matched by the plugin and the default ‘catch all’ option is always used.
Expected outcome:
The plugin would match the custom fact and apply the corresponding hostgroup/environment to that node
Foreman and Proxy versions:
Foreman and Proxy plugin versions:

Other relevant data:
I’ve set the “force_hostgroup_match_only_new” to no and “force_hostgroup_match” to yes in the UI and restarted foreman and httpd.

[e.g. logs from Foreman and/or the Proxy, modified templates, commands issued, etc]
(for logs, surround with three back-ticks to get proper formatting, e.g.)

2019-04-16T14:41:14 [I|app|3cfc7] Processing by Api::V2::HostsController#facts as JSON
2019-04-16T14:41:14 [I|app|3cfc7]   Parameters: {"facts"=>"[FILTERED]", "name"=>"", "certname"=>"", "apiv"=>"v2", "host"=>{"certname"=>"", "name"=>""}}
2019-04-16T14:41:15 [I|app|3cfc7] Import facts for '' completed. Added: 0, Updated: 21, Deleted 0 facts
2019-04-16T14:41:15 [I|app|3cfc7] Fact = apl_env
2019-04-16T14:41:15 [I|app|3cfc7] Regex = dare
2019-04-16T14:41:15 [I|app|3cfc7] Fact = apl_env
2019-04-16T14:41:15 [I|app|3cfc7] Regex = MyAPLCloud-dmz
2019-04-16T14:41:15 [I|app|3cfc7] Fact = apl_env
2019-04-16T14:41:15 [I|app|3cfc7] Regex = MyAPLCloud
2019-04-16T14:41:15 [I|app|3cfc7] Fact = apl_env
2019-04-16T14:41:15 [I|app|3cfc7] Regex = Opt-in
2019-04-16T14:41:15 [I|app|3cfc7] Fact = apl_env
2019-04-16T14:41:15 [I|app|3cfc7] Regex = dev
2019-04-16T14:41:15 [I|app|3cfc7] Fact = apl_env
2019-04-16T14:41:15 [I|app|3cfc7] Regex = test
2019-04-16T14:41:16 [I|app|3cfc7] Fact = hostname
2019-04-16T14:41:16 [I|app|3cfc7] Regex = .*
2019-04-16T14:41:16 [I|app|3cfc7] DefaultHostgroupMatch: added to default
2019-04-16T14:41:16 [I|app|3cfc7] Completed 201 Created in 1887ms (Views: 3.4ms | ActiveRecord: 546.7ms)

When I do a ‘facter apl_env’ on the node:
[root@ticemp1-ll1 ~]# facter apl_env

Yet this host (and other hosts I’ve tried always catch the ‘default’ option, here’s the config:

      "apl_env": "dare"
      "apl_env": "MyAPLCloud-dmz"
      "apl_env": "MyAPLCloud"
      "apl_env": "Opt-in"
      "apl_env": "dev"
      "apl_env": "test"
      "hostname": ".*"

If you need more information let me know. Thanks.

For more information, I set this ‘apl_env’ fact by creating a yaml file in /opt/puppetlabs/facter/facts.d/
It seems that I can match correctly on other core facts such as hostname or ipaddress.

Does this external fact show up in Forman for the host in question once it’s checked in?

Also what’s the output of puppet facts apl_env

This fact used to show up (I was using Foreman 1.19.1) but when I upgraded everything it stopped showing up in foreman.

The output of the command shows all the facts, but does contain apl_env:
[root@ticemp1-ll1 ~]# puppet facts apl_env
“name”: “apl_env”,
“values”: {
“aio_agent_version”: “5.5.13”,
“apl_env”: “test”,
“architecture”: “x86_64”,
“augeas”: {
“version”: “1.11.0”

So foreman not knowing about your external facts will be the reason the match is not happening.

If puppet knows about the fact locally on the node then we need to work out if they are not being reported to the puppetmaster or node.rb is not uploading them to foreman. I don’t know of any mechanism by which external facts would be filtered out intentionally.

Is there anything of interest in the puppetmaster foreman proxy logs when the client checks in?

Unfortunately there’s nothing useful in the foreman-proxy logs.

Did you find the solution for it? I am using the same version and getting same issue. Default facts are working whereas custom facts are not working with this plugin.

Fact value is also getting imported into foreman but still default hostgroup is unable to update that.

Below is my default hostgroup rules.

“foreman_location”: “Noida”
“osfamily”: “RedHat”
“lsbdistcodename”: “Santiago”
“osfamily”: “Darwin”
“hostname”: “.*”

Client host is getting the fact value as below:

[root@rhel6dev ~]# puppet facts foreman_location | grep foreman_location
“name”: “foreman_location”,
“foreman_location”: “Noida”,
[root@rhel6dev ~]#

Image of forman portal which showing the fact value for the host:

But when i am running puppet agent on this client host then its assigning it to “Base” hostgroup not in “Noida_AllHost”

Both the hostgroup i have already created in Foreman.

Please help to fix it.

Hi Support,

Could you please update here?