Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

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





junos_get_facts
get facts
jlk@ubuntu:/etc/ansible/roles/ex3400$ more tasks/main.yml 
---
# tasks file for ex3400
# Enter those command into the JunOS box
#
#set system login user jansible class super-user
#set system login user jansible authentication plain-text-password
#
- name: Get facts Play
  hosts: EX4300 
  connection: local
  gather_facts: no
  roles:
    - Juniper.junos
  vars:
    ansible_python_interpreter: "/usr/bin/python"
  tasks:
    - name: Checking NETCONF connectivity Task
      wait_for: host={{ inventory_hostname }} port=830 timeout=5
    - name: Get junos facts Task
      junos_get_facts:
        host: "172.30.95.194"
        user: "jansible"
        passwd: "jansible123"
      register: junos
    - name: Print facts
      debug:
        var: junos










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

  • No labels