https://github.com/Juniper/Intro-to-Using-Ansible-with-Junos-OS/wiki/Health-Checks
Junos Automation: Using Ansible to pull basic information from a network device
jlk@ubuntu:/etc/ansible$ more /etc/ansible/hosts
[vsrx]
vsrx1
[srx300]
192.168.0.2
jlk@ubuntu:/etc/ansible$ more /etc/hosts
127.0.0.1 localhost
127.0.1.1 ubuntu
192.168.101.27 vsrx1
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
jlk@ubuntu:/etc/ansible$ more /etc/ansible/hosts
[vsrx]
vsrx1
[srx300]
192.168.0.2
jlk@ubuntu:/etc/ansible$ more /etc/ansible/facts.pb.yaml
---
- name: Get facts
hosts: vsrx
connection: local
gather_facts: no
roles:
- Juniper.junos
vars_prompt:
- name: ADMUSER
prompt: Username
private: no
- name: ADMPASS
prompt: password
private: yes
tasks:
- name: Get junos facts
junos_get_facts:
host: "{{ inventory_hostname }}"
user: "{{ ADMUSER }}"
passwd: "{{ ADMPASS }}"
register: junos
- name: Print facts
debug:
var: junos
jlk@ubuntu:/etc/ansible$ sudo ansible-playbook -i hosts ./facts.pb.yaml --verbose
Using /etc/ansible/ansible.cfg as config file
Username: root
password:
PLAY [Get facts] *************************************************************************************************
TASK [Get junos facts] *******************************************************************************************
ok: [vsrx1] => {"ansible_facts": {"junos": {"HOME": "/root", "RE0": {"last_reboot_reason": "Router rebooted after a normal shutdown.", "mastership_state": "master", "model": "FIREFLY-PERIMETER RE", "status": "Testing", "up_time": "5 hours, 30 minutes, 2 seconds"}, "RE1": null, "RE_hw_mi": false, "current_re": ["master", "node", "fwdd", "member", "pfem", "backup", "re0", "fpc0.pic0"], "domain": null, "fqdn": "vsrxipsec", "has_2RE": false, "hostname": "vsrxipsec", "hostname_info": {"re0": "vsrxipsec"}, "ifd_style": "CLASSIC", "junos_info": {"re0": {"object": {"build": 7, "major": [12, 1], "minor": [47, "D", 2