【发布时间】:2016-11-11 21:08:03
【问题描述】:
我对 ansible 相当陌生,并试图探索字典插件选项。 下面是我的剧本,我正在尝试使用 from_json 模块将 json 文件转换为字典,然后我只想打印特定的键。 无法完成第二部分。
代码如下:
hosts: localhost
vars:
jsonVar: "{{ lookup('file', 'ConfigData.json') | from_json }}"
tasks:
- name: print numbers
debug: msg=" {{ jsonVar.cpsSiteName }}"
debug: msg=" {{ jsonVar.dmsDataCacheAddress }}"
debug: msg=" {{ jsonVar.htsHttpClientIdleConnectionTimeout }}"
debug: msg=" {{ jsonVar.palConsulServerList }}"
debug: msg=" {{ jsonVar.prsMaxIncoReqProcTime }}"
debug: msg=" {{ jsonVar.prsMaxNumberOfExecutedScriptInstructions }}"
debug: msg=" {{ jsonVar.prsmschapv2Password }}"
输出仅显示最后一个调试语句。 渴望知道是否有更聪明的方法可以从转换后的字典中访问特定变量,然后在输出中打印出来。
我尝试使用 with_items,但不起作用。 提前感谢您的帮助。
下面是一个示例 json 文件:
root@BVSETL04:/etc/ansible# less ConfigData.json
{
"appSupCommonPullSendProxyAuthInfo":0,
"appSupCommonPullSendWebAuthInfo":0,
"appSupDdcSupervisionEnabled":1,
"appSupDdcSupervisionInterval":15,
"appSupDdcSupervisionMaxNoOfFailures":4,
"appSupDNS_number_consequtive_failures":5,
"appSupDNS_supervision_interval":60,
}
【问题讨论】:
标签: dictionary ansible