Limiting Ansible Tower inventory with Satellite host groups
When thinking about ingesting systems into Ansible Tower’s inventory, a common use-case is to intelligently filter hosts into Ansible Tower such that we’re selectively adding only the hosts we want into Tower inventory. When pairing with Red Hat Satellite, we can use Satellite’s host grouping feature combined with Ansible Tower’s Satellite 6 dynamic inventory script to apply this filtering.
In Satellite, I’ve created two host groups, “rhv_hypervisors” and “prod_web_servers”:
I’ve got 2 hosts in the rhv_hypervisors group, and 1 in the prod_web_servers group:
In my case, I only want to import the “prod_web_servers” hosts into Ansible Tower inventory, and not the rest of the Satellite inventory. So, I setup the Ansible Tower inventory source to be Satellite 6, however I will also include the “host_filters” attribute in the source variables section. Here I’ll use the “hostgroup_title” key/value to limit the hosts that will get imported to Satellite. I could use any other host variable that Satellite advertises to Tower however, such as “foreman_location_calgary” perhaps if I wanted to ingest only the hosts in that Satellite location:
With the host filter in place, I will save the inventory source, and run a sync. After the sync, the result is just the one prod web server in “prod_web_servers” host group has been added to the Ansible Tower inventory:
This will help keep Ansible Tower inventory purposeful, and can help reduce the managed nodes counting against the Ansible Tower license.
To make the classification of Satellite hosts a little easier, we can also automate the membership of hosts and host groups with the hammer CLI:
[root@satellite ~]# hammer host update --hostgroup prod_web_servers --name web1.dev.ludwar.ca Host updated. [root@satellite ~]#
References:
1 https://access.redhat.com/documentation/en-us/red_hat_satellite/6.2/html/architecture_guide/chap-red_hat_satellite-architecture_guide-host_grouping_concepts
2 https://access.redhat.com/documentation/en-us/red_hat_satellite/6.5/html-single/managing_hosts/index#sect-Red_Hat_Satellite-Managing_Hosts-Changing_the_Group_of_a_Host