Configure an inventory sourced from a project and create a smart inventory that selects its hosts from existing inventories based on the value of a host variable.
Outcomes
Use an existing static inventory file stored in a Git repository.
Create a smart inventory.
As the student user on the workstation machine, use the lab command to prepare your system for this exercise.
This command ensures that private automation hub and automation controller are installed and configured with any necessary resources created in previous exercises.
[student@workstation ~]$ lab start advinventory-review
Procedure 7.3. Instructions
Navigate to https://controller.lab.example.com and log in as the admin user with redhat as the password.
Create a new project based on the following information:
| Field | Value |
|---|---|
LabProjectGit
| |
git@git.lab.example.com:git/advinventory-review.git
| |
| (selected) |
Navigate to → and then click .
Enter the following details, and then click :
| Field | Value |
|---|---|
LabProjectGit
| |
git@git.lab.example.com:git/advinventory-review.git
| |
| (selected) |
After you click , automation controller immediately attempts to synchronize the project.
On the tab, verify that the value of shows .
If the project synchronization fails, then ensure that the project specifies the correct source control URL and credentials.
Create a new inventory based on the following information:
| Field | Value |
|---|---|
LabGit
| |
| Source |
git-inventory-lab
|
| (selected) |
When configured correctly, a successful synchronization of the git-inventory-lab inventory source creates the storage group with the servere.lab.example.com and serverf.lab.example.com hosts within the group.
Navigate to → and then click → .
Enter LabGit as the name, use as the organization, and then click .
On the page, click the tab and then click .
Enter the following details, and then click :
| Field | Value |
|---|---|
| Name |
git-inventory-lab
|
| Source | |
| Project | |
| Inventory file | |
| Update options | (selected) |
You might see the following message below the field even if you selected the project name from the list of projects.
That value was not found. Please enter or select a valid value.
The message disappears as soon as you select a different field.
Click and wait until the value of shows .
Navigate to → and click the link.
Click the tab and verify that the group exists.
Click the link and then click the tab. Verify that the group contains the and hosts.
Update the automation controller job settings so that the Per-Host Ansible Fact Cache Timeout setting has a value of 86400 seconds.
Modify the Demo Job Template resource to use the LabGit inventory and the Operations machine credential. Select the option.
Launch a job using the resource and verify that the job caches facts for the servere.lab.example.com and serverf.lab.example.com hosts in the LabGit inventory.
Navigate to → and click the icon for the resource.
The job succeeds and the job output displays the Gathering Facts task for the servere.lab.example.com and serverf.lab.example.com hosts.
...output omitted...
TASK [Gathering Facts] *********************************************************
ok: [servere.lab.example.com]
ok: [serverf.lab.example.com]
...output omitted...Navigate to → and click the link for the host in the inventory. Click the tab and verify that facts exist for the host.
Navigate to → and click the link for the host in the inventory. Click the tab and verify that facts exist for the host.
Create a smart inventory named LabSmart in the Default organization. Configure the smart inventory to use the ansible_distribution="RedHat" filter against cached Ansible facts. When configured correctly, the LabSmart inventory includes at least the servere.lab.example.com and serverf.lab.example.com hosts.
Navigate to → and then click → .
Enter the initial details for the smart inventory:
| Field | Value |
|---|---|
LabSmart
| |
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"
|
Depending on the screen resolution on workstation and the size or zoom setting of your web browser, you might not be able to select . The responsive web UI on automation controller might hide some controls in narrow browser windows.
If this applies to you, then click the search icon again, increase your screen resolution, or reduce the zoom in your web browser.
Click to create the smart inventory.
Click the tab and verify that the servere.lab.example.com and serverf.lab.example.com hosts are available. If you do not see the specified hosts, then look for a typing mistake in the smart inventory host filter.
You might see other hosts in addition to servere.lab.example.com and serverf.lab.example.com.
The LabSmart inventory host list contains all hosts that have cached facts and all hosts in the classroom environment are Red Hat Enterprise Linux hosts.