Ansible 2.9 Cisco IOS模块环路



我正试图循环通过ios_l2_interfaces模块,但遇到了一个问题,我似乎无法让Ansible使用我定义的字典循环通过该模块。

我目前根据字典的访问/中继值来分隔播放,并循环项目。但是,这在l3_interfaces和lag_interfaces模块中也是一个挑战。所以我也想解决这些问题。

假设我有:

vars: 
interfaces:
- name: test1/0/1
access:
vlan: 10
- name: test2/0/1
trunk
allowed_vlans: 10,20,30

- name: Configure Trunk and Access Ports
ios_l2_interfaces
config:
{{ item }}
state: replaced
with_items: {{ interfaces }}

我得到的错误是:

argument config is of type <type 'dict'> and we were unable to convert to list: <type 'dict'> cannot be converted to a list"

我该如何写这出戏,以便循环浏览具有不同属性的词典?

在我写这篇文章的时候就想出来了。。。在{{item}}声明之前缺少一个"-"。

这起到了作用:

- name: Configure Trunk and Access Ports
ios_l2_interfaces
config:
- {{ item }}
state: replaced
with_items: {{ interfaces }}

最新更新