Ability to create unique snapshot names
Closed this issue · 2 comments
It'd be nice to be able to name the snapshots something unique/different on each host. For example, I'd like to use the UUID of the vmware guest as its snapshot name. Unfortunately, I've not found a way to use ansible facts or magic variables to do so. For example, this doesn't work as expected:
target_snapshot_name: "brian-{{ ansible_hostname }}"
Gives me 'brian-brian-lab' when the name of the VMWare API host is 'brian-lab'.
This is probably my ignorance with the intricacies of roles and vars/group_vars.
That's correct, and that is because the API host is the one running the actions.
Can you try using {{ hostvars[item.vm][ansible_hostname] }}
instead? This is the same loop item as the rest of the snap code is using.
@bschonec Been a while, but I have reworked the code into version 2.0.0. Which also makes the vm_info
variable available with all info reported back by the community.vmware.vmware_guest_info
module.
When using the playbook below, it will create snapshots with the VMWare UUID of each VM:
# This playbook will remove all snapshots for all VMs in the inventory
- name: 'Ensure snapshots of targeted VMs'
hosts: 'vmware_guests'
gather_facts: false
tasks:
- name: 'Ensure snapshots'
ansible.builtin.import_role:
name: 'vmware'
vars:
vmware_target_action: 'snap'
vmware_target_state: 'present'
vmware_target_snapshot_name: "{{ vm_info['instance']['instance_uuid'] }}"
I'm confident this will address your issue ;-)