python - How to Json query in Ansible
问题描述
I am using ec2_lc_facts ansible module and registering the output to a variable called lc_facts. I am able to grab the block_device_mappings value using json query "{{ lc_facts.launch_configurations|json_query('[*].block_device_mappings') }}" but want to grab the volume_size and volume_type from the following output. Please help.
"lc_facts": {
"changed": false,
"failed": false,
"launch_configurations": [
{
"block_device_mappings": [
{
"device_name": "/dev/sda1",
"ebs": {
"delete_on_termination": true,
"volume_size": 40,
"volume_type": "gp2"
}
}
]
}
]
}
解决方案
The query below
- debug:
msg: "{{ lc_facts.launch_configurations|json_query('[*].block_device_mappings[0].ebs.[volume_size, volume_type]') }}"
gives
"msg": [
[
40,
"gp2"
]
]
To get hashes use this one
- debug:
msg: "{{ lc_facts.launch_configurations|json_query('[*].block_device_mappings[0].ebs.{size: volume_size, type: volume_type}') }}"
推荐阅读
- reactjs - React formik 验证Schema conditionalValidation
- testing - 我在服务器上的 jmeter 中得到 java.net.unknownhostexception
- javascript - JsViews / JsRender 使用 GroupBy 属性/属性渲染表格
- python - 使用python 3中的结构元素选择数组中的像素
- ios - 未找到请求的实体 FCM iOS React Native
- javascript - 如何在不使用 NodeJS 加载页面的情况下发送 POST 请求并获取响应
- python - 在 try except 块中附加 None 值
- node.js - 节点模块更新后 Gulp 不起作用
- xamarin.forms - 在 iOS/Android 应用上使用 IdentityServer 进行生物识别登录
- flutter - Flutter 在多个列表之间拖放列表项