Running Ansible Azure playbook in Azure Cloud Shell

by Carlos Mendible on 05 May 2018 » Azure, DevOps

NOTE: The issue described in this post was fixed!!! (ansible 2.5.2 and Azure CLI 2.0.34)

Last week I tried to run this simple Ansible playbook in Azure Cloud Shell:

# resource_group.yml
# Create test resource group in west europe
- name: Create a Resource Group
  hosts: localhost
  connection: local
  gather_facts: no
  tasks:
    - name: Create Resource Group
      azure_rm_resourcegroup:
        location: westeurope
        name: test
        state: present

The first attempt to run the playbook with:

ansible-playbook resource_group.yml -vvv

failed with the following message: No module named ‘packaging’

So I ran:

pip install --user packaging

But this time when I tried to run the playbook I got a message telling me to upgrade the Azure module for Ansible. Again the first attempt didn’t go well so I forced the upgrade:

pip install ansible[azure] --upgrade --force --user

Problem solved!!! Runing the following command did create the resource group:

ansible-playbook resource_group.yml -vvv

Hope it helps!