【发布时间】:2019-11-02 14:15:32
【问题描述】:
我以为这很简单,但我很难过。如何为每个子 activedirectory_devops.hosts 条目选择父 hostvars 条目?如果这是 SQL,我会尝试编写 join。
{
"_meta": {
"hostvars": {
"foo_423d1fe9-d964-d45e-ec69-2565589deae6": {
"ansible_host": "192.168.0.1",
"config.cpuHotAddEnabled": true,
"config.cpuHotRemoveEnabled": false,
"config.hardware.numCPU": 4,
"config.instanceUuid": "503d1a90-8b07-4b33-2648-5d1f9330e5f7",
"config.name": "devops-dal13-bc1",
"config.template": false,
"guest.guestId": "windows9Server64Guest",
"guest.guestState": "running",
"guest.hostName": "foo.company.com",
"guest.ipAddress": "192.168.0.1",
"inventory_dir": "/ansible/inventories",
"inventory_file": "/ansible/inventories/vcsa2.vmware.yml",
"name": "foo",
"runtime.maxMemoryUsage": 16384
},
,
"bar_420b8b36-fffe-6f29-3e32-0ce9aa0d0ad3": {
"config.cpuHotAddEnabled": false,
"config.cpuHotRemoveEnabled": false,
...
}
}
},
"activedirectory_devops": {
"hosts": [
"foo_423d1fe9-d964-d45e-ec69-2565589deae6",
"bar_420b8b36-fffe-6f29-3e32-0ce9aa0d0ad3"
]
},
我不完整的尝试:
jq '. as $parent | .activedirectory_devops.hosts as $children | .'
【问题讨论】:
-
请发布一个有效的 JSON 样本。它应该根据mcve 指南简明扼要。另外,不要忘记显示预期的输出。