Installing Azure CLI and Ansible on Ubuntu

by Carlos Mendible on 10 Aug 2018 » Azure, DevOps

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:

AZ_REPO=$(lsb_release -cs)
echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $AZ_REPO main" | \ sudo tee /etc/apt/sources.list.d/azure-cli.list

curl -L https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -

sudo apt-get install apt-transport-https
sudo apt-get update && sudo apt-get install azure-cli

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

2. Ansible


To intall Ansible run the following commands:

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

Please find the official Microsoft documentation here

3. Verify the installation

To confirm that both tools are installed just run:

az --version
ansible --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:

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

Hope it helps!!!