Events
Mar 17, 11 PM - Mar 21, 11 PM
Join the meetup series to build scalable AI solutions based on real-world use cases with fellow developers and experts.
Register nowThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Get started with Ansible by configuring Ansible on Azure and creating a basic Azure resource group.
Ansible is an open-source product that automates cloud provisioning, configuration management, and application deployments. Using Ansible you can provision virtual machines, containers, and network and complete cloud infrastructures. Also, Ansible allows you to automate the deployment and configuration of resources in your environment.
This article describes getting started with Ansible from the Azure Cloud Shell environment.
If you already have a Cloud Shell session open, you can skip to the next section.
Browse to the Azure portal
If necessary, log in to your Azure subscription and change the Azure directory.
Open Cloud Shell.
If you haven't previously used Cloud Shell, configure the environment and storage settings.
Select the command-line environment.
When signed into the Cloud Shell, Ansible authenticates with Azure to manage infrastructure without any extra configuration.
When working with multiple subscriptions, specify the subscription Ansible uses by exporting the AZURE_SUBSCRIPTION_ID
environment variable.
To list all of your Azure subscriptions, run the following command:
az account list
Using your Azure subscription ID, set the AZURE_SUBSCRIPTION_ID
as follows:
export AZURE_SUBSCRIPTION_ID=<your-subscription-id>
You now have configured Ansible for use within Cloud Shell!
This section shows how to create a test resource group within your new Ansible configuration. If you don't need to do that, you can skip this section.
Save the following code as create_rg.yml
.
---
- hosts: localhost
connection: local
tasks:
- name: Creating resource group - "{{ name }}"
azure_rm_resourcegroup:
name: "{{ name }}"
location: "{{ location }}"
register: rg
- debug:
var: rg
Run the playbook using ansible-playbook. Replace the placeholders with the name and location of the resource group to be created.
ansible-playbook create_rg.yml --extra-vars "name=<resource_group_name> location=<resource_group_location>"
Key points:
register
variable and debug
section of the playbook, the results display when the command finishes.Save the following code as delete_rg.yml
.
---
- hosts: localhost
tasks:
- name: Deleting resource group - "{{ name }}"
azure_rm_resourcegroup:
name: "{{ name }}"
state: absent
register: rg
- debug:
var: rg
Run the playbook using the ansible-playbook command. Replace the placeholder with the name of the resource group to be deleted. All resources within the resource group will be deleted.
ansible-playbook delete_rg.yml --extra-vars "name=<resource_group>"
Key points:
register
variable and debug
section of the playbook, the results display when the command finishes.Events
Mar 17, 11 PM - Mar 21, 11 PM
Join the meetup series to build scalable AI solutions based on real-world use cases with fellow developers and experts.
Register nowTraining
Module
Control Azure services with the CLI - Training
Learn the steps to install the Azure CLI locally, create a website, and manage Azure resources using the CLI.
Certification
Microsoft Certified: Azure Administrator Associate - Certifications
Demonstrate key skills to configure, manage, secure, and administer key professional functions in Microsoft Azure.
Documentation
Get Started - Configure Ansible on an Azure VM
Learn how to install and configure Ansible on an Azure VM for managing Azure resources.
Quickstart - Create an Azure service principal for Ansible
In this quickstart, learn how to create an Azure Service Principal to authenticate to Azure.
Create a Linux virtual machines in Azure using Ansible
Learn how to create a Linux virtual machine in Azure using Ansible