我有一个Ansible角色,该角色使用变量:connection_name,connection_ip等来创建连接。
在我的主机文件中,我可以有许多“连接”并将其定义为列表的字典:
host_file:
hosts:
host_one:
domain: one
ip: 172.18.1.1
connection:
- connection_name: two
connection_ip: 172.18.1.2
- connection_index: three
local_hub_ip: 172.18.1.3
host_two:
domain: two
ip: 172.18.1.2
host_three:
domain: three
ip: 172.18.1.3
如何将每个“连接”对象传递给我的Ansible角色,以便它可以使用嵌套变量“ connection_name”和“ connection_ip”?我尝试像这样使用“ with_items”和“ with_dict”:
---
- name: Creating new connection
hosts: "{{ host_name }}"
gather_facts: no
become: yes
remote_user: "{{ user | default('root')}}"
tasks:
- include_role:
name: connection-create
with_items: "{{connection}}"
但是我得到一个“失败:connection_name未定义”,因为它以{“ connection_name”:2,“ connection_ip”:172.18.1.2}而不是内部“ connection_name”:2,“ connection_ip”:没有{}的172.18.1.2。
答案 0 :(得分:0)