Lab Guide: Azure Dynamic Inventory and Visibility

A guide to understanding and using the automation controller to create and manage a dynamic inventory for Microsoft Azure.


1. Lab Briefing

This section provides an overview of the lab environment and key concepts in Ansible Automation Platform.

The goal of this lab is to illustrate how Ansible info modules can retrieve from public clouds can provide us awareness of our cloud footprint easily and output it to anything.

2. Automation controller

The control plane for Ansible Automation Platform is the automation controller. It helps standardize how automation is deployed, initiated, delegated, and audited. You can manage inventory, launch and schedule workflows, track changes, and integrate reporting, all from a centralized user interface and RESTful API.

Automation controller dashboard

3. Inventories

An inventory is a collection of hosts against which jobs can be launched, similar to an Ansible inventory file. Inventories are divided into groups, and these groups contain the actual hosts. Groups can be sourced manually or dynamically from a supported cloud provider using Inventory Plugins.

Some of the available inventory plugins include:

  • Amazon Web Services EC2

  • Google Compute Engine

  • Microsoft Azure Resource Manager

  • VMware vCenter

4. Lab Diagram

This diagram shows the topology for this lab.

Lab topology diagram

This concludes your lab briefing.


5. Lab Guide: Hands-On Tasks

Estimated time to complete: 10 minutes

Welcome to the Ansible for Azure Automation - Infrastructure Visibility lab. In this first challenge, you will learn how to set up a dynamic inventory for Azure virtual machines in the automation controller.

First, log in to the automation controller with the following credentials.

Table 1. Login Credentials

Username

admin

Password

ansible123!

5.1. Task 1: Configure Credentials

Credentials are used to authenticate to machines, inventory sources, and version control systems. The azure_credential for accessing the Azure cloud is already configured. You will now create a Machine credential to access the RHEL virtual machine.

  1. Navigate to the Credentials page.

    Expand the Automation Execution menu on the left. Automation ExecutionInfrastructureCredentials.

  2. Create a new credential.

    Click the blue + Create credential button.

  3. Enter the credential details.

    Fill out the form with the following information:

    Parameter

    Value

    Name

    RHEL on Azure

    Organization

    Default

    Credential Type

    Machine

    Username

    rheluser

    Password

    RedHatAnsible123!

  4. Save the credential.

    Click the blue Create credential button at the bottom.

Passwords and keys are encrypted. Once saved in the automation controller, no one, including administrators, can view the sensitive values.

5.2. Task 2: Create an Inventory

Next, you will create a new inventory to hold your dynamically discovered hosts from Azure.

  1. Navigate to the Inventories page.

    Expand the Automation Execution menu on the left. Automation ExecutionInfrastructureInventories.

  2. Create a new inventory.

    Click the blue + Create inventory button and select `Create inventory.

  3. Enter the inventory details.

    Parameter

    Value

    Name

    Azure Inventory

    Organization

    Default

  4. Save the inventory.

    Click the blue Create inventory button.

5.3. Task 3: Create an Inventory Source

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

  1. Navigate to the Sources tab.

    Within your newly created Azure Inventory, click the Sources tab.

  2. Create a new source.

    Click the blue + Create source button.

  3. Enter the source details.

    Fill out the form with the following information:

    Parameter

    Value

    Name

    Azure Source

    Execution Environment

    Microsoft Azure Execution Environment

    Source

    Microsoft Azure Resource Manager

    Credential

    azure_credential

  4. Add the source variables.

    In the Source variables YAML editor below, paste the following code. This configures the inventory to use the name tag as the hostname and the public IP address for connections.

    ---
    hostnames:
      - tags.name
    compose:
      ansible_host: public_ipv4_address[0]
  5. Save and sync the source.

    Click Create source, then click Launch inventory update to retrieve the inventory from Microsoft Azure.

5.4. Task 4: Examine the Inventory and Run an Ad-Hoc Command

Finally, you will examine the discovered hosts and run a command to verify connectivity.

  1. Navigate to the Hosts view.

    Once the sync is complete, return to the Azure Inventory details and click the Hosts tab. You should see two hosts listed: RHEL-ansible and WIN-ansible.

  2. Run an ad-hoc command on the RHEL host.

    Select the checkbox next to RHEL-ansible and click the Run Command button. A wizard will appear.

  3. Configure the command.

    Fill out the wizard prompts as follows:

    1. Details View: From the Module dropdown, select ping. Click Next.

    2. Execution Environment View: Select Default execution environment. Click Next.

    3. Credential View: Select RHEL on Azure. Click Next.

  4. Launch the ad-hoc command.

    On the Review screen, click the Finish button.

The ad-hoc command runs the Ansible ping module, which verifies connectivity to the RHEL instance running on Azure.


6. Next Steps

Press the Next button below 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.