Create a Microsoft Azure Resource Group With Ansible

Following our past blog posts about Microsoft Azure and Ansible today we will learn how to create an Azure Resource Group with Ansible.

Before you start, it is recommended you create a credentials file for Microsoft Azure if you are using a Linux or macOS machine. If you prefer not to create a creds file, you can use the az login command to log in to Azure and auth before running the playbook.

Playbook

If you have Ansible installed and configured, you can use the following playbook to create an empty resource group on Microsoft Azure. In my case, I have named the resource group WSL, and I am creating it in the West US region.

---
- name: Create a resource group
  hosts: localhost
  connection: local
  gather_facts: no
  tasks:
    - name: Create a resource group
      azure_rm_resourcegroup:
        name: WSL
        location: westus
        tags:
          Environment: PROD

To run the playbook, use the follwoing command.

ansible-playbook resource-group.yml -vvv

If you like this post, make sure you visit our ansible category page.

Processing…
Success! You're on the list.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.