Virtual Geek

Tales from real IT system administrators world and non-production environment

Create multiple Azure vnet (Virtual Network) using ansible

This is a second part of Deploy create Virtual Network vNET in Azure cloud using Ansible, in this part I am creating multiple vNets with single Ansible script. All the info and details related to new vNet added in separate vnet variable yml file in json format as shown below.

Azure Virtual network json ansible yaml mutliple vnets creation resources arm templates resource group address prefixes cidr location vnet name.jpg

Next in below ansible yaml script, I am using foreach loop on the provided json information and create mutliple Virtual Network on the Microsoft Azure. You can use ansible-playbook command to deploy this yaml playbook.

Azure.azcollection vnet variables azure virtual network ansible redhat azure_rm_virtualnetwork subnet address prefixes cidr loop configuration.jpg

Download this here or it is also available on

# multi-azvnets.yaml - Ansible yaml code to create multiple AZ vnets
- name: Create Azure vNets (Virtual Networks)
  hosts: localhost
  connection: local
  gather_facts: false

    - azure.azcollection

    - name: Include variable file
        file: vnet_var.yml
        name: vnet_var

    - name: Create a vNets (Virtual Networks)
        resource_group: "{{ item.resource_group }}"
        name: "{{ }}"
        location: "{{ item.location }}"
        address_prefixes_cidr: "{{ item.address_prefixes_cidr }}"
          # - ""
          # - ""
      loop: "{{ vnet_var.vnet_resources }}"

# vnet_var.yaml - json variables info of AZ vNet resource
# resource_group:
# vnet_name: global_vnet_eastus
# location: eastus
# vnet_address_prefixes_cidr:
# subnet01_name: prod01-10.10.1.x
# subnet01_address_prefix:

  - {
      resource_group: rg-globalnetwork-prod,
      name: prod-vnet-wus3-01,
      vnet_address_prefixes_cidr: [""],
      location: West US3
  - {
      resource_group: "rg-globalnetwork-prod",
      name: "prod-vnet-weu-01",
      vnet_address_prefixes_cidr: [""],
      location: "West Europe"

Useful Articles
How to install and configure Ansible on Ubuntu
Get Started: Configure Ansible for Azure Cloud Infrastructure
Install the Microsoft Azure CLI on Ubuntu Linux

Redhat ansible logo azure vmware vsphere awx tower controller yml yaml configuration automation.pngDeploy create Virtual Network vNET in Azure cloud using Ansible
Quickstart How to authenticate Ansible with Microsoft Azure
Ansible authenticate to Microsoft Azure using credential profiles Part 1
Ansible authenticate to Microsoft Azure using credential profiles Part 2
Ansible authenticate to Microsoft Azure using credential inside yaml file

Go Back


Blog Search

Page Views


Follow me on Blogarama