# How to deploy multiple image using Ansible on VMwar

**URL:** <https://forum.ansible.com/t/how-to-deploy-multiple-image-using-ansible-on-vmwar/35718>\
**Category:** Ansible Project\
**Created:** [September 9, 2021, 11:41am UTC](https://forum.ansible.com/t/how-to-deploy-multiple-image-using-ansible-on-vmwar/35718 "2021-09-09T11:41:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ibrahim\_Salah](https://avatars.discourse-cdn.com/v4/letter/i/a587f6/32.png) [@Ibrahim\_Salah](https://forum.ansible.com/u/Ibrahim_Salah)\
**Post date:** [September 9, 2021, 11:41am UTC](https://forum.ansible.com/t/how-to-deploy-multiple-image-using-ansible-on-vmwar/35718/1 "2021-09-09T11:41:20Z")

</div>

Hello,

I was using Ansible to deploy an image using the following code :

`—

- name: Create a VM from a template  
hosts: ‘192.168.0.110’  
connection: local  
gather\_facts: no  
tasks:
  - name: Clone the template  
vmware\_guest:  
hostname: ‘192.168.0.111’  
username: [administrator@vsphere.local](mailto:administrator@vsphere.local)  
password: Test123\*\_  
validate\_certs: False  
name: testvm\_2  
template: Mikrotik  
datacenter: Test  
folder: /Test/vm  
state: poweredon  
wait\_for\_ip\_address: yes`

The question can I deploy multiple images in the same code ?

IS there any code that I can use to deploy multiple images ? I used this code and it works without any issues

I mean what if I want to deploy 20 VMS in the same time ?

Best Regards

---

<div class="post-metadata">

**Author:** ![Roberto\_J\_R\_Paz](https://avatars.discourse-cdn.com/v4/letter/r/d2c977/32.png) [@Roberto\_J\_R\_Paz](https://forum.ansible.com/u/Roberto_J_R_Paz)\
**Post date:** [September 17, 2021, 6:43pm UTC](https://forum.ansible.com/t/how-to-deploy-multiple-image-using-ansible-on-vmwar/35718/2 "2021-09-17T18:43:23Z")

</div>

You can deploy multiples VMs with the same playbook, as long as you change “name:”. You can provide the name as an “extra var” at runtime.

You can’t create 20 VMs from the same command, because VMWare API don’t support cloning for multiple VMs at once.

However, you can run the playbook 20 times with different extra vars. As long as the vCenter has enough resources to attend to the paralells requirements, this is possible.

---

<div class="post-metadata">

**Author:** ![Pushparaj\_Gothandam](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/pushparaj_gothandam/32/5538_2.png) [@Pushparaj\_Gothandam](https://forum.ansible.com/u/Pushparaj_Gothandam)\
**Post date:** [September 18, 2021, 2:36am UTC](https://forum.ansible.com/t/how-to-deploy-multiple-image-using-ansible-on-vmwar/35718/3 "2021-09-18T02:36:34Z")

</div>

with\_items – This is a loop in Ansible that allows us to run this playbook for the multiple items/servers we are specifying in the “servers” variable

Fo eg:

```auto
 name: Clone multiple VMs
  hosts: localhost 
  gather_facts: false
  vars_files: 
    multiple_vms.yml
  tasks: 
  - name: Clone multiple VMs from template
    vmware_guest:
      hostname: "{{ vcenter_hostname }}"
      username: "{{ username }}"
      password: "{{ password }}"
      validate_certs: no      
      folder: "{{ folder }}"
      template: "{{ vmtemplate }}"
      name: "{{ item }}"
      cluster: "{{ vmcluster }}"
      datacenter: CloudLocal
      state: poweredon
      customization_spec: "{{ customization_spec }}"
    with_items: "{{ servers }}"

```
