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.

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
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.
Username |
|
Password |
|
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.
-
Navigate to the Credentials page.
Expand the
Automation Executionmenu on the left.Automation Execution→Infrastructure→Credentials. -
Create a new credential.
Click the blue
+ Create credentialbutton. -
Enter the credential details.
Fill out the form with the following information:
Parameter
Value
Name
RHEL on AzureOrganization
DefaultCredential Type
MachineUsername
rheluserPassword
RedHatAnsible123! -
Save the credential.
Click the blue
Create credentialbutton 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.
-
Navigate to the Inventories page.
Expand the
Automation Executionmenu on the left.Automation Execution→Infrastructure→Inventories. -
Create a new inventory.
Click the blue
+ Create inventorybutton and select `Create inventory. -
Enter the inventory details.
Parameter
Value
Name
Azure InventoryOrganization
Default -
Save the inventory.
Click the blue
Create inventorybutton.
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.
-
Navigate to the Sources tab.
Within your newly created
Azure Inventory, click theSourcestab. -
Create a new source.
Click the blue
+ Create sourcebutton. -
Enter the source details.
Fill out the form with the following information:
Parameter
Value
Name
Azure SourceExecution Environment
Microsoft Azure Execution EnvironmentSource
Microsoft Azure Resource ManagerCredential
azure_credential -
Add the source variables.
In the
Source variablesYAML editor below, paste the following code. This configures the inventory to use thenametag as the hostname and the public IP address for connections.--- hostnames: - tags.name compose: ansible_host: public_ipv4_address[0] -
Save and sync the source.
Click
Create source, then clickLaunch inventory updateto 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.
-
Navigate to the Hosts view.
Once the sync is complete, return to the
Azure Inventorydetails and click theHoststab. You should see two hosts listed:RHEL-ansibleandWIN-ansible. -
Run an ad-hoc command on the RHEL host.
Select the checkbox next to
RHEL-ansibleand click theRun Commandbutton. A wizard will appear. -
Configure the command.
Fill out the wizard prompts as follows:
-
Details View: From the Module dropdown, select
ping. ClickNext. -
Execution Environment View: Select
Default execution environment. ClickNext. -
Credential View: Select
RHEL on Azure. ClickNext.
-
-
Launch the ad-hoc command.
On the Review screen, click the
Finishbutton.
The ad-hoc command runs the Ansible ping module, which verifies connectivity to the RHEL instance running on Azure.
7. Troubleshooting
If you have encountered an issue or have noticed something not quite right, please open an issue on GitHub.