Lab Guide: Day-2 Operations with Azure Dynamic Inventory
A guide to understanding Day-2 cloud operations and automating common use cases for Microsoft Azure.
Estimated time to complete: 15 minutes
Lab Overview
Welcome to the Ansible Hybrid Cloud Automation - Cloud Operations lab. In this guide, you will learn about a pre-configured Dynamic Inventory for Microsoft Azure and see how it uses tags to manage cloud resources.
1. Task 1: Understanding Credentials
First, you will log in to the Ansible Automation Platform and examine the pre-configured credentials for this lab.
-
Navigate to the Ansible Automation Platform UI.
Click on the Ansible Automation Platform tab at the top of your lab window.
-
Log in with the provided credentials.
Parameter
Value
Username
adminPassword
ansible123! -
Examine the pre-configured credentials.
Credentials are used to authenticate to machines, inventory sources, and version control systems. In this lab, we use three different credentials:
-
RHEL on Azure: An SSH key for the Red Hat Enterprise Linux host.
-
Windows on Azure: Credentials for the Windows Server host.
-
azure_credential: A Microsoft Azure credential for performing actions on the cloud, like creating a virtual network or stopping an instance.
To view them, Expand the
Automation Executionmenu on the left.Automation Execution→Infrastructure→Credentials.
-
| Credential keys are encrypted. Once entered into the Ansible Automation Platform, no one, including administrators, can view the sensitive values. |
2. Task 2: Synchronize the Azure Inventory
Next, you will synchronize the dynamic inventory to ensure the Ansible Automation Platform has the latest host information from Azure.
-
Navigate to the Inventories menu.
To view them, Expand the
Automation Executionmenu on the left.Automation Execution→Infrastructure→Inventories. -
Select the Azure Inventory.
Click on the inventory named
Azure Inventory. -
Synchronize the inventory source.
Select the
Sourcestab and click theRocket Launcher Rocket 🚀 iconbutton on the right side of the screen. This will update the host list from Azure. -
View the updated hosts.
Wait for the synchronization job status to show Successful, then click on the
Hoststab to view the discovered Azure virtual machines.
3. Task 3: Create a Job Template to Retrieve VM Information
Now, you will create a job template to run a playbook that gathers and displays information about your Azure virtual machines.
-
Navigate to the Templates page.
Expand the
Automation Executionmenu on the left.Automation Execution→Templates. -
Initiate the creation of a new job template.
Click the
+ Create Templatethen scroll down and clickCreate job template -
Enter the job template details.
Fill out the form with the following information:
Parameter
Value
Name
Retrieve virtual machine informationInventory
Azure InventoryProject
Cloud Visibility ProjectPlaybook
playbooks/retrieve_vms.ymlExecution Environment
Microsoft Azure Execution EnvironmentCredentials
azure_credentialTo select the azure_credential, click in the text field or on the drop down icon, then selectMicrosoft Azure Resource Manager. -
Save and launch the job template.
Scroll to the bottom, click
Create job template, and then🚀 Launch template. -
Observe the output.
The job output will display information retrieved from your Azure VMs.
| In a highly dynamic environment, the Azure inventory can change often. It’s important to trigger an inventory synchronization before running jobs that rely on that inventory. We will address this in the next task. |
4. Task 4: Build a Workflow to Synchronize the Inventory and Retrieve VM Information
To ensure you are always working with the latest inventory, you will create a workflow that first syncs the Azure inventory and then runs the job template to retrieve VM information.
-
Navigate to the Templates page and initiate workflow creation.
Expand the
Automation Executionmenu on the left.Automation Execution→Templates.
Click the + Create Template then scroll down and click Create workflow job template
-
Enter the workflow details.
Parameter
Value
Name
WORKFLOW - Retrieve virtual machines informationClick
Create workflow job template. The Workflow Visualizer will open. -
Add the first step (Inventory Sync).
Click the
+ Add stepbutton. In the Add step dialog, configure the first step:-
Node TypeSelectInventory Source Sync. -
Inventory SourceSelectAzure Source. -
Click
Next, thenFinish
-
-
Add the second step (Job Template).
Cick on the elipses (3-dots) at the end of
Azure Source, and select+ Add step and link. Configure it as follows:
-
Node TypeSelectJob Template. -
Job TemplateSelectRetrieve virtual machine information. -
StatusSelectRun On Success -
Click
Next, thenFinish -
Click
Saveat the top left corner of the Visualizer.
Your completed workflow is now ready.
-
-
Launch the workflow.
Navigate back to the
Templatespage and launch theWORKFLOW - Retrieve virtual machines informationworkflowtemplate. Once it has ran, you can click on each node in the visualizer to see the output for that specific step.
This workflow ensures your inventory is always up-to-date before you attempt to gather information from it.