Menu

Virtual Geek

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

Get Started: Configure Ansible for Azure Cloud Infrastructure

This is second part of How to install and configure Ansible on Ubuntu, where I will be installing and configuring Microsoft Azure modules to use it with ansible for Microsoft Azure cloud infrastructure automation. I have python-pip3 is already installed, The next instructions is to install ansible[azure] packages using pip3 as shown below. 

Microsoft Azure pip3 install ansible[azure] python requirement already satisfied ansible-core jinja2 pyyaml resolvelib markupsafe pyparsing.png

All below prerequisite packages are installed.

root@ansible:~# sudo pip3 install ansible[azure]
Requirement already satisfied: ansible[azure] in /usr/local/lib/python3.8/dist-packages (5.5.0)
WARNING: ansible 5.5.0 does not provide the extra 'azure'
Requirement already satisfied: ansible-core~=2.12.3 in /usr/local/lib/python3.8/dist-packages (from ansible[azure]) (2.12.3)
Requirement already satisfied: jinja2 in /usr/local/lib/python3.8/dist-packages (from ansible-core~=2.12.3->ansible[azure]) (3.0.3)
Requirement already satisfied: PyYAML in /usr/lib/python3/dist-packages (from ansible-core~=2.12.3->ansible[azure]) (5.3.1)
Requirement already satisfied: packaging in /usr/local/lib/python3.8/dist-packages (from ansible-core~=2.12.3->ansible[azure]) (21.3)
Requirement already satisfied: resolvelib<0.6.0,>=0.5.3 in /usr/local/lib/python3.8/dist-packages (from ansible-core~=2.12.3->ansible[azure]) (0.5.4)
Requirement already satisfied: cryptography in /usr/lib/python3/dist-packages (from ansible-core~=2.12.3->ansible[azure]) (2.8)
Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.8/dist-packages (from jinja2->ansible-core~=2.12.3->ansible[azure]) (2.1.1)
Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in /usr/local/lib/python3.8/dist-packages (from packaging->ansible-core~=2.12.3->ansible[azure]) (3.0.7)
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
root@ansible:~#

Next install azure.azcollection module collection set from ansible-galaxy command, it is downloads files under location ~/.ansible/collections/ansible_collections/azure/azcollection/.

Microsoft azure ansible galaxy collection install.azcollection sudo pip3 install az collections requirements-azure.txt automation declarative yaml yml.png

From downloaded files use requirements-azure.txt from the above path to install Azure packages using pip3. Here azure module collection for ansible installation will be completed.

root@ansible:~# ansible-galaxy collection install azure.azcollection
Starting galaxy collection install process
Process install dependency map
Starting collection install process
Downloading https://galaxy.ansible.com/download/azure-azcollection-1.12.0.tar.gz to /root/.ansible/tmp/ansible-local-729027zchtpbc/tmpq1lrerr8/azure-azcollection-1.12.0-yhd773bh
Installing 'azure.azcollection:1.12.0' to '/root/.ansible/collections/ansible_collections/azure/azcollection'
azure.azcollection:1.12.0 was installed successfully
root@ansible:~#
root@ansible:~# sudo pip3 install -r ~/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt
/usr/lib/python3/dist-packages/secretstorage/dhcrypto.py:15: CryptographyDeprecationWarning: int_from_bytes is deprecated, use int.from_bytes instead
  from cryptography.utils import int_from_bytes
/usr/lib/python3/dist-packages/secretstorage/util.py:19: CryptographyDeprecationWarning: int_from_bytes is deprecated, use int.from_bytes instead
  from cryptography.utils import int_from_bytes
Requirement already satisfied: packaging in /usr/local/lib/python3.8/dist-packages (from -r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 1)) (21.3)
Requirement already satisfied: requests[security] in /usr/lib/python3/dist-packages (from -r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 2)) (2.22.0)
Requirement already satisfied: xmltodict in /usr/local/lib/python3.8/dist-packages (from -r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 3)) (0.12.0)
Requirement already satisfied: azure-cli-core==2.34.0 in /usr/local/lib/python3.8/dist-packages (from -r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 4)) (2.34.0)
Requirement already satisfied: azure-common==1.1.11 in /usr/local/lib/python3.8/dist-packages (from -r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 5)) (1.1.11)
Requirement already satisfied: azure-identity==1.7.0 in /usr/local/lib/python3.8/dist-packages (from -r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 6)) (1.7.0)
Requirement already satisfied: azure-mgmt-apimanagement==0.2.0 in /usr/local/lib/python3.8/dist-packages (from -r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 7)) (0.2.0)
Requirement already satisfied: azure-mgmt-authorization==0.51.1 in /usr/local/lib/python3.8/dist-packages (from -r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 8)) (0.51.1)
Requirement already satisfied: azure-mgmt-batch==5.0.1 in /usr/local/lib/python3.8/dist-packages (from -r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 9)) (5.0.1)
Requirement already satisfied: azure-mgmt-cdn==3.0.0 in /usr/local/lib/python3.8/dist-packages (from -r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 10)) (3.0.0)
Requirement already satisfied: azure-mgmt-compute==23.1.0 in /usr/local/lib/python3.8/dist-packages (from -r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 11)) (23.1.0)
Requirement already satisfied: azure-mgmt-containerinstance==1.4.0 in /usr/local/lib/python3.8/dist-packages (from -r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 12)) (1.4.0)
Requirement already satisfied: azure-mgmt-containerregistry==2.0.0 in /usr/local/lib/python3.8/dist-packages (from -r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 13)) (2.0.0)
Requirement already satisfied: azure-mgmt-containerservice==9.1.0 in /usr/local/lib/python3.8/dist-packages (from -r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 14)) (9.1.0)
Requirement already satisfied: azure-mgmt-datalake-store==0.5.0 in /usr/local/lib/python3.8/dist-packages (from -r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 15)) (0.5.0)
Requirement already satisfied: azure-mgmt-dns==2.1.0 in /usr/local/lib/python3.8/dist-packages (from -r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 16)) (2.1.0)
Requirement already satisfied: azure-mgmt-keyvault==1.1.0 in /usr/local/lib/python3.8/dist-packages (from -r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 17)) (1.1.0)
Requirement already satisfied: azure-mgmt-marketplaceordering==0.1.0 in /usr/local/lib/python3.8/dist-packages (from -r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 18)) (0.1.0)
Requirement already satisfied: azure-mgmt-monitor==3.0.0 in /usr/local/lib/python3.8/dist-packages (from -r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 19)) (3.0.0)
Requirement already satisfied: azure-mgmt-managedservices==1.0.0 in /usr/local/lib/python3.8/dist-packages (from -r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 20)) (1.0.0)
Requirement already satisfied: azure-mgmt-managementgroups==0.2.0 in /usr/local/lib/python3.8/dist-packages (from -r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 21)) (0.2.0)
Requirement already satisfied: azure-mgmt-network==19.1.0 in /usr/local/lib/python3.8/dist-packages (from -r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 22)) (19.1.0)
Requirement already satisfied: azure-mgmt-nspkg==2.0.0 in /usr/local/lib/python3.8/dist-packages (from -r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 23)) (2.0.0)
Requirement already satisfied: azure-mgmt-privatedns==0.1.0 in /usr/local/lib/python3.8/dist-packages (from -r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 24)) (0.1.0)
Requirement already satisfied: azure-mgmt-redis==5.0.0 in /usr/local/lib/python3.8/dist-packages (from -r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 25)) (5.0.0)
Requirement already satisfied: azure-mgmt-resource==10.2.0 in /usr/local/lib/python3.8/dist-packages (from -r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 26)) (10.2.0)
Requirement already satisfied: azure-mgmt-rdbms==1.9.0 in /usr/local/lib/python3.8/dist-packages (from -r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 27)) (1.9.0)
Requirement already satisfied: azure-mgmt-search==3.0.0 in /usr/local/lib/python3.8/dist-packages (from -r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 28)) (3.0.0)
Requirement already satisfied: azure-mgmt-servicebus==0.5.3 in /usr/local/lib/python3.8/dist-packages (from -r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 29)) (0.5.3)
Requirement already satisfied: azure-mgmt-sql==0.10.0 in /usr/local/lib/python3.8/dist-packages (from -r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 30)) (0.10.0)
Requirement already satisfied: azure-mgmt-storage==19.0.0 in /usr/local/lib/python3.8/dist-packages (from -r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 31)) (19.0.0)
Requirement already satisfied: azure-mgmt-trafficmanager==0.50.0 in /usr/local/lib/python3.8/dist-packages (from -r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 32)) (0.50.0)
Requirement already satisfied: azure-mgmt-web==0.41.0 in /usr/local/lib/python3.8/dist-packages (from -r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 33)) (0.41.0)
Requirement already satisfied: azure-nspkg==2.0.0 in /usr/local/lib/python3.8/dist-packages (from -r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 34)) (2.0.0)
Requirement already satisfied: azure-storage==0.35.1 in /usr/local/lib/python3.8/dist-packages (from -r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 35)) (0.35.1)
Requirement already satisfied: msrest==0.6.21 in /usr/local/lib/python3.8/dist-packages (from -r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 36)) (0.6.21)
Requirement already satisfied: msrestazure==0.6.4 in /usr/local/lib/python3.8/dist-packages (from -r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 37)) (0.6.4)
Requirement already satisfied: azure-keyvault==1.0.0a1 in /usr/local/lib/python3.8/dist-packages (from -r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 38)) (1.0.0a1)
Requirement already satisfied: azure-graphrbac==0.61.1 in /usr/local/lib/python3.8/dist-packages (from -r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 39)) (0.61.1)
Requirement already satisfied: azure-mgmt-cosmosdb==0.5.2 in /usr/local/lib/python3.8/dist-packages (from -r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 40)) (0.5.2)
Requirement already satisfied: azure-mgmt-hdinsight==0.1.0 in /usr/local/lib/python3.8/dist-packages (from -r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 41)) (0.1.0)
Requirement already satisfied: azure-mgmt-devtestlabs==3.0.0 in /usr/local/lib/python3.8/dist-packages (from -r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 42)) (3.0.0)
Requirement already satisfied: azure-mgmt-loganalytics==1.0.0 in /usr/local/lib/python3.8/dist-packages (from -r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 43)) (1.0.0)
Requirement already satisfied: azure-mgmt-automation==0.1.1 in /usr/local/lib/python3.8/dist-packages (from -r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 44)) (0.1.1)
Requirement already satisfied: azure-mgmt-iothub==0.7.0 in /usr/local/lib/python3.8/dist-packages (from -r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 45)) (0.7.0)
Requirement already satisfied: azure-mgmt-recoveryservices==0.4.0 in /usr/local/lib/python3.8/dist-packages (from -r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 46)) (0.4.0)
Requirement already satisfied: azure-mgmt-recoveryservicesbackup==0.6.0 in /usr/local/lib/python3.8/dist-packages (from -r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 47)) (0.6.0)
Requirement already satisfied: azure-mgmt-notificationhubs==2.0.0 in /usr/local/lib/python3.8/dist-packages (from -r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 48)) (2.0.0)
Requirement already satisfied: azure-mgmt-eventhub==2.0.0 in /usr/local/lib/python3.8/dist-packages (from -r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 49)) (2.0.0)
Requirement already satisfied: knack~=0.9.0 in /usr/local/lib/python3.8/dist-packages (from azure-cli-core==2.34.0->-r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 4)) (0.9.0)
Requirement already satisfied: pkginfo>=1.5.0.1 in /usr/local/lib/python3.8/dist-packages (from azure-cli-core==2.34.0->-r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 4)) (1.8.2)
Requirement already satisfied: paramiko<3.0.0,>=2.0.8 in /usr/lib/python3/dist-packages (from azure-cli-core==2.34.0->-r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 4)) (2.6.0)
Requirement already satisfied: PyJWT>=2.1.0 in /usr/local/lib/python3.8/dist-packages (from azure-cli-core==2.34.0->-r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 4)) (2.3.0)
Requirement already satisfied: msal<2.0.0,>=1.16.0 in /usr/local/lib/python3.8/dist-packages (from azure-cli-core==2.34.0->-r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 4)) (1.17.0)
Requirement already satisfied: pyopenssl>=17.1.0 in /usr/local/lib/python3.8/dist-packages (from azure-cli-core==2.34.0->-r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 4)) (22.0.0)
Requirement already satisfied: msal-extensions<0.4,>=0.3.1 in /usr/local/lib/python3.8/dist-packages (from azure-cli-core==2.34.0->-r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 4)) (0.3.1)
Requirement already satisfied: jmespath in /usr/local/lib/python3.8/dist-packages (from azure-cli-core==2.34.0->-r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 4)) (1.0.0)
Requirement already satisfied: azure-mgmt-core<2,>=1.2.0 in /usr/local/lib/python3.8/dist-packages (from azure-cli-core==2.34.0->-r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 4)) (1.3.0)
Requirement already satisfied: cryptography in /usr/local/lib/python3.8/dist-packages (from azure-cli-core==2.34.0->-r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 4)) (36.0.2)
Requirement already satisfied: argcomplete~=1.8 in /usr/local/lib/python3.8/dist-packages (from azure-cli-core==2.34.0->-r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 4)) (1.12.3)
Requirement already satisfied: humanfriendly~=10.0 in /usr/local/lib/python3.8/dist-packages (from azure-cli-core==2.34.0->-r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 4)) (10.0)
Requirement already satisfied: psutil~=5.9 in /usr/local/lib/python3.8/dist-packages (from azure-cli-core==2.34.0->-r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 4)) (5.9.0)
Requirement already satisfied: azure-cli-telemetry==1.0.6.* in /usr/local/lib/python3.8/dist-packages (from azure-cli-core==2.34.0->-r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 4)) (1.0.6)
Requirement already satisfied: six>=1.12.0 in /usr/lib/python3/dist-packages (from azure-identity==1.7.0->-r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 6)) (1.14.0)
Requirement already satisfied: azure-core<2.0.0,>=1.11.0 in /usr/local/lib/python3.8/dist-packages (from azure-identity==1.7.0->-r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 6)) (1.23.0)
Requirement already satisfied: azure-mgmt-datalake-nspkg>=2.0.0 in /usr/local/lib/python3.8/dist-packages (from azure-mgmt-datalake-store==0.5.0->-r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 15)) (2.0.0)
Requirement already satisfied: python-dateutil in /usr/lib/python3/dist-packages (from azure-storage==0.35.1->-r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 35)) (2.7.3)
Requirement already satisfied: requests-oauthlib>=0.5.0 in /usr/local/lib/python3.8/dist-packages (from msrest==0.6.21->-r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 36)) (1.3.1)
Requirement already satisfied: isodate>=0.6.0 in /usr/local/lib/python3.8/dist-packages (from msrest==0.6.21->-r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 36)) (0.6.1)
Requirement already satisfied: certifi>=2017.4.17 in /usr/lib/python3/dist-packages (from msrest==0.6.21->-r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 36)) (2019.11.28)
Requirement already satisfied: adal<2.0.0,>=0.6.0 in /usr/local/lib/python3.8/dist-packages (from msrestazure==0.6.4->-r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 37)) (1.2.7)
Requirement already satisfied: applicationinsights<0.12,>=0.11.1 in /usr/local/lib/python3.8/dist-packages (from azure-cli-telemetry==1.0.6.*->azure-cli-core==2.34.0->-r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 4)) (0.11.10)
Requirement already satisfied: portalocker~=1.2 in /usr/local/lib/python3.8/dist-packages (from azure-cli-telemetry==1.0.6.*->azure-cli-core==2.34.0->-r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 4)) (1.7.1)
Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in /usr/local/lib/python3.8/dist-packages (from packaging->-r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 1)) (3.0.7)
Requirement already satisfied: idna>=2.0.0 in /usr/lib/python3/dist-packages (from requests[security]->-r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 2)) (2.8)
Requirement already satisfied: typing-extensions>=4.0.1 in /usr/local/lib/python3.8/dist-packages (from azure-core<2.0.0,>=1.11.0->azure-identity==1.7.0->-r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 6)) (4.1.1)
Requirement already satisfied: cffi>=1.12 in /usr/local/lib/python3.8/dist-packages (from cryptography->azure-cli-core==2.34.0->-r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 4)) (1.15.0)
Requirement already satisfied: pyyaml in /usr/lib/python3/dist-packages (from knack~=0.9.0->azure-cli-core==2.34.0->-r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 4)) (5.3.1)
Requirement already satisfied: tabulate in /usr/local/lib/python3.8/dist-packages (from knack~=0.9.0->azure-cli-core==2.34.0->-r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 4)) (0.8.9)
Requirement already satisfied: pygments in /usr/local/lib/python3.8/dist-packages (from knack~=0.9.0->azure-cli-core==2.34.0->-r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 4)) (2.11.2)
Requirement already satisfied: oauthlib>=3.0.0 in /usr/lib/python3/dist-packages (from requests-oauthlib>=0.5.0->msrest==0.6.21->-r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 36)) (3.1.0)
Requirement already satisfied: PySocks!=1.5.7,>=1.5.6 in /usr/local/lib/python3.8/dist-packages (from requests[security]->-r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 2)) (1.7.1)
Requirement already satisfied: pycparser in /usr/local/lib/python3.8/dist-packages (from cffi>=1.12->cryptography->azure-cli-core==2.34.0->-r /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt (line 4)) (2.21)
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
root@ansible:~#

If curl package is not installed on the system, install it with command apt-get or yum repository.

Microsoft Azure sudo apt-get install curl package dependency curl ansible installation azure collection az login az cli powershell.png

root@ansible:~# sudo apt-get install curl
Reading package lists... Done
Building dependency tree
Reading state information... Done
curl is already the newest version (7.68.0-1ubuntu2.7).
0 upgraded, 0 newly installed, 0 to remove and 5 not upgraded.
root@ansible:~#

Before using azure ansible collection I need to authenticate to Microsoft Azure using ansible module. For this I am installing and using Az CLI application using below command.

Microsoft Azure curl aka.ms installazureCLIdeb bash apt-get packages azure-cli ansible authentication login azure az collection.png

root@ansible:~# curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
Hit:1 http://us.archive.ubuntu.com/ubuntu focal InRelease
Get:2 http://us.archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Get:3 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
Get:4 http://us.archive.ubuntu.com/ubuntu focal-backports InRelease [108 kB]
Hit:5 https://packages.microsoft.com/repos/azure-cli focal InRelease
Get:6 http://us.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [1,674 kB]
Get:7 http://us.archive.ubuntu.com/ubuntu focal-updates/main i386 Packages [621 kB]
Get:8 http://us.archive.ubuntu.com/ubuntu focal-updates/main amd64 DEP-11 Metadata [278 kB]
Get:9 http://us.archive.ubuntu.com/ubuntu focal-updates/universe amd64 DEP-11 Metadata [391 kB]
Get:10 http://us.archive.ubuntu.com/ubuntu focal-updates/multiverse amd64 DEP-11 Metadata [944 B]
Get:11 http://us.archive.ubuntu.com/ubuntu focal-backports/main amd64 DEP-11 Metadata [8,012 B]
Get:12 http://us.archive.ubuntu.com/ubuntu focal-backports/universe amd64 DEP-11 Metadata [30.8 kB]
Get:13 http://security.ubuntu.com/ubuntu focal-security/main amd64 DEP-11 Metadata [40.6 kB]
Get:14 http://security.ubuntu.com/ubuntu focal-security/universe amd64 DEP-11 Metadata [66.3 kB]
Get:15 http://security.ubuntu.com/ubuntu focal-security/multiverse amd64 DEP-11 Metadata [2,464 B]
Fetched 3,449 kB in 2s (1,827 kB/s)
Reading package lists... Done
Reading package lists... Done
Building dependency tree
Reading state information... Done
lsb-release is already the newest version (11.1.0ubuntu2).
curl is already the newest version (7.68.0-1ubuntu2.7).
gnupg is already the newest version (2.2.19-3ubuntu2.1).
apt-transport-https is already the newest version (2.0.6).
0 upgraded, 0 newly installed, 0 to remove and 5 not upgraded.
Hit:1 http://us.archive.ubuntu.com/ubuntu focal InRelease
Hit:2 http://us.archive.ubuntu.com/ubuntu focal-updates InRelease
Hit:3 https://packages.microsoft.com/repos/azure-cli focal InRelease
Hit:4 http://us.archive.ubuntu.com/ubuntu focal-backports InRelease
Hit:5 http://security.ubuntu.com/ubuntu focal-security InRelease
Reading package lists... Done
Reading package lists... Done
Building dependency tree
Reading state information... Done
azure-cli is already the newest version (2.34.1-1~focal).
0 upgraded, 0 newly installed, 0 to remove and 5 not upgraded.
root@ansible:~#

Once Az CLI installation completed, use az login command to login to Azure cloud, it will provide a link https//microsoft.com/devicelogin and enter the given code to authenticate in the browser. If you have multiple Azure subscription use az account set command to set default subscription.

MIcrosoft azure az login ansible localhost -m azure.azcollection.azure_rm_resourcegroup -a argument subscription tags azure cloud ansible devicelogin enter code localhost.png

Finally to test Ansible Azure I am using ad-hoc ansible command with module azure.azcollection.azure_rm_resourcegroup with arguments name and location to create Resource Group and the result is successful.

root@ansible:~# az login
To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code Exxxxxxxx to authenticate.
The following tenants require Multi-Factor Authentication (MFA). Use 'az login --tenant TENANT_ID' to explicitly login to a tenant.
a59fb284-02ec-4a72-a79a-4a6b6105ab9d 'vcloud-lab.com'
[
  {
    "cloudName": "AzureCloud",
    "homeTenantId": "3b80xxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "id": "9e22xxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "isDefault": true,
    "managedByTenants": [],
    "name": "Sponsership-by-Microsoft",
    "state": "Enabled",
    "tenantId": "3b80xxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "user": {
      "name": "janvi@xxxxxxxx.com",
      "type": "user"
    }
  }
]
root@ansible:~# 
root@ansible:~# az account list
root@ansible:~# az account set --subscription="Sponsership-by-Microsoft"
root@ansible:~# az account show
root@ansible:~# 
root@ansible:~# ansible localhost -m azure.azcollection.azure_rm_resourcegroup -a "name=testrg location=westus"
[WARNING]: No inventory was parsed, only implicit localhost is available
localhost | CHANGED => {
    "changed": true,
    "contains_resources": false,
    "state": {
        "id": "/subscriptions/9e22xxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/testrg",
        "location": "westus",
        "name": "testrg",
        "provisioning_state": "Succeeded",
        "tags": null
    }
}
root@ansible:~#

This is another ad-hoc command to configure ansible / azure, check the module difference.

root@ansible:~# ansible localhost -m azure_rm_resourcegroup -a "name=testrg location=westus state=absent"
[WARNING]: No inventory was parsed, only implicit localhost is available
localhost | CHANGED => {
    "changed": true,
    "contains_resources": false,
    "state": {
        "id": "/subscriptions/9e22fba3-00a9-447c-b954-a26fec38e029/resourceGroups/testrg",
        "location": "westus",
        "name": "testrg",
        "provisioning_state": "Succeeded",
        "status": "Deleted",
        "tags": null
    }
}
root@ansible:~#

Useful Articles
Ansible selectattr The error was TemplateRuntimeError no test named 'equalto'
ansible create an array with set_fact
Ansible get information from esxi advanced settings nested dictionary with unique keynames
Install Ansible AWX Tower on Ubuntu Linux
Ansible AWX installation error Cannot have both the docker-py and docker python modules
Ansible AWX installation error docker-compose run --rm --service-ports task awx-manage migrate --no-input
docker: Got permission denied while trying to connect to the Docker daemon socket
Ansible AWX Tower create Manual SCM (Source Control Credential Type) project
Reset Ansible AWX Tower admin password
Install Ansible AWX on Microsoft Windows OS
Step by Step Install Ansible on Ubuntu OS
Install Ansible AWX Tower on Ubuntu Linux OS
Ansible AWX Tower Github inventory integration | Github inventory source

Go Back

Comment

Blog Search

Page Views

8146654

Follow me on Blogarama