Как получить имя конкретного словаря - Ansible

Мне нужна помощь, чтобы получить только имя виртуальных машин моего хоста ESXI.

- name: VM-FACTS
  vmware_vm_facts:
    hostname: "{{ ansible_hostname }}"
    username: "{{ ansible_user }}"
    password: "{{ ansible_password }}"
    validate_certs: False
  delegate_to: localhost
  register: vmfacts

- name: Debug
  debug:
    var: vmfacts.virtual_machines

Выход переменной:

ok: [xxxxx] => {
    "vmfacts.virtual_machines": {
        "001-MV-Test": {
            "cluster": null,
            "esxi_hostname": "xxxxx",
            "guest_fullname": "Red Hat Enterprise Linux 7 (64-bit)",
            "ip_address": "10.252.130.196",
            "mac_address": [
                "00:50:56:b3:c5:b0"
            ],
            "power_state": "poweredOn",
            "uuid": "4233910e-4fde-7d1b-765d-b748bf9d1cd9",
            "vm_network": {
                "00:50:56:b3:c5:b0": {
                    "ipv4": [
                        "10.252.130.196"
                    ],
                    "ipv6": [
                        "fe80::250:56ff:feb3:c5b0"
                    ]
                }
            }
        }
    }
}

Я хочу иметь только имя виртуальной машины (001-MV-Test). Потому что я хочу получить больше информации с помощью vmware_guest_facts.

Спасибо!


person Alex    schedule 23.11.2018    source источник
comment
Означает ли это, что вы не знакомы с шаблонами Jinja2?   -  person mdaniel    schedule 24.11.2018


Ответы (1)


Это тот код, который вы ищете?

- debug: msg="{{ item.key }}"
  loop: "{{ vmfacts.virtual_machines|dict2items }}"
person Vladimir Botka    schedule 25.11.2018
comment
Спасибо, Владимир! - person Alex; 27.11.2018