...

/

Azure - Create a Dynamic Inventory

Azure - Create a Dynamic Inventory

Create a dynamic inventory of the deployed Linux and Windows hosts on Azure.

We'll cover the following...

Ansible has a built-in inventory plugin for Azure called azure_rm. This plugin queries Azure Resource Manager for the VM details and constructs an Ansible inventory from that information.

Virtual machines in Azure populate host entries, and groups and group memberships are determined by host variables assigned to each host.

We have created a file named hosts_azure_rm.yml.

Press + to interact
plugin: azure_rm
include_vm_resource_groups:
- ansible
auth_source: auto

Let’s break down the file.

  • plugin: Define the inventory plugin, azure_rm.

  • include_vm_resource_groups: Control the scope of the inventory. Set to ansible.

  • auth_source: Set to auto. The auto will follow the default precedence of the module parameters → environment variables → default profile in the credential file.

Because we are leveraging the environment variables to ...