Lab Guide: Understanding Tags for Azure Optimization
A guide to understanding basic cloud optimization exercises, starting with dynamic inventory and resource tagging in Microsoft Azure.
1. Lab Briefing
This section provides an overview of the lab environment and the importance of resource tagging in the cloud.
1.1. Lab Summary
Welcome to the Ansible Hybrid Cloud Automation - Cloud Optimization lab. In this lab, you will use Microsoft Azure as the public cloud provider. We have created an Azure account just for this lab so you can automate against a real Microsoft Azure environment with two virtual machines already running.

1.2. Cloud Resources
Cloud environments are composed of numerous resources, including instances, containers, networks, and more. To effectively manage these resources, it is crucial to use tags. Tags are simple key-value pairs that help you organize, filter, and track your assets. There is no limit to how many tags a resource can have.
2. Lab Guide: Hands-On Tasks
Estimated time to complete: 10 minutes
In this first challenge, you will learn about the pre-configured Dynamic Inventory for this lab and see how it uses tags to identify resources.
2.1. Task 1: Log into Automation Controller
First, you will log in to the Ansible Automation Platform to begin the lab exercises.
-
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.
Username
adminPassword
ansible123!
After logging in, you will land on the main dashboard.
2.2. Task 2: Examine the Dynamic Inventory
Next, you will explore the pre-configured dynamic inventory and inspect the host variables and tags that were automatically discovered from Azure.
-
Navigate to the Inventories page.
To view them, Expand the
Automation Executionmenu on the left.Automation Execution→Infrastructure→Inventories. -
Select the Azure Inventory.
The inventory has been created for you and synced from Azure automatically. Click on the inventory named
Azure Inventory.
-
View the hosts.
Click on the
Hoststab. You will see two hosts listed.
-
Inspect a host’s variables.
Click on one of the hosts to open its details page.
-
Examine the tags.
On the host’s Details tab, find the
VARIABLESsection.Scroll down to the
tagssection in theVariablesframe to see the key-value pairs discovered from the Azure virtual machine. Take note of the tags, as you will use them in a future challenge. You can view the details in bothYAMLandJSONformat.
To see these same tags on the Azure resource, you can switch to the Cloud(Azure)tab at the top of your lab environment.
2.3. Task 3: Create a Job Template to Display Tags
Now, you will create a job template to run a playbook that retrieves and displays tag information.
-
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
Display tag informationJob Type
RunInventory
Azure InventoryProject
Cloud Visibility ProjectPlaybook
playbooks/display_tags.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.
| The Ansible Playbooks for this lab are sourced from this project on GitHub. |
2.4. Task 4: Launch the Job and Review Output
Finally, you will run the job template and examine the structured data it collects.
-
Launch the job template.
Scroll to the bottom, and then
🚀 Launch template.
-
Understand the playbook execution.
This playbook runs three tasks:
-
It uses the
azure.azcollection.azure_rm_virtualmachine_infomodule to retrieve information for all virtual machines. -
The second task prints the entire JSON payload from the first task.
-
The third task prints a formatted summary of the name, tags, and power state for each VM.
- name: print tags ansible.builtin.debug: msg: - name: "{{ item.name }}" - tags: "{{ item.tags }}" - power_state: "{{ item.power_state }}" loop: "{{ retrieved_info.vms | list }}" loop_control: label: "virtual machine info and associated tags"
-
-
Review the job output.
The output in the automation controller will show this structured data clearly for each resource.