Bookmark this page

Guided Exercise: Importing External Static Inventories

  • Use an existing static inventory stored in a Git repository in automation controller.

Outcomes

  • Use an existing static inventory file stored in a Git repository.

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

[student@workstation ~]$ lab start advinventory-static

Procedure 7.1. Instructions

  1. Use an existing static inventory file stored in a Git repository.

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

    2. Create a new inventory. Navigate to ResourcesInventories and then click AddAdd inventory.

    3. Use Git Inventory as the name, use Inventory with Git source as the description, and then click Save.

    4. On the Details page, click the Sources tab and then click Add to add a source.

    5. Fill in the details as follows and then click Save.

      FieldValue
      Name Git Source
      Description Git source for inventory
      Source Sourced from a Project
      Project Advanced Inventory
      Inventory file inventory
      Update options Update on launch

      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.

    6. Click Sync and wait until Last Job Status displays Successful.

    7. Navigate to ResourcesInventories and click Git Inventory.

    8. Review the Hosts tab and the Groups tab and notice the hosts and groups that were added to the inventory.

    9. View the details of the web_servers host group and notice that the variables are also imported.

      Note

      Although the variables are displayed in JSON format here, the web UI can also display variables in YAML format.

  2. Modify an existing job template to use the new inventory.

    1. Navigate to ResourcesTemplates.

    2. Click the Edit Template icon for the Hello World job template.

    3. On the Edit Details page, enter Git Inventory in the Inventory field.

      Click Save to save the changes.

    4. On the Details page, click Launch.

    5. Review the Output page. Notice that the job runs on three hosts: servera.lab.example.com, serverb.lab.example.com, and serverc.lab.example.com.

  3. Clone the https://git.lab.example.com/git/advanced-inventory.git Git repository into the /home/student/git-repos directory.

    1. From a terminal, create the /home/student/git-repos directory if it does not already exist, and then change into it.

      [student@workstation ~]$ mkdir -p ~/git-repos/
      [student@workstation ~]$ cd ~/git-repos/
    2. Clone the advanced-inventory git repository and then change into the cloned repository:

      [student@workstation git-repos]$ git clone \
      > https://git.lab.example.com/git/advanced-inventory.git
      Cloning into 'advanced-inventory'...
      ...output omitted...
      [student@workstation git-repos]$ cd advanced-inventory
    3. Review the files in the project directory using the tree command:

      [student@workstation advanced-inventory]$ tree
      .
      ├── ansible.cfg
      ├── group_vars
      │   └── web_servers
      │       └── packages.yml
      ├── hello_world.yml
      └── inventory
      
      2 directories, 4 files
    4. Add serverd.lab.example.com to the [lb_servers] section of the inventory file. The first three lines of the file should consist of the following content:

      [student@workstation advanced-inventory]$ head -n 3 inventory
      [lb_servers]
      servera.lab.example.com
      serverd.lab.example.com
    5. Add the changes to the index, commit the changes using Updated inventory as the commit message, and then push the changes to the remote repository.

      [student@workstation advanced-inventory]$ git add inventory
      [student@workstation advanced-inventory]$ git commit -m "Updated inventory"
      [main e76b744] Updated inventory
       1 file changed, 1 insertion(+)
      [student@workstation advanced-inventory]$ git push -u origin main
      Enumerating objects: 5, done.
      Counting objects: 100% (5/5), done.
      ...output omitted...
      Branch 'main' set up to track remote branch 'main' from 'origin'.
  4. Verify that the changes are reflected in the inventory.

    1. From the automation controller web UI, navigate to ResourcesProjects.

    2. Click the Sync Project icon for the Advanced Inventory project. Wait until the synchronization is complete.

    3. Navigate to ResourcesTemplates and click the Launch Template icon for the Hello World job template.

    4. After the job is finished, review the Output page. Notice that the job runs on four hosts: servera.lab.example.com, serverb.lab.example.com, serverc.lab.example.com, and serverd.lab.example.com.

    5. Navigate to ResourcesInventories and click Git Inventory. Review the Hosts tab and notice that serverd.lab.example.com is now present in the inventory.

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

This concludes the section.

Revision: do467-2.2-08877c1