I’ve been using Ansible and the Azure CLI every single day for the last 3 months. Non stop work editing playbooks and scripts with Visual Studio Code and running them on Ubuntu (WSL) on my Windows 10 machine.

Turns out that because Ansible uses python version 2.7.12 and the Azure CLI uses python 3.6.5 you can make a mess if you get “creative” trying to install the tools instead of using the recommended commands:

1. Azure CLI#


To install the Azure CLI just run the following commands:

1AZ_REPO=$(lsb_release -cs)
2echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $AZ_REPO main" | sudo tee /etc/apt/sources.list.d/azure-cli.list
3
4curl -L https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
5
6sudo apt-get install -y apt-transport-https
7sudo apt-get update && sudo apt-get install -y azure-cli

If you want to read the official Microsoft documentation please find it here

2. Ansible#


To install Ansible run the following commands:

1sudo apt-get update && sudo apt-get install -y libssl-dev libffi-dev python-dev python-pip
2sudo pip install ansible[azure]

Please find the official Microsoft documentation here

3. Verify the installation#

To confirm that both tools are installed just run:

1az --version
2ansible --verison

Take a minute and check the python versions and you’ll see the difference!

4. Install using a gist#


I’ve published a gist so you can install both Ansible and Azure CLI in one run:

1sudo curl -s https://gist.githubusercontent.com/cmendible/696bc74bfd123924bd255834aeedb340/raw/a3fd95f7cf6556292a04ee289ae05769f83caa40/azure_cli_ansible_install.sh | bash

Hope it helps!!!