# How to create multiple virtual machines in azure using ansible

**URL:** <https://forum.ansible.com/t/how-to-create-multiple-virtual-machines-in-azure-using-ansible/19647>\
**Category:** Ansible Project\
**Tags:** azure, windows\
**Created:** [October 29, 2015, 5:34am UTC](https://forum.ansible.com/t/how-to-create-multiple-virtual-machines-in-azure-using-ansible/19647 "2015-10-29T05:34:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![naveen.kumare36](https://avatars.discourse-cdn.com/v4/letter/n/6f9a4e/32.png) [@naveen.kumare36](https://forum.ansible.com/u/naveen.kumare36)\
**Post date:** [October 29, 2015, 5:34am UTC](https://forum.ansible.com/t/how-to-create-multiple-virtual-machines-in-azure-using-ansible/19647/1 "2015-10-29T05:34:14Z")

</div>

I tried with the following playbook and its not working. Not sure what I am missing here.

```auto
  hosts: localhost
  connection: local
  gather_facts: no
  vars_files:
    - vars/azure.yml
  tasks:
    - name: create VM
      azure:
        name: '{{ vm_name }}'
        role_size: '{{ role_size }}'
        image: '{{ image_name }}'
        location: '{{ location }}'
        user: '{{ username }}'
        password: '{{ password }}'
        subscription_id: '{{ subscription_id }}'
        management_cert_path: '{{ certificate_path }}'
        storage_account: '{{ storage_account_name }}'
        virtual_network_name: '{{ virtual_network_name }}'
        wait: yes
      with_items: 
        - { name: "{{ vm_names_list }}" } 
      register : azure

    - name : Debug Azure output
      debug :
        var : azure

```

I have mentioned my `vm_names_list` like this :

```auto
vm_names_list:
    - "loferVM123"
    - "loferVM234"

```

It does not do what I expect. I expected it to create three VMs. But it creates only one VM. In the debug output it gives me the items in the list but only creates one VM.

This is the debug output:

```auto
"virtual_network_name": "myVirtualNetwork"
                },
                "invocation": {
                    "module_args": "",
                    "module_name": "azure"
                },
                "item": {
                    "vm_name": [
                        "loferVM123",
                        "loferVM234"
                    ]
                },
                "public_dns_name": "lofervm175.cloudapp.net"

```

My variable file:

```auto
subscription_id: "ID"
certificate_path: "/path/to/certs/mycert.pem"
image_name: "5112500ae3b842c8b9c604889f8753c3__OpenLogic-CentOS-67-20150815"
storage_account_name: "mystorageacc"
virtual_network_name: "myVirtualNetwork"
username: "user"
password: "password"
vm_name: "Testvm"
vm_names_list:
    - "loferVM123"
    - "loferVM234"
role_size: "Small"
location: "Central US"
data_disk_size: "100"
commitlog_disk_size: "10"

```

This is the output from azure-cli vm show

```auto
data: DNSName "lofervm234.cloudapp.net"
data: Location "Central US"
data: VMName "loferVM234"
data: IPAddress "10.0.2.6"
data: InstanceStatus "ReadyRole"
data: InstanceSize "Small"
data: Image "5112500ae3b842c8b9c604889f8753c3__OpenLogic-CentOS-67-20150815"
data: OSDisk hostCaching "ReadWrite"
data: OSDisk name "loferVM234-loferVM234-0-201510262116050841"
data: OSDisk mediaLink "http://portalvhdskswbj32fl5cx8.blob.core.windows.net/vhds/loferVM234-loferVM234-2015-10-26.vhd"
data: OSDisk sourceImageName "5112500ae3b842c8b9c604889f8753c3__OpenLogic-CentOS-67-20150815"
data: OSDisk operatingSystem "Linux"
data: OSDisk iOType "Standard"
data: DataDisks 0 hostCaching "None"
data: DataDisks 0 label "loferVM234-loferVM234-loferVM234-0"
data: DataDisks 0 name "loferVM234-loferVM234-0-201510262116380749"
data: DataDisks 0 logicalDiskSizeInGB 100
data: DataDisks 0 mediaLink "https://portalvhdskswbj32fl5cx8.blob.core.windows.net/vhds/loferVM234-b73613825dfb0bcb.vhd"
data: DataDisks 0 iOType "Standard"
data: DataDisks 1 hostCaching "None"
data: DataDisks 1 label "loferVM234-loferVM234-loferVM234-1"
data: DataDisks 1 name "loferVM234-loferVM234-1-201510262117180308"
data: DataDisks 1 logicalUnitNumber 1
data: DataDisks 1 logicalDiskSizeInGB 100
data: DataDisks 1 mediaLink "https://portalvhdskswbj32fl5cx8.blob.core.windows.net/vhds/loferVM234-cf18946abcbfe4c8.vhd"
data: DataDisks 1 iOType "Standard"
data: ReservedIPName ""
data: VirtualIPAddresses 0 address "104.43.202.234"
data: VirtualIPAddresses 0 name "loferVM234ContractContract"
data: VirtualIPAddresses 0 isDnsProgrammed true
data: Network Endpoints 0 localPort 22
data: Network Endpoints 0 name "TCP-22"
data: Network Endpoints 0 port 22
data: Network Endpoints 0 protocol "tcp"
data: Network Endpoints 0 virtualIPAddress "104.43.202.234"
data: Network Endpoints 0 enableDirectServerReturn false
data: Network Endpoints 0 idleTimeoutInMinutes 4

```

---

<div class="post-metadata">

**Author:** ![yaniv\_refael](https://avatars.discourse-cdn.com/v4/letter/y/f07891/32.png) [@yaniv\_refael](https://forum.ansible.com/u/yaniv_refael)\
**Post date:** [April 10, 2016, 10:34am UTC](https://forum.ansible.com/t/how-to-create-multiple-virtual-machines-in-azure-using-ansible/19647/2 "2016-04-10T10:34:30Z")

</div>

Can you share the ansible-palybook command?
