Problem:
How can I use the host_collection as matcher within an foreman ansible variable definition?
I have tried a lot of things but nothing worked (like foreman_host_collections or foreman::foreman_host_collections or foreman.foreman_host_collections as Attribute type).
Have anybody used this (or any other foreman fact) as matcher for selecting different values for a specific ansible variable?
hostgroup works fine but I would like to use another grouping option too
Iām afraid it currently does not work. Even basic inheritance seems broken to me on my nightly setup. @nofaralfasi could you please take a look if you can override variable e.g. based on host group or subnet? If this worked, potentially one could add a new matcher host_collection and it may just work.
@Marek_Hulan We are using basic inheritance for all of our Ansible variables, in the production release of F/K (3.5.1/4.7.2) it works fine. We set global defaults and override them based on host groups and location.
We are not using host collections, so I canāt answer to the original topic.
just for information: if I set a local ansible fact on the host, I can access it (like āansible_local::preferences::general::collectionā (file under /etc/ansible/facts.d/preference.fact with [general]collection=xxx)) . In my opinion, it just does not work with the foreman facts
I need to look if this is broken on nightlies or just my setup then. Do you see the overrides correctly on the new host detail page then? (Ansible ā Variables tab and sub-tab). If that works, one should be able to add āhost_collectionā as a new matcher per ansible variable. Then the value should be able to be overriden by the collection.
@nofaralfasi: thanks a lot! This fixed the Error 500 ! Now I can see all Variables in the Host Answible Tab ā¦
but ⦠I still canāt use āforeman_host_colltectionsā
Maybe itās because host_collections is an array ? If I use the field ācommentā, for example, I can work with it. However, it would be important to also make these fields usable so that I have another grouping (editable via the UI) option (and I can recreate something like ansible inventory groups).
Or is there a better way to recreate this in foreman (e.g. that a host can be in multiple groups like āwebā and ādatabaseā when both are running on this system)?
What unfortunately also cost me time (the documentation should be clearer here): all foreman ansible facts are āflatā, i.e. ācommentā applies instead of āforeman::commentā (as it is displayed in the fact list).
and depending on the different host_collections memberships, it should be possible to overwrite the variables with suitable values. The point is that if I already have the Ansible integration in foreman, I donāt have to build an additional Ansible infrastructure (like awx) in smaller environments.
I was able to override a variable based on a hostgroup on nightly.
However, Iām not sure what you mean when you say we can do the override using host_collections.
Iām trying to do that using facts now, but I havenāt figured it out yet.
I have a host in host collection (entity added by Katello plugin). I go to ansible variable thatās overriden for the hostās role. I can specify a new matcher in the order field (this is not well known feature). Then it appears in the attribute type selector. Given host_collection is valid relation, IMHO that should work. Once I save the variable, I donāt see the value on host detail page.
Whatās also interesting - I already override the value per hostgroup and os, however I still only see the default value. Thatās what I mean by the inheritance seems broken. I donāt see those values (hostgroup or os level) even in the ansible inventory.
hostgroup as one type of grouping is fine, but my hostgroups are only divided into OS and Lifecycle as subgroups (by the way: a host can only be a member of one hostgroup). I need a second kind of grouping (e.g. one group for all web servers, one group for all DB servers and so on (and like in Ansible inventories, a host should be able to be in different groups at the same time)). For me, foreman host_collections could be this kind of grouping ⦠but ⦠it is not possible to use this variable as matcher to overwrite (because this variable is an array and not a string?).
I went through the same steps as you suggested with the host_collection to try and override a variable, but it didnāt work for me (I tried it on downstream cause I donāt have the setup for katello ready yet).
Yeah, thatās what I meant, Iām afraid it wouldnāt work. But I was not sure if because the other issue that can be seen on the recording or because thereās something else missing for host_collection (e.g. missing search definition).
Yeah, host collection working would just positively surprise me. However as you can see on the recording, the hostgroup nor os overriding does not seem to work on the nightly (demo hw btw). It may be something with the demo hw, since youāre saying hostgroup overriding works for you. Can you also try os just to be sure?
Works with os on nightly.
I forgot that you can see the value of the variable in the hostās new UI (nice feature!), so I thought I have to run the role to see the variable.
Next time Iāll save myself some time and use the demo HW
I created a role that prints the variable I was testing. I wanted to see if we can use a matcher for host_collections (after it worked with the hostgroups).
Now Iām trying to see if I can achieve the same goal by using facts.