AnsibleUpdated July 3, 2026
Azure Ansible Local CLI Setup
ansibleazurelocal-setupclipyenvpythonazure-cliazure-collectiondevelopment-environment
Azure Ansible Local CLI Setup Guide
This guide helps you set up a robust, secure, and maintainable local Ansible environment for Azure development, using your own credentials via az login.
Prerequisites
- Python 3.11+ (recommended: manage via pyenv)
- Ansible (v2.18+ recommended)
- Azure CLI
- Azure Ansible Collection (
azure.azcollection)
1. Install pyenv and Python
1.1 Mac (Homebrew)
brew update
brew install pyenv
pyenv install 3.11.9
pyenv virtualenv 3.11.9 ansible-azure-311
pyenv activate ansible-azure-311
1.2 Linux/WSL
curl https://pyenv.run | bash
# Follow pyenv's setup instructions for your shell
pyenv install 3.11.9
pyenv virtualenv 3.11.9 ansible-azure-311
pyenv activate ansible-azure-311
2. Upgrade pip and Install Ansible
python -m pip install --upgrade pip
pip install "ansible>=2.18.0"
3. Install Azure Ansible Collection
ansible-galaxy collection install azure.azcollection
4. Install Python Dependencies for Azure Collection
pip install -r ~/.ansible/collections/ansible_collections/azure/azcollection/requirements.txt
5. Install Azure CLI
5.1 Mac
brew install azure-cli
5.2 Linux/WSL
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
6. Authenticate to Azure
az login
-
Complete the browser-based login with your developer credentials.
-
Ensure you have access to the correct subscription:
az account show
7. Configure Your Inventory File (azure_rm.yaml)
Example:
plugin: azure.azcollection.azure_rm
auth_source: cli
plain_host_names: true
keyed_groups:
- key: tags
prefix: tag
- key: location
prefix: azure
Save to e.g. inventories/azure/azure_rm.yaml.
8. Test the Inventory
ansible-inventory -i inventories/azure/azure_rm.yaml --list
9. Optional: Project .ansible.cfg
[defaults]
ansible_python_interpreter = ~/.pyenv/versions/ansible-azure-311/bin/python3
inventory = inventories/azure/azure_rm.yaml
[inventory]
enable_plugins = azure.azcollection.azure_rm,host_list,script,auto,yaml,ini,toml
Troubleshooting
- Missing dependencies:
Ensure all requirements in the Azure collection’s
requirements.txtare installed. - No inventory found:
Double check
az loginand your subscription. - Auth errors:
Confirm
auth_source: cliand no conflicting environment variables.