我试图从交换机收集不属于端口通道的接口列表。我正在尝试使用计数器控制列表的位置,以便随后可以指定键,以便可以看到该值,但操作失败。
但是当我使用计数器时,我得到的列表对象没有属性。
- name: Check for port-channel config in the Ethernet
nxos_command:
commands: sh run int {{ item }} | include channel-group
register: output
with_items: "{{ ethernet }}"
- name: Trim down conf output
set_fact:
int_config: "{{ output['results'] }}"
- debug:
msg:
- "The counter is {{ counter | int }}"
- "Found interface with channgel-group, interface {{ item }}"
name: show the results
loop: "{{ int_config[counter] }}"
loop_control:
index_var: counter
答案 0 :(得分:0)
这是您要找的吗?
- debug:
msg: "Counter: {{ item|int }} Interface: {{ int_config[item] }}"
loop: "{{ range(0, int_config|length)|list }}"
此任务以及以下数据
int_config:
- abc
- def
- ghi
给予
"msg": "Counter: 0 Interface: abc"
"msg": "Counter: 1 Interface: def"
"msg": "Counter: 2 Interface: ghi"