ansible - Ansible:附加列表和字典
问题描述
我有以下内容:
containers:
- name: "c1"
devices:
https: { listen: "tcp:{{l}}:443", connect: "tcp:{{c}}:443", bind:"host", type: "proxy" }
proxy:
- { name: http, dst: 80, nxt: 80, proto: tcp }
- { name: ssh, dst: 1200, nxt: 22, proto: tcp }
- name: "c2"
devices:
pg : { listen: "tcp:{{ lip }}:8085", connect: "tcp:{{ cip }}:8085", bind: "host", type: "proxy" }
而且我想以这样的方式合并设备和代理,即c1的设备将包含
https: {listen: "tcp:{{l}}:443", connect: "tcp:{{c}}:443", bind:"host", type: "proxy"}
http: {listen: "tcp:{{l}}:80", connect: "tcp:{{c}}:80", bind:"host", type: "proxy" }
ssh: {listen: "tcp:{{l}}:1200", connect: "tcp:{{c}}:22", bind:"host", type: "proxy" }
其中两个新项目只是代理的重新排序值。我试图将其分解为几个步骤,但我一直遇到错误或拼写错误。任何帮助将不胜感激。
编辑
知道了!见下文。
解决方案
最后我把它分成两个文件,外部和内部。外面是这样的:
- include_tasks: inner.yml
with_items: "{{ containers }}"
loop_control:
loop_var: outer_item
内部是这样的:https ://gist.github.com/killua-eu/f81af4a84e9cc1394d028a9b193380e7
推荐阅读
- entity-framework - 更新 EF 6.x 后出现意外的异常链
- java - MongoDB 和 Spring MVC:PATCH 操作?
- kubernetes - Kubernetes NodePort 服务如何使用 Service.spec.externalTrafficPolicy=Local 路由流量?
- angular - 如何以角度将按钮角色添加到自定义元素以使其可由屏幕阅读器访问?
- python - Matplotlib 等高线图与曲线上的条件
- flutter - 颤振力为列表中的所有对象设置属性值
- google-kubernetes-engine - 有没有办法访问 Istio 在 GKE 中创建的 promsd 服务?
- json - 如何绕过 Nodebb 中先前声明的 json body-parser?
- reactjs - 如何使用基于条件的映射函数循环数组然后设置状态?
- hadoop - 在 Hadoop 中,如何验证我是否对 DFS 传输进行了数据加密?