How to do it...

  1. Install the jxmlease Python package, as follows:
$ pip3 install jxmlease
  1. Create a new playbook called pb_get_ospf_peers.yml and populate it with the following task to extract OSPF peering information:
---
- name: "Get OSPF Status"
hosts: junos
tasks:
- name: "Get OSPF Neighbours Data"
junos_command:
commands: show ospf neighbor
display: xml
register: ospf_output

- name: "Extract OSPF Neighbour Data"
set_fact:
ospf_peers: "{{ ospf_output.output[0]['rpc-reply']\
['ospf-neighbor-information']['ospf-neighbor'] }}"
  1. Update the pb_get_ospf_peers.yml playbook with the following task to validate that all OSPF peerings across all nodes are in a Full state:
    - name: "Validate All OSPF Peers are in Full State"
assert:
that: item['ospf-neighbor-state'] == 'Full'
fail_msg: "Peer on Interface {{item['interface-name']}} is Down"
success_msg: "Peer on Interface {{item['interface-name']}} is UP"
loop: "{{ospf_peers}}"