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.

Table 1. Login Credentials

Username

admin

Password

ansible123!


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.

  1. Navigate to the Templates page.

    In the left navigation menu, select Templates.

  2. Initiate the creation of a new job template.

    Click the Create template button, then select Create job template.

    Create a new job template
  3. Enter the job template details.

    Fill out the form with the following information:

    Parameter

    Value

    Name

    Retrieve VPC info

    Job Type

    Run

    Inventory

    Demo Inventory

    Project

    AWS Demos Project

    Execution Environment

    AWS Execution Environment

    Playbook

    playbooks/info_vpcs.yml

    Credentials

    AWS_Credential

    When selecting the credential, you may need to filter by the Amazon Web Services credential type to find the AWS_Credential.
  4. 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.

  1. Navigate to the Templates page.

    If you are not already there, select Templates from the left navigation menu.

  2. Launch the job template.

    Find the Retrieve VPC info job template in the list and click the Launch icon (🚀).

    Launch Job Icon
  3. 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 the us-east-1 region.

    • 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.

      VPC structured data output

      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.

  1. Open the job template’s settings.

    Navigate back to the Templates page and click on the name of the Retrieve VPC info job template.

  2. Navigate to the Survey tab.

    At the top of the template’s details page, click the Survey tab.

    Survey Tab
  3. Create a new survey question.

    Click the blue Add button.

  4. 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_region

    Answer type

    Multiple Choice (single select)

    Required

    Check the box ☑️

    Multiple Choice Options

    us-east-1, us-east-2, eu-central-1

  5. Set the default answer.

    Click the radio button next to us-east-1 to make it the default option.

  6. Save the survey question.

    Click the blue Save button.

  7. Enable the survey.

    After saving, you must enable the survey by clicking the toggle switch at the top of the survey page.

    Enable Survey Toggle
  8. Launch the template again.

    Click the Launch button. This time, you will be prompted with the survey question you just created.

    Survey Prompt

    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.

  1. Create a job template to retrieve EC2 instance information.

    Parameter

    Value

    Name

    Retrieve EC2 instances info

    Playbook

    playbooks/info_instances.yml

    Use the same Inventory, Project, Execution Environment, and Credentials as the first template.
  2. Create a job template to retrieve Internet Gateway (IGW) information.

    Parameter

    Value

    Name

    Retrieve IGWs info

    Playbook

    playbooks/info_igws.yml

  3. (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 info

    Playbook

    playbooks/info_combined.yml

    When 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.

    Combined cloud awareness output

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.