Json 从JMESPATH表达式中选择中级属性
我试图使用Ansible的json_查询为特定虚拟机选择集群名称,该查询在后端使用JMESPATH。 我已经在上学习了教程和示例,但无法构造正确的查询 我的数据结构如下:Json 从JMESPATH表达式中选择中级属性,json,ansible,jmespath,Json,Ansible,Jmespath,我试图使用Ansible的json_查询为特定虚拟机选择集群名称,该查询在后端使用JMESPATH。 我已经在上学习了教程和示例,但无法构造正确的查询 我的数据结构如下: { "datacenters": [ { "name": "dc-a", "clusters": [ { "name": "cluster-a", "hosts": [ { "name": "host-a", "vms": [
{
"datacenters": [
{
"name": "dc-a",
"clusters": [
{ "name": "cluster-a",
"hosts": [
{
"name": "host-a",
"vms": [
{
"name": "vm-a",
"summary": {
"mem": "8",
"diskGB": "78.00",
"annotation": "",
"state": "poweredOn",
"ostype": "Microsoft Windows Server 2008 R2 (64-bit)",
"cpu": "2"
}
},
{
"name": "vm-b",
"summary": {
"mem": "24",
"diskGB": "114.00",
"annotation": "",
"state": "poweredOn",
"ostype": "Microsoft Windows Server 2008 R2 (64-bit)",
"cpu": "4"
}
}]
}]
}]
}]
}
我可以使用下面的查询选择VM('VM-a'),但我正在寻找集群(即'cluster-a')
数据中心[]。群集[]包含(主机[]。虚拟机[]。名称,'vm-a')。名称[]
无需证明,请阅读以了解如何正确地提出有关StackOverflow的问题。我认为这是一个足够好的问题。我当然见过更糟的。另外,这是海报的第一个问题,这里没有必要过于正式。更不用说否决投票了。
datacenters[].clusters[].hosts[].vms[?name=='vm-a'].name[]