Michael et al, feel free to comment on this "hack" and let me know what else could be done to simplify.
---
#-----------------------PLAY 1 ------------------------------------------#
- name: collecting ospf data
hosts: routers
connection: local
gather_facts: no
# note: routers only has two hosts/devices in it. Basically, the two I want to compare
tasks:
- name: get ospf facts
ospf_facts: device={{inventory_hostname}} interface={{ ospf_interface }}
register: ospf_data
# just a bunch of debug messages displaying some facts on each device during the run
- name: interface ip addresses used for OSPF peering
debug: msg="local router interface IP address- {{ ospf_data.ofacts.oif_ip }} on {{ ospf_data.ofacts.oif }}"
- name: is ospf active on interface?
debug: msg="ospf active on interface = {{ ospf_data.ofacts.ospf_active_on_intf }}"
- name: process id check
debug: msg="at least one ospf process configurd on router = {{ ospf_data.ofacts.processExists }}"
- name: MTUs of interfaces
debug: msg="MTU = {{ ospf_data.ofacts.oif_mtu }}"
- name: ospf network type
debug: msg="network type = {{ ospf_data.ofacts.network_type }}"
- name: ospf timers on interface
debug: msg="{{ ospf_data.ofacts.timers }}"
- name: interface status
debug: msg="interface status={{ ospf_data.ofacts.interface_status.status }} and line protocol = {{ ospf_data.ofacts.interface_status.line_proto}}"
- name: display neighbors and state
debug: msg="{{ospf_data.ofacts.oif_neighbors}}"
#-----------------------PLAY 2 ------------------------------------------#
# local is just 127.0.0.1, so it runs just once
- name: ospf config validation & automated re-configuration
hosts: local
connection: local
gather_facts: no
#to simplify a bit, using "root" as what the "other" device will be compared to...10.1.1.110 and 10.1.1.1.120 are both devices from routers in the first play
vars:
root: "{{ hostvars['10.1.1.110'].inventory_hostname }}"
other: "{{ hostvars['10.1.1.120'].inventory_hostname }}"
# creating new short name variables to simplify the calling of them in this play. Contents of the vars file is below too.
vars_files:
- vars/simple_vars.yml
tasks:
- debug: msg="{{ root }} mtu = {{ r1_mtu }} && {{ other }} mtu = {{ r2_mtu }}"
- debug: msg="*******MTU mismatch*******"
when: r1_mtu != r2_mtu
- debug: msg="*******MTUs match*********"
when: r1_mtu == r2_mtu
- name: auto re-config of MTU by increasing lower MTU to be equal to higher MTU value
mtu: dev1={{ r1_ip }} dev2={{ r2_ip }} mtu1={{ r1_mtu }} mtu2={{ r2_mtu }} int1={{ r1_oif }} int2={{ r2_oif }}
when: r1_mtu != r2_mtu
---
r1_mtu: "{{ hostvars[root].ospf_data.ofacts.oif_mtu }}"
r2_mtu: "{{ hostvars[other].ospf_data.ofacts.oif_mtu }}"
r1_ip: "{{ hostvars[root].inventory_hostname }}"
r2_ip: "{{ hostvars[other].inventory_hostname }}"
r1_oif: "{{ hostvars[root].ospf_data.ofacts.oif }}"
r2_oif: "{{ hostvars[other].ospf_data.ofacts.oif }}"