Skip to content
Azure on Ansible basis
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


(Azure on Ansible basis)

Table of content


I would like to provide you here some Ansible based solution for Azure


Install packages for ansible

I use Ansible 2.5.x.

# update PIP on your computer
sudo pip install --upgrade pip 

# Install/Update azure 
sudo pip install azure --upgrade 

# Install/Update msrestazure 
sudo pip install msrestazure --upgrade  

# Install/update packaging 
sudo pip install packaging --upgrade 

# Install/Update cryptography 
sudo pip install cryptography --upgrade 

# Install/Update azure module for Ansible 
sudo pip install ansible[azure] --upgrade

Access on Azure for Ansible

Here we create a Service Principal in Azurre and the credential file for Azure access.

Create Service Principal

  1. Login to Azure (and set the default subscription)
az cloud update

az cloud set -n AzureCloud
# Login with your account
az login -u <your username>
# Set the required subsctiption
az account set --subscription <subscriptionID>
  1. Create the service principal for automation
az ad sp create-for-rbac --name Automation_ResourceManager --query '{"client_id": appId, "secret": password, "tenant": tenant}'
  • Please write down and store in a secret place the "secret" because you cannot receive again from system anymore.
  • Required permission for this SP on subscription: Contributor
  • You have to be owner or co-administrator privileges on Azure to be able to create Service Principal
  1. Make credential file

When you execute a playbook with Ansible it requires the Azure login data. For this we have to create a file

# Create directory
mkdir ~/.azure

# Create the azure file for credential
vim ~/.azure/credentials


You are ready to Ansible on Azure.


100 - Fudamentals

A simple and easy to understand example which can work in a live environment as well. Jump there

101 - Health check

A tool for check your Linux server availability with a simple script execution on the remote VM. Jump there

201 - Virtual Machine with multiple NICs

A solution which can deploy VMs with 2 NICs. It deploys VNET, Subnets, NSGs, AvailabilitySets as well. Jump there

You can’t perform that action at this time.