Create a smart inventory and explore how smart inventories work.
Outcomes
Create a smart inventory that dynamically includes hosts selected from all other inventories on this automation controller based on whether a particular Ansible fact gathered from each host has a particular value.
As the student user on the workstation machine, use the lab command to prepare your system for this exercise.
This command ensures that automation controller is installed and configured with any necessary resources created in earlier exercises.
[student@workstation ~]$ lab start advinventory-smart
Procedure 7.2. Instructions
Navigate to https://controller.lab.example.com and log in as the admin user with redhat as the password.
Make sure that the per-host Ansible fact cache time-out for automation controller is set for exactly one day (86400 seconds). This ensures that facts are cached for hosts but also expire if those facts have not been refreshed recently.
Click in the left navigation bar.
In the window, on the tile, click .
Confirm that is set to 86400 seconds. If the setting is different, click , edit that field to contain the value 86400, and click .
Edit the Refresh Fact Cache job template to enable it to use fact storage, and then launch a test job using the Dev inventory.
Click → . For the Refresh Fact Cache job template, click the icon to edit that job template.
Scroll to the bottom of the page, select the checkbox, and then click .
On the page, click .
Select the Dev inventory and then click .
Click to launch the job.
Verify that the facts for servera and serverb in the Dev inventory are available in the automation controller cache.
Navigate to → .
Click the Dev inventory, and then click the tab.
Click servera.lab.example.com, and then click the tab.
Verify that the facts for servera.lab.example.com are available in the cache.
Repeat the preceding substeps with serverb.lab.example.com instead of servera.lab.example.com to verify that the facts for serverb are also available in the cache.
Create a smart inventory named Smart that includes the Red Hat Enterprise Linux-based systems that currently have facts cached by automation controller. This smart inventory must select hosts for which the Ansible fact ansible_distribution has the value RedHat.
Navigate to → .
Click → to create a new smart inventory.
On the page, complete the details as follows:
| Field | Value |
|---|---|
| Name |
Smart
|
| Description |
Smart Inventory
|
| Organization |
Default
|
Click the search icon for the field. Create an advanced filter using the following information and then click .
| Field | Value |
|---|---|
| Filter type |
Advanced
|
| Key |
ansible_facts
|
| Search field |
ansible_distribution="RedHat"
|
Click to create the smart inventory.
Click the tab and verify that both servera.lab.example.com and serverb.lab.example.com are available.
If you previously collected facts for hosts in other inventories, then you might see additional hosts that match the smart host filter. For example, if you collected facts for the Test inventory, then the smart host filter also matches the serverc.lab.example.com and serverd.lab.example.com hosts.
If you collect facts for additional inventories, then hosts that match the smart host filter are added to the existing hosts in the smart inventory.
Log out of automation controller.