Bookmark this page

Lab: Managing Advanced Inventories

  • 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

  1. Navigate to https://controller.lab.example.com and log in as the admin user with redhat as the password.

  2. Create a new project based on the following information:

    FieldValue
    Name LabProjectGit
    Organization Default
    Source Control Type Git
    Source Control URL git@git.lab.example.com:git/advinventory-review.git
    Source Control Credential Student Git Credential
    Options Update Revision on Launch (selected)
    1. Navigate to ResourcesProjects and then click Add.

    2. Enter the following details, and then click Save:

      FieldValue
      Name LabProjectGit
      Organization Default
      Source Control Type Git
      Source Control URL git@git.lab.example.com:git/advinventory-review.git
      Source Control Credential Student Git Credential
      Options Update Revision on Launch (selected)

      After you click Save, automation controller immediately attempts to synchronize the project.

    3. On the Details tab, verify that the value of Last Job Status shows Successful.

      Important

      If the project synchronization fails, then ensure that the project specifies the correct source control URL and credentials.

  3. Create a new inventory based on the following information:

    FieldValue
    Name LabGit
    Organization Default
    Source Name git-inventory-lab
    Source Sourced from a Project
    Project LabProjectGit
    Inventory file inventory
    Update options Update on launch (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.

    1. Navigate to ResourcesInventories and then click AddAdd inventory.

    2. Enter LabGit as the name, use Default as the organization, and then click Save.

    3. On the Details page, click the Sources tab and then click Add.

    4. Enter the following details, and then click Save:

      FieldValue
      Name git-inventory-lab
      Source Sourced from a Project
      Project LabProjectGit
      Inventory file inventory
      Update options Update on launch (selected)

      Important

      You might see the following message below the Project 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.

    5. Click Sync and wait until the value of Last Job Status shows Successful.

    6. Navigate to ResourcesInventories and click the LabGit link.

    7. Click the Groups tab and verify that the storage group exists.

    8. Click the storage link and then click the Hosts tab. Verify that the storage group contains the servere.lab.example.com and serverf.lab.example.com hosts.

  4. Update the automation controller job settings so that the Per-Host Ansible Fact Cache Timeout setting has a value of 86400 seconds.

    1. Navigate to Settings and then click the Job settings link.

    2. Click Edit.

    3. Update the Per-Host Ansible Fact Cache Timeout field to use a value of 86400 seconds and then click Save.

  5. Modify the Demo Job Template resource to use the LabGit inventory and the Operations machine credential. Select the Enable Fact Storage option.

    1. Navigate to ResourcesTemplates and then click the Edit Template icon for the Demo Job Template resource.

    2. In the Inventory field, select the LabGit inventory.

    3. In the Credentials field, select the Operations credential.

    4. Select the Enable Fact Storage checkbox and then click Save.

  6. Launch a job using the Demo Job Template resource and verify that the job caches facts for the servere.lab.example.com and serverf.lab.example.com hosts in the LabGit inventory.

    1. Navigate to ResourcesTemplates and click the Launch Template icon for the Demo Job Template resource.

    2. 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...
    3. Navigate to ResourcesHosts and click the link for the servere.lab.example.com host in the LabGit inventory. Click the Facts tab and verify that facts exist for the host.

    4. Navigate to ResourcesHosts and click the link for the serverf.lab.example.com host in the LabGit inventory. Click the Facts tab and verify that facts exist for the host.

  7. 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.

    1. Navigate to ResourcesInventories and then click AddAdd smart inventory.

    2. Enter the initial details for the smart inventory:

      FieldValue
      Name LabSmart
      Organization Default
    3. Click the search icon for the Smart host filter field. Create an advanced filter using the following information and then click Select.

      FieldValue
      Filter type Advanced
      Key ansible_facts
      Search field ansible_distribution="RedHat"

      Important

      Depending on the screen resolution on workstation and the size or zoom setting of your web browser, you might not be able to select Advanced. 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.

      Create a smart host filter
    4. Click Save to create the smart inventory.

    5. Click the Hosts 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.

      Note

      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.

Finish

On the workstation machine, change to the student user home directory and use the lab command to complete this exercise. This step is important to ensure that resources from previous exercises do not impact upcoming exercises.

[student@workstation ~]$ lab finish advinventory-review

This concludes the section.

Revision: do467-2.2-08877c1