Lab Guide: Retrieving Cloud Information with Job Templates
This guide explains how to use a Job Template to retrieve information from a public cloud provider.
Estimated time to complete: 20 minutes
1. Lab Overview
Welcome to the second challenge. In this lab, you will learn how to retrieve public cloud information with a job template in the automation controller.
First, log in to the Ansible Automation Platform UI with the following credentials.
Username |
|
Password |
|
2. Task 1: Create a Job Template
To create a Job Template, you need three main components:
-
An inventory to run the automation against.
-
A credential to access the cloud provider’s API.
-
A project to synchronize your Ansible Playbooks from.
In this task, we will combine these components into a new job template.
-
Navigate to the Templates page.
In the left navigation menu, select 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 VPC infoJob Type
RunInventory
Demo InventoryProject
AWS Demos ProjectExecution Environment
AWS Execution EnvironmentPlaybook
playbooks/info_vpcs.ymlCredentials
AWS_CredentialWhen selecting the credential, you may need to filter by the Amazon Web Servicescredential type to find theAWS_Credential. -
Save the job template.
Click the blue Save button.
| The Ansible Playbooks for this lab are sourced from the following project: ansible-cloud/aws_demos. |
3. Task 2: Launch the Job Template
Now that the template is created, let’s run it.
-
Navigate to the Templates page.
If you are not already there, select Templates from the left navigation menu.
-
Launch the job template.
Find the
Retrieve VPC infojob template in the list and click the Launch icon (🚀).
-
Examine the job output.
This playbook runs two tasks:
-
The first task,
amazon.aws.ec2_vpc_net_info, retrieves structured data for all VPCs in theus-east-1region. -
The second task,
ansible.builtin.debug, prints this data to the job output.To view the data, click on the Print vpc info to terminal task. In the details pane that appears, select the JSON tab to see the structured data retrieved from AWS. We have pre-configured one VPC in this region.
This structured data will be used in a future challenge to create dynamic documentation.
-
4. Task 3: Create a Survey
Surveys allow you to prompt a user for information when a job template is launched, making your automation more interactive and flexible.
-
Open the job template’s settings.
Navigate back to the Templates page and click on the name of the
Retrieve VPC infojob template. -
Navigate to the Survey tab.
At the top of the template’s details page, click the Survey tab.
-
Create a new survey question.
Click the blue Add button.
-
Configure the survey question.
Fill out the form with the following values:
Parameter
Value
Question
What AWS region?Description
Choose the AWS region you want to query.Answer variable name
ec2_regionAnswer type
Multiple Choice (single select)Required
Check the box ☑️
Multiple Choice Options
us-east-1,us-east-2,eu-central-1 -
Set the default answer.
Click the radio button next to
us-east-1to make it the default option. -
Save the survey question.
Click the blue Save button.
-
Enable the survey.
After saving, you must enable the survey by clicking the toggle switch at the top of the survey page.
-
Launch the template again.
Click the Launch button. This time, you will be prompted with the survey question you just created.
Feel free to choose a different region and verify that the output changes.
5. Task 4: Create More Job Templates
You can create similar job templates to gather information about other AWS resources.
-
Create a job template to retrieve EC2 instance information.
Parameter
Value
Name
Retrieve EC2 instances infoPlaybook
playbooks/info_instances.ymlUse the same Inventory, Project, Execution Environment, and Credentials as the first template. -
Create a job template to retrieve Internet Gateway (IGW) information.
Parameter
Value
Name
Retrieve IGWs infoPlaybook
playbooks/info_igws.yml -
(Optional) Create a combined information job template.
This template combines information from VPCs, EC2 instances, and IGWs to provide a holistic view of your cloud infrastructure.
Parameter
Value
Name
Retrieve Combined infoPlaybook
playbooks/info_combined.ymlWhen you run this combined template, a cloud operator can quickly see how many instances are online in a given region, which VPCs they reside on, and their associated IGWs. This combined view helps identify unused resources, such as the retired VPCs shown in the example output below.
6. Next Steps
You have successfully completed this lab. Press the Check button in the lab environment to proceed to the next challenge.
7. Troubleshooting
If you have encountered an issue or have noticed something not quite right, please open an issue on GitHub.