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:
Create a resource group;
Create an Event Hubs namespace;
Wait for the namespace to become active asynchronously using facts module;
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:
$ ansible-playbook eventhubs-create.yml
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.
Kylie Liang
Sr. Program Manager within Microsoft's Cloud + Enterprise Group
She focuses on DevOps and open source, including Ansible and Kubernetes, and Java tooling on Microsoft Azure. She has been working with open source communities for several years and is a board director of the FreeBSD Foundation.
Open source is the foundation for AI and, as AI workloads scale, developers need that foundation to be more secure, more predictable, and easier to build apps and agents.
The Cloud Native Computing Foundation’s (CNCF) Hyperlight project delivers faster, more secure, and smaller workload execution to the cloud-native ecosystem.