Lab Guide: Provisioning an Azure VM with Ansible Lightspeed
A guide to using Ansible Lightspeed to generate a playbook that provisions a virtual machine in Microsoft Azure.
Introduction and Setup
|
Important Note About This Lab IBM watsonx Code Assistant models are continuously updated and improved. As a result, some specific task generation challenges in this lab may not work exactly as described due to model updates. This is expected behavior. The primary goal of this lab is to help you understand the key features of Ansible Lightspeed, including:
If a specific prompt doesn’t generate suggestions as expected:
|
In this challenge, you will use Ansible Lightspeed to generate an Ansible Playbook that automates the provisioning of a Microsoft Azure Virtual Machine.
Your Mission
Your goal is to use Ansible Lightspeed to generate a playbook that automates the following task:
-
Provision a VM called
vm-lightspeedin the demo Azure account provided by the lab.
The examples used in this lab are available in the Ansible Lightspeed Demo repository.
|
Azure Credentials: This lab uses a temporary Azure account. You’ll find the credentials in the AWS/Azure tab at the top of your lab environment when you need them in Task 4. Need Help? If you encounter difficulties or want to verify your work, you can reference the solution playbook at |
Task 1: Generate Playbook Tasks with Ansible Lightspeed
You will now edit a pre-created playbook file and use a natural language prompt to have Ansible Lightspeed generate the necessary task.
-
Open the playbook file in VS Code.
-
Click on the VS Code tab at the top of your lab environment
Work in a new browser tab: For the best experience with Ansible Lightspeed features, click the VS Code tab to open it in a new browser tab rather than using the inline embedded window.
-
On the left side of VS Code, click the Explorer icon (two overlapping documents) to show the file explorer
-
In the file explorer, expand these folders: playbooks → cloud → azure
-
Click on demo_provision_azure_vm.yml to open it in the editor
-
-
Generate the VM provisioning task.
-
In the playbook file, find the line:
#- name: Create a VM called vm-lightspeed using vm_config var -
Uncomment the line by removing the
#(or pressCTRL+/for Windows/Linux orCMD+/for Mac) -
Place your cursor at the end of the line (after "var")
-
Press
ENTERto create a new line -
Wait a moment - Ansible Lightspeed will show a suggestion in gray text
-
Press
TABto accept the suggestion_Lightspeed Highlight:_ Lightspeed correctly uses the `azure.azcollection.azure_rm_virtualmachine` module to generate a task that creates an Azure virtual machine. The suggestion also correctly uses the `vm_config` variable from the playbook's `vars` section.
-
-
Save the playbook.
Click **File** → **Save** from the top menu, or press `CTRL+S` (Windows/Linux) or `CMD+S` (Mac).
Task 2: Review Ansible Lightspeed Training Matches
One of Ansible Lightspeed’s key differentiators is providing information on the potential training data used to generate suggestions.
-
Open the Lightspeed Training Matches view.
-
At the top of VS Code, click View in the menu bar
-
Select Open View…
-
In the search box that appears, type
Lightspeed -
Click on Lightspeed Training Matches from the list
-
-
Examine a training match.
-
In your playbook, click on the task name you generated
-
Delete one line of the generated code and press
ENTERto regenerate the suggestion -
Look at the Lightspeed Training Matches pane (usually at the bottom of VS Code)
-
You’ll see potential training sources. Click on any entry to see details including the content source, author, and license information.
-
Task 3: Run the Playbook
You can now choose to run the completed playbook using either the automation controller or ansible-navigator.
Option 1: Using Automation Controller
-
Commit and push the playbook to Git.
-
On the left side of VS Code, click the Source Control icon (it looks like a branch with circles)
-
You should see
demo_provision_azure_vm.ymllisted under "Changes" -
Hover over the file name and click the + (plus) icon that appears to stage the changes
-
At the top, in the "Message" box, type a commit message like:
Provision Azure VM -
Click the Commit button (checkmark icon)
-
Click the Sync Changes button to push your playbook to the Git repository
-
-
Run the playbook from Automation Controller.
-
Click the Ansible Automation Platform tab at the top of the lab window
-
If you see a login screen, enter:
-
Username:
admin -
Password:
ansible123!
-
-
On the left sidebar, click Resources → Templates
-
Find the template named Provision Azure VM
-
Click the launch icon (🚀 rocket ship) on the right side of that row
-
Wait for the job to complete successfully (you’ll see a green "Successful" status)
-
Option 2: Using ansible-navigator
-
Open a terminal in VS Code.
-
Make sure you’re on the VS Code tab
-
Look at the top menu bar and click Terminal → New Terminal
-
A terminal panel will open at the bottom of VS Code
-
-
Navigate to the playbook folder.
In the terminal, type the following command and press `ENTER`:
cd playbooks/cloud/azure -
Run the playbook with ansible-navigator.
Type the following command and press `ENTER`:
ansible-navigator run demo_provision_azure_vm.ymlThe playbook will run and show you the results. Press the `ESC` key to return to the terminal prompt when it's done.
Task 4: Verify the VM Provisioning
Finally, verify that the new virtual machine is running in the Azure Portal.
-
Get your Azure credentials and access the portal.
-
At the very top of your lab environment, click the AWS/Azure tab
-
Scroll down to the Azure credentials section
-
You’ll see Azure account credentials displayed (Subscription ID, Email, Password, and Portal URL)
-
Click the Azure Portal URL link (or copy it to a new browser tab)
-
-
Log in to the Azure Portal.
-
Go back to the AWS/Azure tab to copy the credentials
-
Copy the Email and Password shown in the Azure section
-
Paste them into the Azure login page
-
Click Sign In
-
If prompted with additional security questions, click Skip for now or Ask later
-
-
View your Azure VM.
-
In the Azure Portal, look for the search bar at the top
-
Type
Virtual machinesand click on Virtual machines from the results -
You should see your new VM named vm-lightspeed in the list
-
The status should show as "Running"
-
This confirms that your Ansible playbook successfully created the Azure VM!
-
Conclusion and Additional Resources
Congratulations! You’ve successfully created an Ansible Playbook using Ansible Lightspeed to deploy a VM on Azure!
|
Solution Playbook Available: If you encountered issues or want to compare your work, you can review the complete solution at |
Additional Resources
-
More information on Red Hat Ansible Lightspeed with IBM watsonx Code Assistant