Lab Guide: Retrieving Azure Cloud Information
A guide to performing automation against Microsoft Azure to retrieve information about regions, virtual networks, and virtual machines.
1. Lab Briefing
This section provides an overview of the lab challenge and instructions for getting started.
1.1. Challenge Summary
In this challenge, you’ll perform automation against your Microsoft Azure public cloud environment. You will create a Job Template in Ansible Automation Platform and launch it to perform the following actions:
-
Retrieve information about Azure regions.
-
Retrieve information about Virtual Networks.
-
Retrieve information about Virtual Machines.
1.2. Infrastructure Visibility
Cloud automation begins and ends with structured data. Ansible Automation Platform can help retrieve information from your public cloud to help you understand your cloud footprint and make informed decisions.
2. Lab Guide: Hands-On Tasks
Estimated time to complete: 15 minutes
Welcome to the second challenge. You will now learn how to retrieve public cloud information with a job template.
First, log in to the Ansible Automation Platform with the following credentials.
Username |
|
Password |
|
2.1. Task 1: Create the "Retrieve region info" Job Template
To create a Job Template, you need three main components: an inventory, a credential, and a project.
-
Navigate to the Templates page.
Expand the
Automation Executionmenu on the left.Automation Execution→Templates. -
Create 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 region infoJob Type
RunInventory
Azure InventoryProject
Cloud Visibility ProjectPlaybook
playbooks/retrieve_regions.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 the job template.
Scroll to the bottom, click
Create job template, and then🚀 Launch template.
| The Ansible Playbooks for this lab are sourced from this project on GitHub. |
2.2. Task 2: Launch the Job Template
Now you are ready to run the job and view the retrieved data.
-
Launch the job template.
From the Templates page, find the
Retrieve region infotemplate and then🚀 Launch template. -
Review the job output.
This playbook runs two tasks. The first,
azure.azcollection.azure_rm_resource_info, retrieves structured data. The second,ansible.builtin.debug, prints it to the job output.Click on the
print var all_regionstask, then select theDataand then select theJSONsub-tab to see the structured data for all available Azure regions.
2.3. Task 3: Create More Job Templates
Next, create two more job templates to retrieve information about virtual networks and virtual machines.
-
Create the "Retrieve virtual networks info" template.
Parameter
Value
Name
Retrieve virtual networks infoPlaybook
playbooks/retrieve_networks.ymlUse the same Inventory, Project, Execution Environment, and Credentials as the first template. Save the template. -
Save the job template.
Scroll to the bottom, click
Create job template. -
Create the "Retrieve virtual machines info" template.
Parameter
Value
Name
Retrieve virtual machines infoPlaybook
playbooks/retrieve_vms.ymlUse the same Inventory, Project, Execution Environment, and Credentials as the first template. Save the template. -
Save the job template.
Scroll to the bottom, click
Create job template. -
Run the new templates.
Launch both new job templates and examine their output. You will see that the
Retrieve virtual machines infojob retrieves two virtual machines:RHEL-ansibleandWIN-ansible.
2.4. Task 4: Create a Survey to Filter VMs
To make the Retrieve virtual machines info template more flexible, you will add a survey to filter the results by tags.
-
Navigate to the Survey tab for the template.
Go to the Templates page, click on the name
Retrieve virtual machines info, and then click the Survey tab.
-
Create a new survey question.
Click the blue
+ Create survey questionbutton.Fill out the form with the following values:
Parameter
Value
Question
What tag do you want to filter on?Answer variable name
your_tagsAnswer type
TextRequired
Check the box ☑️
Default answer
demo:trueClick the blue
Create survey questionbutton to save the question. -
Enable and launch the survey.
Enable the survey by clicking the toggle switch at the top of the page.

Now, launch the
Retrieve virtual machines infojob template again. This time, you will see a survey prompt. -
Use the survey to filter results.
Surveys allow you to abstract complexity by setting playbook variables with user-friendly questions.
Try using os:windowsto retrieve only the Windows virtual machine, oros:linuxto retrieve only the RHEL machine. This is extremely useful for managing hundreds of virtual machines.os:linuxos:windows
4. Troubleshooting
If you have encountered an issue or have noticed something not quite right, please open an issue on GitHub.