I've just found the UUID is avaible in ansible_product_uuid (or facter fact 
as 'uuid'). So easy enough if we gather facts from the machine first.


On Wednesday, 17 October 2018 17:18:10 UTC+1, KSS wrote:
>
> Hi,
>
> I'm looking at switching to using the vmware_guest_snapshot module to take 
> snapshots of VMs before performing package updates on them (I previously 
> used another custom module where we changed case of hostnames to lowercase 
> and compared to vm object name after also making that lowercase). 
> Unfortunately, our VMs are not consistently named in vCenter - they can be 
> lowercase, uppercase or even a mixture of both - but the module only 
> supports finding VMs using the exact case. This makes it difficult when 
> passing hostnames to a playbook, we always pass a lowercase and the 
> hostnames are used as the VM name by my playbook.
>
> I've thought about using a daily cache file created using the 
> vmware_vm_facts module (we don't want to have to query vCentre for these 
> facts on each run as it contains hundreds of VMs), retrieving the machine 
> UUID from that cache and using it to identify the VM to snapshot (rathre 
> than its name). However, I've not been able to figure out how to select 
> from my cache file (without actually making it all lowercase).
>
> So to debug, the following just writes out the facts gathered by 
> vmware_vm_facts and then the debug grabs the UUID by matching the inventory 
> hostname (but obviously that only works if it matches the case sensitive 
> hostname);
>
>         - name: Write out facts to file
>           copy: content="{{ vm_facts.virtual_machines }}" 
> dest=vm_facts.cache
>           delegate_to: localhost
>           run_once: 'True'
>
>         - debug:
>             msg: "My UUID is {{ myvm[inventory_hostname]['uuid'] }}"
>           vars:
>             myvm: "{{ lookup('file', 'vm_facts.cache') }}"
>
> I know I can work with this by making things all lower case as follows;
>
>         - debug:
>             msg: "My UUID is {{ myvm[inventory_hostname|lower]['uuid'] }}"
>           vars:
>             myvm: "{{ lookup('file', 'vm_facts.cache') | lower }}"
>
> Sample cache file (ignore values - they've been changed);
>
> {"SERVER1": {"esxi_hostname": "test_esx", "vm_network": {"00:00:00:00:00": 
> {"ipv4": ["10.0.0.1"], "ipv6": ["f----"]}}, "power_state": "poweredOn", 
> "mac_address": ["00:00:00:00:00"], "guest_fullname": "CentOS 4/5 or later 
> (64-bit)", "ip_address": "10.0.0.1", "uuid": 
> "422342435-de04-5014-58d4-475ab4ffdc8a"}, "server2": {"esxi_hostname": 
> "test_esx", "vm_network": {}, "power_state": "poweredOn", "mac_address": 
> ["00:00:00:00:00:00"], "guest_fullname": "CentOS 4/5 or later (64-bit)", 
> "ip_address": "", "uuid": "422344329-d4df-72c9-477b-bdd976e72be7"}}
>
> But can anyone advise a better way of achieving this without having to 
> change everything to lowercase (just in case UUID ever contains upper and 
> lowercase characters)? Alternatively, a way to find the VM name from the 
> cache file and use that to pass as the name to the module.
>
> It would be nice if the vmware modules would allow case insensitive 
> matches of VM names (the modules already cater for a situation where more 
> than one VM has the same name by using the name_match parameter).
>
> Ansible Version: 2.6.5
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/b51e1eec-df88-44cb-a748-32d51f7ee31c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to