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.

Diagram of infrastructure visibility

1.3. Understanding Job Templates

A job template is a definition and set of parameters for running an Ansible job. Job templates are useful for executing the same job many times and they encourage the reuse of Ansible playbook content and collaboration between teams.

Example of a job template

1.4. Getting Started

That is the end of your challenge briefing! Let’s get started!


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.

Table 1. Login Credentials

Username

admin

Password

ansible123!

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.

  1. Navigate to the Templates page.

    Expand the Automation Execution menu on the left. Automation ExecutionTemplates.

  2. Create a new job template.

    Click the + Create Template then scroll down and click Create job template

  3. Enter the job template details.

    Fill out the form with the following information:

    Parameter

    Value

    Name

    Retrieve region info

    Job Type

    Run

    Inventory

    Azure Inventory

    Project

    Cloud Visibility Project

    Playbook

    playbooks/retrieve_regions.yml

    Execution Environment

    Microsoft Azure Execution Environment

    Credentials

    azure_credential

    To select the azure_credential, click in the text field or on the drop down icon, then select Microsoft Azure Resource Manager.
  4. 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.

  1. Launch the job template.

    From the Templates page, find the Retrieve region info template and then 🚀 Launch template.

  2. 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_regions task, then select the Data and then select the JSON sub-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.

  1. Create the "Retrieve virtual networks info" template.

    Parameter

    Value

    Name

    Retrieve virtual networks info

    Playbook

    playbooks/retrieve_networks.yml

    Use the same Inventory, Project, Execution Environment, and Credentials as the first template. Save the template.
  2. Save the job template.

    Scroll to the bottom, click Create job template.

  3. Create the "Retrieve virtual machines info" template.

    Parameter

    Value

    Name

    Retrieve virtual machines info

    Playbook

    playbooks/retrieve_vms.yml

    Use the same Inventory, Project, Execution Environment, and Credentials as the first template. Save the template.
  4. Save the job template.

    Scroll to the bottom, click Create job template.

  5. Run the new templates.

    Launch both new job templates and examine their output. You will see that the Retrieve virtual machines info job retrieves two virtual machines: RHEL-ansible and WIN-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.

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

    Survey tab

  2. Create a new survey question.

    Click the blue + Create survey question button.

    Fill out the form with the following values:

    Parameter

    Value

    Question

    What tag do you want to filter on?

    Answer variable name

    your_tags

    Answer type

    Text

    Required

    Check the box ☑️

    Default answer

    demo:true

    Click the blue Create survey question button to save the question.

  3. Enable and launch the survey.

    Enable the survey by clicking the toggle switch at the top of the page.

    Survey enabled toggle

    Now, launch the Retrieve virtual machines info job template again. This time, you will see a survey prompt.

  4. Use the survey to filter results.

    Surveys allow you to abstract complexity by setting playbook variables with user-friendly questions.

    Try using os:windows to retrieve only the Windows virtual machine, or os:linux to retrieve only the RHEL machine. This is extremely useful for managing hundreds of virtual machines.

    os:linux

    os:windows


3. Next Steps

Press the Next button below to proceed to the next challenge.

4. Troubleshooting

If you have encountered an issue or have noticed something not quite right, please open an issue on GitHub.