在 ansible 中提取并连接 json 个节点
Extract and concatinate json nodes in ansible
我有 Ansible 任务,其中输出已注册。
它是 curl/uri
模块调用的 elastisearch 请求的响应。
一个例子:
{
"changed": false,
"msg": "All items completed",
"results": [
{
"_ansible_item_result": true,
"_ansible_no_log": false,
"changed": false,
"content_length": "747",
"content_type": "application/json; charset=UTF-8",
"invocation": {...},
"item": "content",
"json": {
"snapshots": [
{
"duration_in_millis": 2863,
"end_time": "2016-09-25T16:00:05.357Z",
"end_time_in_millis": 1474819205357,
"failures": [],
"indices": [
"content_h_20160817_1155",
"content_s_20160817_1159",
"content_p_20160817_1158",
"content_t_20160909_0451",
"content_v_20160909_0454",
"content_h_20160909_0431",
"content_v_20160817_1201",
"content_m_20160817_1157",
"content_m_20160909_0438",
"content_p_20160909_0443",
"content_t_20160817_1200",
"content_i_20160817_1156",
"content_i_20160909_0434",
"content_s_20160909_0447"
],
"shards": {
"failed": 0,
"successful": 28,
"total": 28
},
"snapshot": "snapshot_content_20160925_1600",
"start_time": "2016-09-25T16:00:02.494Z",
"start_time_in_millis": 1474819202494,
"state": "SUCCESS",
"version": "2.3.3",
"version_id": 2030399
}
]
},
"msg": "OK (747 bytes)",
"redirected": false,
"status": 200,
"url": "url"
},
{
"_ansible_item_result": true,
"_ansible_no_log": false,
"changed": false,
"content_length": "526",
"content_type": "application/json; charset=UTF-8",
"invocation": {...},
"item": "log",
"json": {
"snapshots": [
{
"duration_in_millis": 5002,
"end_time": "2016-09-25T16:01:24.174Z",
"end_time_in_millis": 1474819284174,
"failures": [],
"indices": [
"log_i_20160804_0749",
"log_p_20160804_0811",
"log_v_20160804_0847",
"log_m_20160804_0758",
"log_h_20160804_0746",
"log_t_20160804_0829",
"log_s_20160804_0825"
],
"shards": {
"failed": 0,
"successful": 14,
"total": 14
},
"snapshot": "snapshot_log_20160925_1600",
"start_time": "2016-09-25T16:01:19.172Z",
"start_time_in_millis": 1474819279172,
"state": "SUCCESS",
"version": "2.3.3",
"version_id": 2030399
}
]
},
"msg": "OK (526 bytes)",
"redirected": false,
"status": 200,
"url": "url"
}
]
}
接下来,我只需要从 result.
中的每个元素中获取 indices[]
我怎样才能将所有 result[]
节点的 indices[]
数组提取到一个变量中,以便以后能够使用 with_items
?
谢谢。
PS。我省略了 invocation
个元素,它们太长了。
我有 Ansible 任务,其中输出已注册。
它是 curl/uri
模块调用的 elastisearch 请求的响应。
一个例子:
{
"changed": false,
"msg": "All items completed",
"results": [
{
"_ansible_item_result": true,
"_ansible_no_log": false,
"changed": false,
"content_length": "747",
"content_type": "application/json; charset=UTF-8",
"invocation": {...},
"item": "content",
"json": {
"snapshots": [
{
"duration_in_millis": 2863,
"end_time": "2016-09-25T16:00:05.357Z",
"end_time_in_millis": 1474819205357,
"failures": [],
"indices": [
"content_h_20160817_1155",
"content_s_20160817_1159",
"content_p_20160817_1158",
"content_t_20160909_0451",
"content_v_20160909_0454",
"content_h_20160909_0431",
"content_v_20160817_1201",
"content_m_20160817_1157",
"content_m_20160909_0438",
"content_p_20160909_0443",
"content_t_20160817_1200",
"content_i_20160817_1156",
"content_i_20160909_0434",
"content_s_20160909_0447"
],
"shards": {
"failed": 0,
"successful": 28,
"total": 28
},
"snapshot": "snapshot_content_20160925_1600",
"start_time": "2016-09-25T16:00:02.494Z",
"start_time_in_millis": 1474819202494,
"state": "SUCCESS",
"version": "2.3.3",
"version_id": 2030399
}
]
},
"msg": "OK (747 bytes)",
"redirected": false,
"status": 200,
"url": "url"
},
{
"_ansible_item_result": true,
"_ansible_no_log": false,
"changed": false,
"content_length": "526",
"content_type": "application/json; charset=UTF-8",
"invocation": {...},
"item": "log",
"json": {
"snapshots": [
{
"duration_in_millis": 5002,
"end_time": "2016-09-25T16:01:24.174Z",
"end_time_in_millis": 1474819284174,
"failures": [],
"indices": [
"log_i_20160804_0749",
"log_p_20160804_0811",
"log_v_20160804_0847",
"log_m_20160804_0758",
"log_h_20160804_0746",
"log_t_20160804_0829",
"log_s_20160804_0825"
],
"shards": {
"failed": 0,
"successful": 14,
"total": 14
},
"snapshot": "snapshot_log_20160925_1600",
"start_time": "2016-09-25T16:01:19.172Z",
"start_time_in_millis": 1474819279172,
"state": "SUCCESS",
"version": "2.3.3",
"version_id": 2030399
}
]
},
"msg": "OK (526 bytes)",
"redirected": false,
"status": 200,
"url": "url"
}
]
}
接下来,我只需要从 result.
中的每个元素中获取 indices[]
我怎样才能将所有 result[]
节点的 indices[]
数组提取到一个变量中,以便以后能够使用 with_items
?
谢谢。
PS。我省略了 invocation
个元素,它们太长了。