How to assign random name for vmware snapshot?

46 views
Skip to first unread message

Mani

unread,
May 7, 2020, 4:30:36 AM5/7/20
to Ansible Project
I am a newbie to ansible and I am trying to take a snapshot of multiple VM's with a random snapshot name including the VM name (vmname + random number or timestamp). 

I am able to take snapshot using the VM name with the below code:

---
- name: Gather all registered virtual machines
  vmware_vm_info:
    hostname: '{{ running_host }}'
    username: '{{ esxi_user }}'
    password: '{{ esxi_pass }}'
  delegate_to: localhost
  register: vminfo

- name: Create a snapshot
  vmware_guest_snapshot:
    hostname: "{{ vcenter_server }}"
    username: "{{ vcenter_user }}"
    password: "{{ vcenter_pass }}"
    datacenter: 'VDC'
    folder: 'VDC/vm/'
    name: "{{ item.guest_name }}"
    state: present
    snapshot_name: "{{ item.guest_name }}"
  with_items:
    - "{{ vminfo.virtual_machines }}"

Please provide your inputs.

Abhijeet Kasurde

unread,
May 7, 2020, 4:46:53 AM5/7/20
to ansible...@googlegroups.com

Either - "{{ hostname | to_uuid }}" or  "{{ '%Y_%m_%d_%H_%M_%S' | strftime }}"

--
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/8c90bfb1-30ff-4f56-b1db-42320a9e55c8%40googlegroups.com.


--
Thanks,
Abhijeet Kasurde

Mani

unread,
May 7, 2020, 5:33:19 AM5/7/20
to Ansible Project
Thank you, Abhijeet. That worked!!
To unsubscribe from this group and stop receiving emails from it, send an email to ansible...@googlegroups.com.


--
Thanks,
Abhijeet Kasurde
Reply all
Reply to author
Forward
0 new messages