我们正在制作一个简单的剧本来收集我们所有的路由器接口说明,以便我们可以查看哪些说明不充分的文档,然后进行更正,因为这将使以后的自动化工作变得更加容易。我非常亲密,但坚持希望的只是一个简单的错误。我可以通过主机文件组(仅2个测试路由器)进行循环访问,并且确实可以循环并收集接口,但是似乎将第二个路由器的接口放在两个路由器下?我确定我没有在Jinja2模板中正确循环,但不确定如何更正。
这是我的剧本:
---
- name: Check Interface Descriptions
hosts: prod
connection: network_cli
gather_facts: no
tasks:
- name: GATHER ROUTER FACTS
ios_facts:
- name: Write Interface Descriptions to file
template: src=/home/drojas/networkauto/sedinterfaces.j2 dest=/home/drojas/networkauto/output/interfaces.txt
with_dict: "{{ ansible_net_interfaces }}"
这是我的Jinja2模板:
{% for host in groups['prod'] %}
Hostname: {{ host }}
{% for interface in ansible_net_interfaces %}
{{interface}} {{ansible_net_interfaces[interface]['description']}}
{% endfor %}
{% endfor %}
这是输出:
Hostname: 10.113.2.13
GigabitEthernet0/1.101
GigabitEthernet0/1.100
Async0/0/14
Async0/0/15
Async0/0/10
Async0/0/11
Async0/0/12
Async0/0/13
GigabitEthernet0/1
Async0/0/5
Embedded-Service-Engine0/0
Loopback0
Async0/0/6
Async0/0/7
Async0/0/4
GigabitEthernet0/0 test description on 10.113.2.50 gi0/0
Async0/0/2
Async0/0/3
Async0/0/0
Async0/0/1
Async0/0/8
Async0/0/9
Hostname: 10.113.2.50
GigabitEthernet0/1.101
GigabitEthernet0/1.100
Async0/0/14
Async0/0/15
Async0/0/10
Async0/0/11
Async0/0/12
Async0/0/13
GigabitEthernet0/1
Async0/0/5
Embedded-Service-Engine0/0
Loopback0
Async0/0/6
Async0/0/7
Async0/0/4
GigabitEthernet0/0 test description on 10.113.2.50 gi0/0
Async0/0/2
Async0/0/3
Async0/0/0
Async0/0/1
Async0/0/8
Async0/0/9