Menu

Virtual Geek

Tales from real IT system administrators world and non-production environment

Ansible authenticate to Microsoft Azure using credential profiles Part 2

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.

Microsoft Azure ubuntu ansible redhat .azure credentials authentication prod dev default subscription client secret tenant AZURE_PROFILE resource group azure collection password ad service principal app registrations.png

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

Microsoft azure redhat ansible yaml ansible-playbook subscriptions provisionstate resource group inventory host automation iac yml declarative script code credenital profiles azure.png

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

Go Back

Comment

Blog Search

Page Views

11272722

Follow me on Blogarama