Implementing your own Ansible Azure Collection


In a recent azure ansible article I wrote (, I came across a challenge, whereby listing resources in a resource group wasn’t real-time.

In that article I improvised by waiting and checking every minute until the resources eventually appeared. BUT that loop and sleep took ~20 minutes.

It turns out, the “/resources API is served from a regional cache from Azure Resource Manager, which is eventual consistent, and not real time”

This means, in order to get a real time view of the resources in our resource group, we need to hit the regional azure management endpoint i.e. https://<region>

In this article, I want to show a simple way I’ve got around this by creating our own custom module.

Updating the Azure Ansible Collection

I’m going to do this through Azure Cloudshell, so at the time of writing, Ansible on Cloudshell is using Python 2.7, so first let’s install ansible for python 3

Clone down the latest Azure Ansible Collection

Install all the azure ansible collection dependencies

I’m going to create a new module, by coping

Now we’ll make a few changes, highlighted in bold

See the full code for this module here:

Right we’re good to install/upgrade this Azure Ansible Collection.

Now let’s give it a run. Create a simple Playbook called ans.yaml

Now run the playbook


I hope you found this article useful and it gives you some ideas on creating your own azure ansible collection. Obviously you don’t want to have to reinstall the azure ansible module each time, so preferably you will create your own collection (extend that you can install independently.

Cloud Platform Architect. Opinions and articles on medium are my own.