How to create Multiple Guest Vms Snapshot

522 views
Skip to first unread message

Arvind kumar

unread,
Apr 20, 2020, 7:34:22 AM4/20/20
to Ansible Project
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 **********
===============================================================================
Gathering Facts -------------------------------------------------------------------------------------------------------------------------------------------------- 2.46s
Create a snapshot ------------------------------------------------------------------------------------------------------------------------------------------------ 0.17s

Abhijeet Kasurde

unread,
Apr 21, 2020, 1:21:26 AM4/21/20
to ansible...@googlegroups.com
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.


--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/635f419e-3788-4396-bb05-9fefae07bf3e%40googlegroups.com.


--
Thanks,
Abhijeet Kasurde

Arvind Kumar

unread,
Apr 21, 2020, 12:55:53 PM4/21/20
to ansible...@googlegroups.com
Thank you Abhijeet and team   for support and immediate response 😊😊

Thanks & Regards
Arvind Kumar
Cell:- 9555962061.







Thanks & Regards
Arvind Kumar
Cell:- 9555962061.








Reply all
Reply to author
Forward
0 new messages