如何检索特定字典的名称 - Ansible [英] How retrieve the name of specific dictionary - Ansible
本文介绍了如何检索特定字典的名称 - Ansible的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要帮助才能仅检索 ESXI 主机的虚拟机名称.
I need help to retrieve only the name of the Virtual Machines of my ESXI Host.
- 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 检索更多信息.
I want to have only the name of the virtual machine (001-MV-Test). Because, I want to retrieve more information with vmware_guest_facts.
谢谢!
推荐答案
这是您要找的代码吗?
- debug: msg="{{ item.key }}"
loop: "{{ vmfacts.virtual_machines|dict2items }}"
这篇关于如何检索特定字典的名称 - Ansible的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文