Lab Guide: Ansible Dynamic Inventory for AWS

An overview of setting up a dynamic inventory for AWS EC2 within the automation controller.

Estimated time to complete: 10 minutes


1. Lab Overview

Welcome to the Ansible Hybrid Cloud Automation - Infrastructure Visibility lab. In this guide, you will learn how to set up and use a dynamic inventory for AWS EC2 in the automation controller.

First, log in to the Ansible Automation Platform UI with the following credentials.

Table 1. Login Credentials

Username

admin

Password

ansible123!


2. Task 1: Understanding Credentials

Credentials are used for authentication when launching Jobs against machines, synchronizing with inventory sources, and importing project content from version control systems. In this lab, we use two pre-configured credentials:

  • RHEL on AWS - SSH KEY: An SSH key for connecting to the Red Hat Enterprise Linux hosts running on AWS.

  • AWS_Credential: An AWS credential for performing actions on the AWS cloud, such as creating a VPC or managing instances.

    1. Navigate to the Credentials menu.

      In the Controller UI, go to the left navigation menu and select InfrastructureCredentials.

      Credential keys are encrypted. Once entered into the automation controller, no one, including administrators, can view the sensitive values.

3. Task 2: Creating an Inventory

In this task, you will create a new inventory to hold your dynamically discovered hosts from AWS.

  1. Navigate to the Inventories menu.

    From the left navigation menu, select InfrastructureInventories.

  2. Initiate inventory creation.

    Click the blue Create inventory button and select Create inventory.

    Create a new inventory
  3. Enter the inventory details.

    Fill out the form with the following information:

    Parameter

    Value

    Name

    AWS Inventory

    Organization

    Default

  4. Save the inventory.

    Click the blue Create inventory button.


4. Task 3: Creating an Inventory Source

Now you will configure a source to dynamically pull host information from your AWS account into the inventory you just created.

  1. Navigate to the Sources tab.

    Within your newly created AWS Inventory, click the Sources tab at the top.

    Inventory Sources Tab
  2. Initiate source creation.

    Click the blue Create source button.

  3. Enter the source details.

    Fill out the form with the following information:

    Parameter

    Value

    Name

    AWS Source

    Source

    Amazon EC2

  4. Configure the source credential.

    After selecting Amazon EC2 as the source, more options will appear. Find the Credential field.

    Parameter

    Value

    Credential

    AWS_Credential

    You may need to click the search icon (magnifying glass) to browse and select the AWS_Credential.
  5. Save the source.

    Click the blue Create source button.

  6. Launch the inventory sync.

    Click the Sync button in the top right to retrieve the host inventory from AWS EC2.


5. Task 4: Examining the Inventory

For this final task, we will examine the hosts that were added to the inventory and then run an ad-hoc command to verify connectivity.

  1. Return to the Hosts view.

    Click the Hosts tab. You should now see two hosts listed, dynamically pulled from AWS.

    AWS Inventory Menu
  2. Run an ad-hoc command.

    Select the checkbox next to each host and click the Run command button. A wizard will appear.

  3. Configure the command details.

    • Module: ping

    • Click Next.

  4. Select the Execution Environment.

    • Select Default execution environment.

    • Click Next.

  5. Select the machine credential.

    • Select RHEL on AWS - SSH KEY. (You may have to browse to find it).

    • Click Next.

  6. Launch the job.

    Review the details on the Preview screen and click the Finish button.

    The ad-hoc command runs the Ansible ping module, which verifies SSH connectivity between the control node and the two RHEL EC2 instances. The output should show a "SUCCESS" status.

    Successful ping command output

6. Next Steps

You have successfully completed this lab. Press the Check button in the lab environment to proceed to the next challenge.

7. Troubleshooting

If you have encountered an issue or have noticed something not quite right, please open an issue on GitHub.