Ansible 2.6 was released with more capabilities to provision and manage Azure resources. It includes four new modules for Azure Kubernetes Service and Azure Resource, and many enhancements to existing Ansible modules for Azure (e.g., Virtual Machine, Networking interface).

Here I’ll introduce two new modules azure_rm_resource and azure_rm_resource_facts which allow you to directly call the Azure REST API. If you want to create or manage some Azure resource, but do not find an Ansible module for it, you could use azure_rm_resouce to call the Azure REST API to create that Azure resource and use azure_rm_resource_facts to obtain the facts of that Azure resource.

To get these new Ansible modules for Azure, you need to install:


  • Azure Preview Module role by running below command line if you are still using Ansible 2.5. This playbook role integrates new modules and fixes available in the latest Ansible devel branch. If you want to know more about Ansible Galaxy and Azure Preview Module role, read my last blog.

Below is an example to use azure_rm_resource and azure_rm_resource_facts to create Event Hubs on Azure. It defines variables, such as resource group name, and then executes below four tasks:

  1. Create a resource group;
  2. Create an Event Hubs namespace;
  3. Wait for the namespace to become active asynchronously using facts module;
  4. Create an Event Hub.

Save the preceding playbook as eventhubs-create.yml, or download the sample Ansible playbook here. To run the Ansible playbook, use the ansible-playbook command as follows:

Congratulations! You’ve successfully created your event hubs by calling Azure REST API with Ansible. If you go to the portal, you will see the your event hubs there.

Now you could try to create your own Ansible playbook to provision a new Azure resource or manage existing Azure resource by calling Azure REST API. You could learn more from the documentation for azure_rm_resource / azure_rm_resource_facts and search Azure REST API  regarding details related to specific resource.

If you want to learn more about Ansible on Azure, check out the latest Azure Friday.

Questions? Let us know in the comments.