json_query 在 ansible 中找到键值并在 json 对象中打印另一个键
json_query in ansible to find the key value and print the other key in the json object
这是我想在 ansible 中使用 json_query 和 keyvalue=65060 搜索的原始数据并打印相应的 Neighbor,任何人都可以帮忙。
到目前为止我得到了这个:
- name: data manipulate
debug: msg="{{ msnjson | json_query(msnquery) }}"
vars:
msnquery: "[*].AS"
但这只显示所有 AS 键,但我正在寻找值为 65060 的键和相应的 Neighbor 键。
[
{
"AS": "65060",
"InQ": "0",
"MsgRcvd": "258259",
"MsgSent": "120410",
"Neighbor": "99.99.99.5",
"OutQ": "0",
"Spk": "0",
"StPfxRcd": "1",
"TblVer": "2241",
"UpDown": "2w0d"
},
{
"AS": "64600",
"InQ": "0",
"MsgRcvd": "281828",
"MsgSent": "120498",
"Neighbor": "192.168.100.1",
"OutQ": "0",
"Spk": "0",
"StPfxRcd": "33",
"TblVer": "2241",
"UpDown": "12w5d"
},
{
"AS": "64600",
"InQ": "0",
"MsgRcvd": "281867",
"MsgSent": "120498",
"Neighbor": "192.168.100.2",
"OutQ": "0",
"Spk": "0",
"StPfxRcd": "33",
"TblVer": "2241",
"UpDown": "12w5d"
},
{
"AS": "64600",
"InQ": "0",
"MsgRcvd": "258516",
"MsgSent": "120499",
"Neighbor": "192.168.100.4",
"OutQ": "0",
"Spk": "0",
"StPfxRcd": "19",
"TblVer": "2241",
"UpDown": "5w6d"
}
]
尝试
- name: data manipulate
debug: msg="{{ msnjson | json_query(msnquery) }}"
vars:
msnquery: "[?AS=='65060'].Neighbor"
这是我想在 ansible 中使用 json_query 和 keyvalue=65060 搜索的原始数据并打印相应的 Neighbor,任何人都可以帮忙。
到目前为止我得到了这个:
- name: data manipulate
debug: msg="{{ msnjson | json_query(msnquery) }}"
vars:
msnquery: "[*].AS"
但这只显示所有 AS 键,但我正在寻找值为 65060 的键和相应的 Neighbor 键。
[
{
"AS": "65060",
"InQ": "0",
"MsgRcvd": "258259",
"MsgSent": "120410",
"Neighbor": "99.99.99.5",
"OutQ": "0",
"Spk": "0",
"StPfxRcd": "1",
"TblVer": "2241",
"UpDown": "2w0d"
},
{
"AS": "64600",
"InQ": "0",
"MsgRcvd": "281828",
"MsgSent": "120498",
"Neighbor": "192.168.100.1",
"OutQ": "0",
"Spk": "0",
"StPfxRcd": "33",
"TblVer": "2241",
"UpDown": "12w5d"
},
{
"AS": "64600",
"InQ": "0",
"MsgRcvd": "281867",
"MsgSent": "120498",
"Neighbor": "192.168.100.2",
"OutQ": "0",
"Spk": "0",
"StPfxRcd": "33",
"TblVer": "2241",
"UpDown": "12w5d"
},
{
"AS": "64600",
"InQ": "0",
"MsgRcvd": "258516",
"MsgSent": "120499",
"Neighbor": "192.168.100.4",
"OutQ": "0",
"Spk": "0",
"StPfxRcd": "19",
"TblVer": "2241",
"UpDown": "5w6d"
}
]
尝试
- name: data manipulate
debug: msg="{{ msnjson | json_query(msnquery) }}"
vars:
msnquery: "[?AS=='65060'].Neighbor"