After reading Foreman manual and various threads on this forum I’m still wondering if it’s possible to somehow use Puppet facts as smart matchers?
I’d like to add a certain fact (e.g. os::release::major or some custom structured fact) as one of the smart matchers and then use it to override specific smart class parameters.
If facts can’t be used as smart matchers, what are possible ways of overriding default values of class parameters based on (custom) fact values (preferably without modifying Puppet module’s code)?
Hi, welcome to our forum!
Facts and custom facts can be used as smart matchers.
What version on Foreman are you using?
You can add the fact to the order field according to the order you want and then add a matcher for it.
In the order field you determine which value the host will get if it matches on more than one smart match (the higher order will win).
I’m running the latest stable version (1.24.0). If facts can be used as smart matchers, that’s great
I didn’t find this information in Foreman manual. In what format do I need to add fact as smart matcher (is it
$facts['os']['release']['major'] or something else)?
Thank you for your help.
Use the fact name itself
Thank you Ori, I managed to add custom fact to the list of smart matchers.
One more question.
When I navigate to
Configure > Classes > [class name] > Smart Class Parameter > [some parameter], under “Prioritize Attribute Order” I’m seeing “order” tooltip that displays the following message:
"You may use multiple attributes as a matcher key, for example, an order of
host group, environment would expect a matcher such as
hostgroup = "web servers", environment = production"
How can I configure a multiple attributes as a single smart matcher? Also, how should I define values for each of the attributes?
I tried to configure it as array (within array), but I’m getting “value must be comma separated”. This is the array I’m trying to save:
[ fqdn, hostgroup, os, ["os::release::major", "os::family"], domain, environment ]
The idea here is that I’d like to match two things (“os::family = RedHat” and “os::release::major = 8”) and use this a single smart matcher.
No need for the array, just adding them to the order with a comma and then add a new matcher and you can choose the multiple attribute.
There is an example in the manual using
region, hostgroup, environment.
In your example you add to the order:
Once that exists you can choose it in the matcher (you’ll see
os::family ,os::release::major was added to the options to select), you choose it and the value will be the values you wanted to use with a comma between them, in your case
Please notice the values should be in the same order as the facts so if
os::family is first in the value
RedHat will be first.
Thank you for clarification Ori.
I was under the impression that I need to define “paired” attributes in global settings (i.e. “Default variables lookup path”). Once I realized that attribute order can be defined per class parameter everything clicked into place. It actually makes more sense