Lab Guide: Cloud Optimization with Ansible
A guide to understanding basic cloud optimization exercises, starting with dynamic inventory and resource tagging.
1. Lab Briefing
This section provides an overview of the lab environment and the importance of resource tagging in the cloud.
1.1. Lab Instructions
Please click the green Start button on the bottom right corner to create the lab environment if it has not already started. To navigate through this briefing, click the white > arrow on the right.

1.2. Lab Diagram
The lab topology consists of one Ansible Automation Platform controller node and two Red Hat Enterprise Linux (RHEL) nodes running in Amazon Web Services (AWS) Elastic Compute Cloud (EC2).

1.3. The Importance of Cloud Tags
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.
For example, the tags on this EC2 instance clearly define its purpose, owner, and provisioning details, which is invaluable for cost management, security audits, and operational clarity.
This concludes your lab briefing.
2. Lab Guide: Hands-On Tasks
Welcome to the Ansible Hybrid Cloud Automation - Cloud Optimization lab. 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.
Estimated time to complete: 10 minutes
2.1. Task 1: Log into Ansible Automation Platform
First, you will log in to the automation controller to begin the lab exercises.
-
Navigate to the Automation Controller UI.
Click on the Automation Controller 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
In this task, you will explore the pre-configured dynamic inventory and inspect the host variables and tags that are automatically discovered from AWS.
-
Navigate to the Inventories menu.
In the left navigation menu, go to Automation Execution → Infrastructure → Inventories.
-
Select the AWS Inventory.
Click on the inventory named
AWS Inventory.
-
View the hosts.
Click on the Hosts tab. You will see two hosts listed, identified by their
Nametag from AWS EC2. -
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, scroll down to the
VARIABLESsection. Note thetagssection, which contains key-value pairs discovered directly from the EC2 instance. We will use these tags in a later step.
| To see these same tags in the AWS console, you can open the AWS console tab in your lab environment, log in, and navigate to the EC2 service to inspect the instances. |
2.3. Task 3: Create a Job Template
Next, you will create a job template to run a playbook that retrieves and displays tag information from your AWS resources.
-
Navigate to the Templates page.
From the left navigation menu, select Automation Execution → Templates.
-
Initiate the creation of a new job template.
Click the Create template button, then select Create job template.

-
Enter the job template details.
Fill out the form with the following information:
Parameter
Value
Name
Retrieve tag informationJob Type
RunInventory
Demo InventoryProject
AWS Demos ProjectExecution Environment
AWS Execution EnvironmentPlaybook
playbooks/tag_info_aws.ymlCredentials
AWS_CredentialTo find the AWS_Credential, you may need to filter the Credential Type toAmazon Web Services. -
Save the job template.
Scroll to the bottom and click the blue Save button.
| The Ansible Playbooks for this lab are sourced from the following project: ansible-cloud/aws_demos. |
2.4. Task 4: Launch the Job Template and Review Output
Finally, you will run the job template and examine the structured data it collects.
-
Launch the job template.
Navigate back to the Templates page, find the
Retrieve tag informationjob template, and click the Launch icon (🚀).
-
Understand the playbook execution.
This playbook runs four tasks to gather and display information:
-
It uses the
amazon.aws.ec2_vpc_net_infomodule to get data for all VPCs. -
It uses the
debugmodule to print the VPC ID, name, and tags. -
It uses the
amazon.aws.ec2_instance_infomodule to get data for all EC2 instances. -
It uses another
debugtask to print the EC2 instance name, ID, and tags.
-
-
Review the job output.
The final task in the playbook uses a loop to display the information for each instance.
- name: Display AWS EC2 info and tags information to terminal debug: msg: - "{{ item.tags['Name'] | default('The tag *Name* Does not exist') }}" - "{{ item.instance_id }}" - "{{ item.tags }}" loop: "{{ ec2_instance_info.instances }}"The output in the automation controller will show this structured data clearly for each resource.
