Skip to content

Health Checks

noashadmon edited this page Sep 6, 2017 · 4 revisions

Health Checks: junos_get_facts

IMAGE ALT TEXT HERE

This module retrieves the specific facts about the Junos device. There are multiple parameters that can be included in this task, however, the only parameter that is required is the host. The optional parameters are console, logfile, passwd, port, savedir, and user.

In the example below we only have one task called "Get junos facts." In order to get the host facts, the hostname, username, and password is all passed in and populates the Jinja template. We then save this in the variable junos (the register key word). Then we call junos which holds all of the facts. If successful, all of the facts will be outputted on the screen.

To print the facts of the specific junos device, enter the following line in the command line:

ansible-playbook -i all.inv facts.pb.yaml 

when -i reads the following inventory file (in this case all.inv) that specifies the host information and facts.pb.yaml is the yaml code below.

---
- name: Get facts
  hosts: junos-ssh
  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

The output of executing the command above is shown below:

PLAY [Get facts] ***************************************************************

TASK [Get junos facts] *********************************************************
ok: [core1]

TASK [Print facts] *************************************************************
ok: [core1] => {
    "junos": {
        "changed": false, 
        "facts": {
            "HOME": "/var/home/labadmin", 
            "RE0": {
                "last_reboot_reason": "0x1:power cycle/failure ", 
                "mastership_state": "master", 
                "model": "RE-S-1800x4", 
                "status": "OK", 
                "up_time": "20 days, 1 hour, 17 minutes, 54 seconds"
            }, 
            "RE1": {
                "last_reboot_reason": "0x1:power cycle/failure ", 
                "mastership_state": "backup", 
                "model": "RE-S-1800x4", 
                "status": "OK", 
                "up_time": "20 days, 1 hour, 18 minutes, 26 seconds"
            }, 
            "domain": "englab.juniper.net", 
            "fqdn": "R01-mx480-re0.englab.juniper.net", 
            "has_2RE": true, 
            "hostname": "R01-mx480-re0", 
            "ifd_style": "CLASSIC", 
            "master": "RE0", 
            "model": "MX480", 
            "personality": "MX", 
            "serialnumber": "JN11FF501AFB", 
            "switch_style": "BRIDGE_DOMAIN", 
            "vc_capable": false, 
            "version": "14.2R6.5", 
            "version_RE0": "14.2R6.5", 
            "version_RE1": "14.2R6.5", 
            "version_info": {
                "build": 5, 
                "major": [
                    14, 
                    2
                ], 
                "minor": "6", 
                "type": "R"
            }
        }
    }
}

PLAY RECAP *********************************************************************
core1                      : ok=2    changed=0    unreachable=0    failed=0   
Clone this wiki locally