
I was looking at the best way to create an inventory from a virtual machine scale set and found this gem. The Azure dynamic-inventory plugin is the easiest way to get VMs, scale set and resources from resource groups and do stuff with ansible.
Requirements
- Azure CLI
- Ansible installed
- pip install azure or
pip install -r requirements-azure.txt
https://github.com/ansible-collections/azure
Assuming you have the requirements it is very easy to get info and an inventory file from Azure.
Step 1: Install the plugin
ansible-galaxy collection install azure.azcollection
https://galaxy.ansible.com/azure/azcollection
Step 2: Login to the azure cli
az login
Step 3: Create a dynamic inventory file
The filename has to end in azure_rm.yaml, my file name is azdoscaleset_azure_rm.yaml

Step 4: Test your query

Step 5: Test Deployment with Ansible Ping

You can create different ones based on tags or conditionally for more info see: https://docs.microsoft.com/en-us/azure/developer/ansible/dynamic-inventory-configure?tabs=azure-cli