- Create a new playbook called pb_junos_ping.yml with the following task, to ping all core loopbacks within our sample network:
---
- name: "Validate Core Reachability"
hosts: junos
tasks:
- name: "Ping Across All Loopback Interfaces"
junos_ping:
dest: "{{ item.value.split('/')[0] }}"
interface: lo0.0
size: 512
with_dict: "{{lo_ip}}"
vars:
Ansible_connection: network_cli
register: ping_rst
ignore_errors: yes
- Update the pb_junos_ping.yml playbook with the following task to create a custom report to capture the ping results:
- name: Create Ping Report
blockinfile:
block: |
Node | Destination | Packet Loss | Delay |
-----| ------------| ------------| ------|
{% for node in play_hosts %}
{% for result in hostvars[node].ping_rst.results %}
{% if result.rtt is defined %}
{{ node }} | {{ result.item.value }} | {{ result.packet_loss }} | {{ result.rtt.avg }}
{% else %}
{{ node }} | {{ result.item.value }} | {{ result.packet_loss }} | 'N/A'
{% endif %}
{% endfor %}
{% endfor %}
path: ./ping_report.md
create: yes
run_once: yes