This seems fairly simple that I just can't get the syntax right for. I've an ansible playbook that looks like this
- name: Get VMs
gather_facts: no
hosts: test
connection: local
tasks:
- name: Get all vms
vmware_vm_facts:
hostname: hostname
username: username
password: password
validate_certs: false
delegate_to: localhost
register: vmfacts
- name: Set vm name
set_fact:
vm_name: "{{ vmfacts.virtual_machines.keys() }}"
The output of the vmfacts variable is
ok: [serverhostname] => {
"vmfacts": {
"changed": false,
"failed": false,
"virtual_machines": {
"server1": {
"esxi_hostname": "host1",
"guest_fullname": "Microsoft Windows Server 2012 (64-bit)",
"ip_address": "",
"mac_address": [
"43:55:65:23:er:yr"
],
"power_state": "poweredOff",
"uuid": "839403jj-4jn8-8395-j4l2-i3j24ijil3",
"vm_network": {
"11:22:33:844:we:re": {
"ipv4": [],
"ipv6": []
}
}
},
"server2": {
"esxi_hostname": "host2",
"guest_fullname": "Microsoft Windows Server 2003 (32-bit)",
"ip_address": "",
"mac_address": [
"43:54:64:66:8s:47"
],
"power_state": "poweredOff",
"uuid": "423jlk2-80d9-jl22-2335-4324jklj432",
"vm_network": {
"22:44:55:66:9d:47": {
"ipv4": [],
"ipv6": []
}
}
}
}
I'm trying to get the uuid of each vm, but just can't work out how to get past the variable vm names (server1, server2). I've tried
- name: Print UUID
debug:
var: "{{ vmfacts.virtual_machines[item].uuid }}"
with_items: vm_name
which throws the error
{"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute u'vm_name'}