loops - Ansible 检查是否键入复杂字典
问题描述
我有复杂的字典结构,我想检查是否定义了子键。我什至不知道这是否可能..
这是我的字典的样子:
config:
1:
client: ubuntu
network_setup:
- routed
ports:
sw1: null
sw2:
client: 1/0/2
lte: 1/0/5
2:
client: archlinux
network_setup:
- bridged
ports:
sw1:
client: 1/0/4
sw2: null
...
注意:无法定义 lte 密钥!
我想要的是检查 lte 是否在配置字典中定义。理想情况下,我需要遍历每个条目config
。
我可能会写一个自定义插件,因为这听起来真的很难做到..
解决方案
如果它是一个列表,你必须循环它,你可以试试这个条件
- debug: var=test_item.ports.sw2.lte
when: test_item.ports.sw2.lte is defined
with_items: "{{ config }}"
loop_control:
loop_var: test_item
when 条件将检查变量是否已定义。
推荐阅读
- amazon-web-services - AWS HTTPS Certification not working more than 48 hours dns update
- reactjs - React.js 材料表:如何在加载时禁用操作图标?
- javascript - 如何在 reactjs 中创建像 google-input-tool 这样的下拉输入?
- apache-pig - 如何在猪中将字符串转换为元组
- spring - Atomikos - 唯一的资源名称
- r - 如何在 (...) 中获取值并取平均值?
- linux - 检测 USB 驱动器何时连接脚本未按预期工作
- git - 为什么在将本地分支推送到远程 git repo 后远程分支被跟踪但本地分支没有上游分支?
- intellij-idea - 如何在 Intellij 中删除检查配置文件?
- jquery - 当动态添加的文本区域为空时禁用提交按钮 - jQuery