After completing this section, you should be able to use Ansible to configure the OSPF routing protocol on network devices.
Network administration may involve implementing, managing, or troubleshooting dynamic routing protocols.
The following are minimal OSPF configurations for a VyOS and an IOS device:
VyOS:
set interfaces loopback lo address 10.0.0.1/32 set protocols ospf parameters router-id 10.0.0.1 set protocols ospf area 0 network 10.10.1.0/24 set protocols ospf log-adjacency-changes
IOS:
no router ospf 1 router ospf 1 router-id 172.16.0.1 network 172.16.2.0 0.0.0.3 area 0 network 172.16.5.0 0.0.0.3 area 0 network 172.16.10.0 0.0.0.3 area 0
In the IOS example, 1 is the process id of the OSPF process. In both, the router id is set to a loopback IPv4 address. This is a single area example, all routers in area 0.
Statements such as the ones listed on the previous slide are easy to convert into playbook tasks using suitable *os_config modules (using vyos_config and ios_config, in this case).
A more flexible way to manage the process, though, uses Jinja2 templates in conjunction with *os_config modules to generate and apply blocks of configuration statements.
---
- name: Play that sets up OSPF on the VyOS devices
hosts: vyos
gather_facts: no
vars_files:
- "{{ playbook_dir }}/vars/ospf-vars.yml"
tasks:
- name: configure devices
vyos_config:
src: j2/vyos-ospf.j2
save: yes
- name: Play that sets up OSPF on the IOS devices
hosts: ios
gather_facts: no
vars_files:
- "{{ playbook_dir }}/vars/ospf-vars.yml"
tasks:
- name: configure devices
ios_config:
src: j2/ios-ospf.j2
save: yes