如何解决网络与可行的库存插件vmware_vm_inventory?



我使用可行的库存插件vmware_vm_inventory(见https://docs.ansible.com/ansible/latest/scenario_guides/vmware_scenarios/vmware_inventory_hostnames.html)。我也想为第一个连接的网络分组。那么正确的Propertyname是什么呢?

myvm.vmware.yml:

plugin: vmware_vm_inventory
strict: False
hostname: 10.10.10.1
username: user
password: password
validate_certs: False
with_tags: False
hostnames:
- config.name
properties:
- 'config.name'
- 'config.guestId'
- 'guest.ipAddress'
- 'guest.net'
- 'summary.runtime.powerState'

如果我运行命令:

ansible-inventory --host TESTVM001

我:

{
"ansible_host": "10.20.20.20",
"config": {
"guestId": "ubuntu64Guest",
"name": "TESTVM001"
},
"config.guestId": "ubuntu64Guest",
"config.name": "TESTVM001",
"guest": {
"ipAddress": "10.20.20.20",
"net": [
{
"connected": true,
"deviceConfigId": 4000,
"dnsConfig": null,
"ipAddress": [
"10.20.20.20",
"fe80::333:33ff:aaaa:903f"
],
"ipConfig": {
"autoConfigurationEnabled": null,
"dhcp": null,
"ipAddress": [
{
"ipAddress": "10.20.20.20",
"lifetime": null,
"origin": null,
"prefixLength": 16,
"state": "preferred"
},
{
"ipAddress": "fe80::333:33ff:aaaa:903f",
"lifetime": null,
"origin": null,
"prefixLength": 64,
"state": "unknown"
}
]
},
"macAddress": "00:50:00:ab:cd:ef",
"netBIOSConfig": null,
"network": "MYNETWORK"
}
]
},
"guest.ipAddress": "10.20.20.20",
"guest.net": [
{
"connected": true,
"deviceConfigId": 4000,
"dnsConfig": null,
"ipAddress": [
"10.20.20.20",
"fe80::333:33ff:aaaa:903f"
],
"ipConfig": {
"autoConfigurationEnabled": null,
"dhcp": null,
"ipAddress": [
{
"ipAddress": "10.20.20.20",
"lifetime": null,
"origin": null,
"prefixLength": 16,
"state": "preferred"
},
{
"ipAddress": "fe80::333:33ff:aaaa:903f",
"lifetime": null,
"origin": null,
"prefixLength": 64,
"state": "unknown"
}
]
},
"macAddress": "00:50:00:ab:cd:ef",
"netBIOSConfig": null,
"network": "MYNETWORK"
}
],
"runtime": {
"connectionState": "connected"
},
"runtime.connectionState": "connected",
"summary": {
"runtime": {
"powerState": "poweredOn"
}
},
"summary.runtime.powerState": "poweredOn"
}

我应该如何改变vm.vmware.yml文件中的- 'guest.net'行,以只获得网络名称。

What i tried:

- 'guest.net.0.network'- 'guest.net[0].network'

结果就是ansible-inventory的帮助输出。

我找到了。提示来自https://github.com/ansible-collections/community.vmware/issues/902

plugin: vmware_vm_inventory
strict: False
hostname: 10.10.10.1
username: user
password: password
validate_certs: False
with_tags: False
hostnames:
- config.name
properties:
- 'config.name'
- 'config.guestId'
- 'guest.ipAddress'
- 'guest.net'
- 'summary.runtime.powerState'
compose:
ansible_host: 'guest.ipAddress'
ansible_networkname: 'guest.net[0].network'
keyed_groups:
- key: ansible_networkname
prefix: "net0"
seperator: "-"

compose键理解jinja2。详见https://docs.ansible.com/ansible/latest/collections/community/vmware/vmware_vm_inventory_inventory.html

所以我得到的ansible-inventory --graph是:

@all:
|--@ubuntu64Guest:
|  |--vm1
|  |--vm2
|--@net0_NET01:
|  |--vm1
|--@net0_NET02:
|  |--vm2

相关内容

  • 没有找到相关文章

最新更新