如何选择名字等于孩子名字的父母
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何选择名字等于孩子名字的父母相关的知识,希望对你有一定的参考价值。
我以为这很简单,但是我很困惑。如何为每个子hostvars
条目选择父activedirectory_devops.hosts
条目?如果这是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 | .'
答案
如何为每个子activedirectory_devops.hosts条目选择父hostvars条目?
下面的jq查询就是这样:
.activedirectory_devops.hosts[] as $host
| ._meta.hostvars[$host]
以上是关于如何选择名字等于孩子名字的父母的主要内容,如果未能解决你的问题,请参考以下文章