# How to create Multiple Guest Vms Snapshot

**URL:** <https://forum.ansible.com/t/how-to-create-multiple-guest-vms-snapshot/32734>\
**Category:** Ansible Project\
**Tags:** vmware\
**Created:** [April 20, 2020, 11:34am UTC](https://forum.ansible.com/t/how-to-create-multiple-guest-vms-snapshot/32734 "2020-04-20T11:34:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arvind\_Kumar](https://avatars.discourse-cdn.com/v4/letter/a/e495f1/32.png) [@Arvind\_Kumar](https://forum.ansible.com/u/Arvind_Kumar)\
**Post date:** [April 20, 2020, 11:34am UTC](https://forum.ansible.com/t/how-to-create-multiple-guest-vms-snapshot/32734/1 "2020-04-20T11:34:22Z")

</div>

HI, I have Created a playbook to take a snapshot before patching of servers but this playbook has only one Guest\_vm define so it working perfectly for me.

**- name: Vmware guest snapshot create**  
**hosts: test-hypervisor**  
**tasks:**

**- name: Create a snapshot**  
**vmware\_guest\_snapshot:**  
**hostname: test-hypervisior**  
**username: root**  
**password: asdfghj123\***  
**datacenter: test-hypervisior**  
**folder: " /folder1/localhost.example.com/vm"**  
**name: RJRedhat01**  
**state: present**  
**validate\_certs: False**  
**snapshot\_name: snap55**  
**description: Test snapshot**  
**delegate\_to: localhost**  
**register: snapshot\_info**  
**- name: show the status**  
**debug:**  
**var: snapshot\_info.snapshot\_results**

#### Above Playbook is working fine for me’, But I have dozens of server and I want to create the snapshot of all nodes, I am using **with\_item** for looping all nodes but it is not working for me.

My Playbook for Multi vm\_guest snapshot creation

**- name: Vmware guest snapshot create**  
**hosts: test-hypervisior**  
**tasks:**

**- name: Create a snapshot**  
**vmware\_guest\_snapshot:**  
**hostname: test-hypervisior**  
**username: root**  
**password: asdfghj123\***  
**datacenter: test-hypervisior**  
**folder: " /folder1/localhost.example.com/vm"**  
**name: “{{ item}}”**  
**with\_items:**  
**- RJCentos1**  
**- RJRedhat01**  
**- MAXFAX01**  
**state: present**  
**validate\_certs: False**  
**snapshot\_name: snap\_\_with\_multi\_vms**  
**description: snap1\_descriptioninnn**  
**delegate\_to: localhost**  
**register: snapshot\_info**  
**- name: show the status**  
**debug:**  
**var: snapshot\_info.snapshot\_results**

@@@@@@@@@@@@@@@@@@@@@@@@@@@@

ansible-playbook vm-snap-c2.yaml -u root -k  
SSH password:

PLAY [Vmware guest snapshot create] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK [Gathering Facts] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
Monday 20 April 2020 07:28:44 -0400 (0:00:00.056) 0:00:00.056 \*\*\*\*\*\*\*\*\*\*  
ok: [test-hypervisior]

TASK [Create a snapshot] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
Monday 20 April 2020 07:28:46 -0400 (0:00:02.462) 0:00:02.519 \*\*\*\*\*\*\*\*\*\*  
fatal: [test-hypervisior]: FAILED! =\> {“msg”: “The task includes an option with an undefined variable. **The error was: ‘item’ is undefined\n\nThe error** appears to be in ‘/home/akumar/vm/vm-snap-c2.yaml’: line 5, column 9, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: Create a snapshot\n ^ here\n”}

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
test-hypervisior : ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0

Monday 20 April 2020 07:28:47 -0400 (0:00:00.167) 0:00:02.687 \*\*\*\*\*\*\*\*\*\*

---

<div class="post-metadata">

**Author:** ![Akasurde](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/akasurde/32/230_2.png) [@Akasurde](https://forum.ansible.com/u/Akasurde)\
**Post date:** [April 21, 2020, 5:20am UTC](https://forum.ansible.com/t/how-to-create-multiple-guest-vms-snapshot/32734/2 "2020-04-21T05:20:45Z")

</div>

with\_items is a task level parameter and not vmware\_guest\_snapshot parameter. To fix, you might want to match the indentation of with\_items with delegate\_to or register parameters.

Please read [https://docs.ansible.com/ansible/latest/user\_guide/playbooks\_loops.html#with-items](https://docs.ansible.com/ansible/latest/user_guide/playbooks_loops.html#with-items)

---

<div class="post-metadata">

**Author:** ![Arvind\_Kumar](https://avatars.discourse-cdn.com/v4/letter/a/e495f1/32.png) [@Arvind\_Kumar](https://forum.ansible.com/u/Arvind_Kumar)\
**Post date:** [April 21, 2020, 4:54pm UTC](https://forum.ansible.com/t/how-to-create-multiple-guest-vms-snapshot/32734/3 "2020-04-21T16:54:57Z")

</div>

Thank you Abhijeet and team for support and immediate response 😊😊

Thanks & Regards  
Arvind Kumar  
Cell:- 9555962061.
