This part is continuation of Ansible authenticate to Microsoft Azure using credential profiles Part 1. Earlier I used automatic variables to use profile while executing ansible yaml script. But it is sometimes very inefficient, So inside the Ansible azure yaml code you can use profile parameter as highlighted below in the script. Security profiles are found inside ~/.azure/credentials file (Information added with azure subscription_id, client_id, secret, tenant).
#Ansible variable yaml file - rginfo_var.yml --- name: vcloud-lab.com tags: - orgnization:vcloud-lab.com - owner #Ansible Task yaml file - rginfo.yaml --- - name: Get Azure resource group information hosts: localhost connection: local gather_facts: false collections: - azure.azcollection tasks: - name: Include variable file ansible.builtin.include_vars: file: rginfo_var.yml name: rginfo - name: Get Azure resource group information azure_rm_resourcegroup_info: name: "{{ rginfo.name }}" tags: "{{ rginfo.tags }}" profile: dev #list_resources: yes register: resource_groups - name: Show/Print resource group information debug: var: resource_groups
My credentials file under ~/.azure/ looks like below. It is INI file sections with key pair value file, I am using dev profile.
Download this ansible azure profile script here or it is also available on github.com/janviudapi.
Below is the results after running azure ansible yaml file with ansible-playbook command.
Check this out: Ansible authenticate to Microsoft Azure using credential inside yaml file
Useful Articles
Quickstart How to authenticate Ansible with Microsoft Azure
Create an Azure App registrations in Azure Active Directory using PowerShell & AzureCLI
Deploy create Virtual Network vNET in Azure cloud using Ansible
Deploy create Virtual Network vNET in Azure cloud using Ansible
How to install and configure Ansible on Ubuntu
Get Started: Configure Ansible for Azure Cloud Infrastructure
Install the Microsoft Azure CLI on Ubuntu Linux