Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

[srx300]
192.168.0.2

[EX4300]
172.30.95.194



jlk@ubuntu:/etc/ansible/roles/ex3400$ ansible-playbook tasks/main.yml --verbose Using /etc/ansible/ansible.cfg as config file PLAY [Get facts Play] ******************************************************************************************************************* TASK [Checking NETCONF connectivity Task] *********************************************************************************************** ok: [172.30.95.194] => {"changed": false, "elapsed": 0, "path": null, "port": 830, "search_regex": null, "state": "started"} TASK [Get junos facts Task] ****************************************
new Modulehttps://junos-ansible-modules.readthedocs.io/en/2.3.0/
ssh jansible@172.30.95.194 -p 830 -s netconf
# Add jansible user on he juniper Node
set system login user jansible class super-user
set system login user jansible authentication plain-text-password
# enable NETCONFIG
set system services netconf ssh
Code Block
titletest RPC / NETCONFIG
collapsetrue
jlk@ubuntu:/etc/ansible/roles$ ssh jansible@172.30.95.194 -p 830 -s netconf
Password:
<!-- No zombies were killed during the creation of this user interface -->
<!-- user jansible, class j-super-user -->
<hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
  <capabilities>
    <capability>urn:ietf:params:netconf:base:1.0</capability>
    <capability>urn:ietf:params:netconf:capability:candidate:1.0</capability>
    <capability>urn:ietf:params:netconf:capability:confirmed-commit:1.0</capability>
    <capability>urn:ietf:params:netconf:capability:validate:1.0</capability>
    <capability>urn:ietf:params:netconf:capability:url:1.0?scheme=http,ftp,file</capability>
    <capability>urn:ietf:params:xml:ns:netconf:base:1.0</capability>
    <capability>urn:ietf:params:xml:ns:netconf:capability:candidate:1.0</capability>
    <capability>urn:ietf:params:xml:ns:netconf:capability:confirmed-commit:1.0</capability>
    <capability>urn:ietf:params:xml:ns:netconf:capability:validate:1.0</capability>
    <capability>urn:ietf:params:xml:ns:netconf:capability:url:1.0?protocol=http,ftp,file</capability>
    <capability>urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring</capability>
    <capability>http://xml.juniper.net/netconf/junos/1.0</capability>
    <capability>http://xml.juniper.net/dmi/system/1.0</capability>
  </capabilities>
  <session-id>41417</session-id>
</hello>
]]>]]>


junos_get_facts

ansible-playbook pl_get_facts_new.yml -i hosts


hosts is in the same directory


Code Block
titleget facts
collapsetrue
jlk@ubuntu:/etc/ansible/roles/ex3400$ more tasks/main.yml 
New Version:

---
#- tasksname: 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
#Get facts
  hosts: All-srx
  connection: local
  gather_facts: no
  roles:
    - Juniper.junos

  tasks:
    - name: Get junos facts
Play   hosts: EX4300  juniper_junos_facts:
 connection: local   gather_facts: no   roleshost: "{{ inventory_hostname }}"
 - Juniper.junos   vars:     ansible_python_interpreteruser: "/usr/bin/pythonNetbox"
  tasks:     - namepasswd: Checking"Netbox"
NETCONF connectivity Task    register: junos
 wait_for: host={{ inventory_hostname }} port=830 timeout=5
- name: Print facts
   - name: Get junosdebug:
facts Task       junos_get_factsvar: junos



OLD version:

 host: "172.30.95.194"
        user: "jansible"
        passwd: "jansible123"
      register: junos
    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: PrintGet facts Play
  hosts: EX4300 
  debugconnection: local
  gather_facts: no
  roles:
var:  junos  
ansible-playbook tasks/main.yml --verbose
Code Block
titleansible-playbook tasks/main.yml --verbose
collapsetrue
- 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


ansible-playbook tasks/main.yml --verbose


Code Block
titleansible-playbook tasks/main.yml --verbose
collapsetrue
jlk@ubuntu:/etc/ansible/roles/ex3400$ ansible-playbook tasks/main.yml --verbose
Using /etc/ansible/ansible.cfg as config file

PLAY [Get facts Play] ***********************************************************************************
ok: [172.30.95.194] => {"ansible_facts": {"junos": {"HOME": "/var/home/jansible", "RE0": {"last_reboot_reason": "Router rebooted after a normal shutdown.", "mastership_state": "master", "model": "EX4300-48T", "status": "OK", "up_time": "31 days, 4 hours, 18 minutes, 40 seconds"}, "RE1": null, "RE_hw_mi": false, "current_re": ["master", "node", "fwdd", "member", "pfem", "re0", "fpc0", "localre"], "domain": null, "fqdn": "EX4300-R103-34", "has_2RE": false, "hostname": "EX4300-R103-34", "hostname_info": {"fpc0": "EX4300-R103-34"}, "ifd_style": "SWITCH", "junos_info": {"fpc0": {"object": {"build": 8, "major": [18, 4], "minor": "1", "type": "R"}, "text": "18.4R1.8"}}, "master": "RE0", "master_state": true, "model": "EX4300-48T", "model_info": {"fpc0": "EX4300-48T"}, "personality": "SWITCH", "re_info": {"default": {"0": {"last_reboot_reason": "Router rebooted after a normal shutdown.", "mastership_state": "master", "model": "EX4300-48T", "status": "OK"}, "default": {"last_reboot_reason": "Router rebooted after a normal shutdown.", "mastership_state": "master", "model": "EX4300-48T", "status": "OK"}}}, "re_master": {"default": "0"}, "re_name": "fpc0", "serialnumber": "PE3717290399", "srx_cluster": null, "srx_cluster_id": null, "srx_cluster_redundancy_group": null, "switch_style": "VLAN_L2NG", "vc_capable": true, "vc_fabric": false, "vc_master": "0", "vc_mode": "Enabled", "version": "18.4R1.8", "version_RE0": null, "version_RE1": null, "version_info": {"build": 8, "major": [18, 4], "minor": "1", "type": "R"}, "virtual": false}}, "changed": false, "facts": {"HOME": "/var/home/jansible", "RE0": {"last_reboot_reason": "Router rebooted after a normal shutdown.", "mastership_state": "master", "model": "EX4300-48T", "status": "OK", "up_time": "31 days, 4 hours, 18 minutes, 40 seconds"}, "RE1": null, "RE_hw_mi": false, "current_re": ["master", "node", "fwdd", "member", "pfem", "re0", "fpc0", "localre"], "domain": null, "fqdn": "EX4300-R103-34", "has_2RE": false, "hostname": "EX4300-R103-34", "hostname_info": {"fpc0": "EX4300-R103-34"}, "ifd_style": "SWITCH", "junos_info": {"fpc0": {"object": {"build": 8, "major": [18, 4], "minor": "1", "type": "R"}, "text": "18.4R1.8"}}, "master": "RE0", "master_state": true, "model": "EX4300-48T", "model_info": {"fpc0": "EX4300-48T"}, "personality": "SWITCH", "re_info": {"default": {"0": {"last_reboot_reason": "Router rebooted after a normal shutdown.", "mastership_state": "master", "model": "EX4300-48T", "status": "OK"}, "default": {"last_reboot_reason": "Router rebooted after a normal shutdown.", "mastership_state": "master", "model": "EX4300-48T", "status": "OK"}}}, "re_master": {"default": "0"}, "re_name": "fpc0", "serialnumber": "PE3717290399", "srx_cluster": null, "srx_cluster_id": null, "srx_cluster_redundancy_group": null, "switch_style": "VLAN_L2NG", "vc_capable": true, "vc_fabric": false, "vc_master": "0", "vc_mode": "Enabled", "version": "18.4R1.8", "version_RE0": null, "version_RE1": null, "version_info": {"build": 8, "major": [18, 4], "minor": "1", "type": "R"}, "virtual": false}}

TASK [Print facts] **********************************************************************************************************************
ok: [172.30.95.194] => {
    "junos": {
        "HOME": "/var/home/jansible", 
        "RE0": {
            "last_reboot_reason": "Router rebooted after a normal shutdown.", 
            "mastership_state": "master", 
            "model": "EX4300-48T", 
            "status": "OK", 
            "up_time": "31 days, 4 hours, 18 minutes, 40 seconds"
        },********************************

TASK [Checking NETCONF connectivity Task] ***********************************************************************************************
ok: [172.30.95.194] => {"changed": false, "elapsed": 0, "path": null, "port": 830, "search_regex": null, "state": "started"}

TASK [Get junos facts Task] *************************************************************************************************************
ok: [172.30.95.194] => {"ansible_facts": {"junos": {"HOME": "/var/home/jansible", "RE0": {"last_reboot_reason": "Router rebooted after a normal shutdown.", "mastership_state": "master", "model": "EX4300-48T", "status": "OK", "up_time": "31 days, 4 hours, 18 minutes, 40 seconds"}, "RE1": null, "RE_hw_mi": false, "current_re": ["master", "node", "fwdd", "member", "pfem", "re0", "fpc0", "localre"], "domain": null, "fqdn": "EX4300-R103-34", "has_2RE": false, "hostname": "EX4300-R103-34", "hostname_info": {"fpc0": "EX4300-R103-34"}, "ifd_style": "SWITCH", "junos_info": {"fpc0": {"object": {"build": 8, "major": [18, 4], "minor": "1", "type": "R"}, "text": "18.4R1.8"}}, "master": "RE0", "master_state": true, "model": "EX4300-48T", "model_info": {"fpc0": "EX4300-48T"}, "personality": "SWITCH", "re_info": {"default": {"0": {"last_reboot_reason": "Router rebooted after a normal shutdown.", "mastership_state": "master", "model": "EX4300-48T", "status": "OK"}, "default": {"last_reboot_reason": "Router rebooted after a normal shutdown.", "mastership_state": "master", "model": "EX4300-48T", "status": "OK"}}}, "re_master": {"default": "0"}, "re_name": "fpc0", "serialnumber": "PE3717290399", "srx_cluster": null, "srx_cluster_id": null, "srx_cluster_redundancy_group": null, "switch_style": "VLAN_L2NG", "vc_capable": true, "vc_fabric": false, "vc_master": "0", "vc_mode": "Enabled", "version": "18.4R1.8", "version_RE0": null, "version_RE1": null, "version_info": {"build": 8, "major": [18, 4], "minor": "1", "type": "R"}, "virtual": false}}, "changed": false, "facts": {"HOME": "/var/home/jansible", "RE0": {"last_reboot_reason": "Router rebooted after a normal shutdown.", "mastership_state": "master", "model": "EX4300-48T", "status": "OK", "up_time": "31 days, 4 hours, 18 minutes, 40 seconds"}, "RE1": null, "RE_hw_mi": false, "current_re": ["master", "node", "fwdd", "member", "pfem", "re0", "fpc0", "localre"], "domain": null, "fqdn": "EX4300-R103-34", "has_2RE": false, "hostname": "EX4300-R103-34", "hostname_info": {"fpc0": "EX4300-R103-34"}, "ifd_style": "SWITCH", "junos_info": {"fpc0": {"object": {"build": 8, "major": [18, 4], "minor": "1", "type": "R"}, "text": "18.4R1.8"}}, "master": "RE0", "master_state": true, "model": "EX4300-48T", "model_info": {"fpc0": "EX4300-48T"}, "personality": "SWITCH", "re_info": {"default": {"0": {"last_reboot_reason": "Router rebooted after a normal shutdown.", "mastership_state": "master", "model": "EX4300-48T", "status": "OK"}, "default": {"last_reboot_reason": "Router rebooted after a normal shutdown.", "mastership_state": "master", "model": "EX4300-48T", "status": "OK"}}}, "re_master": {"default": "0"}, "re_name": "fpc0", "serialnumber": "PE3717290399", "srx_cluster": null, "srx_cluster_id": null, "srx_cluster_redundancy_group": null, "switch_style": "VLAN_L2NG", "vc_capable": true, "vc_fabric": false, "vc_master": "0", "vc_mode": "Enabled", "version": "18.4R1.8", "version_RE0": null, "version_RE1": null, "version_info": {"build": 8, "major": [18, 4], "minor": "1", "type": "R"}, "virtual": false}}

TASK [Print facts] **********************************************************************************************************************
ok: [172.30.95.194] => {
    "junos": {
        "HOME": "/var/home/jansible", 
        "RE0": {
            "RE1last_reboot_reason": null,"Router rebooted after a normal shutdown.", 
   "RE_hw_mi": false,          "currentmastership_restate": "master", [
            "mastermodel": "EX4300-48T", 
            "nodestatus": "OK", 
            "fwdd"up_time": "31 days, 4 hours, 18 minutes, 40 seconds"
        "member"}, 
        "RE1": null, 
     "pfem",   "RE_hw_mi": false, 
        "re0current_re",: [
            "fpc0master", 
            "localrenode", 
       ],     "fwdd", 
    "domain": null,       "member", 
 "fqdn": "EX4300-R103-34",          "has_2RE": false,pfem", 
           "hostname": "EX4300-R103-34re0", 
         "hostname_info": {   "fpc0", 
            "fpc0": "EX4300-R103-34localre"
        }], 
        "ifd_styledomain": "SWITCH"null, 
        "junos_infofqdn": {"EX4300-R103-34", 
        "has_2RE": false, 
"fpc0":  {      "hostname": "EX4300-R103-34", 
        "objecthostname_info": {
            "fpc0": "EX4300-R103-34"
       "build": 8}, 
        "ifd_style": "SWITCH", 
         "majorjunos_info": [{
            "fpc0": {
          18,      "object": {
                  4  "build": 8, 
                ],    "major": [
                "minor": "1",       18, 
             "type": "R"           4
     },               ], 
 "text": "18.4R1.8"             }     "minor": "1", 
 },          "master": "RE0",        "type":  "master_stateR":
true,          "model": "EX4300-48T",      }, 
  "model_info": {             "fpc0text": "EX4300-48T"18.4R1.8"
          },  }
       "personality": "SWITCH" }, 
        "re_infomaster": {"RE0", 
           "default"master_state": {true, 
          "model": "EX4300-48T", 
   "0": {    "model_info": {
               "last_reboot_reason"fpc0": "Router rebooted after a normal shutdown.",EX4300-48T"
        }, 
           "mastership_state"personality": "masterSWITCH", 
        "re_info": {
            "modeldefault": "EX4300-48T",{
                     "status": "OK"
                }, 
                "default""0": {
                    "last_reboot_reason": "Router rebooted after a normal shutdown.", 
                    "mastership_state": "master", 
                    "model": "EX4300-48T", 
                    "status": "OK"
                }, 
           }     "default": {
  },          "re_master": {             "default"last_reboot_reason": "0"Router rebooted after a normal shutdown.", 
         },           "remastership_namestate": "fpc0master", 
        "serialnumber": "PE3717290399",            "srx_clustermodel": null"EX4300-48T", 
        "srx_cluster_id": null,            "srx_cluster_redundancy_groupstatus": null,"OK"
           "switch_style": "VLAN_L2NG",     }
         "vc_capable": true,  }
       "vc_fabric": false }, 
        "vcre_master": "0", {
            "vc_modedefault": "Enabled"0"
        }, 
        "versionre_name": "18.4R1.8fpc0", 
        "version_RE0serialnumber": null"PE3717290399", 
        "versionsrx_RE1cluster": null, 
        "versionsrx_cluster_infoid": {null, 
           "build"srx_cluster_redundancy_group": 8null, 
            "major"switch_style": ["VLAN_L2NG", 
        "vc_capable": true, 
    18,    "vc_fabric": false, 
        "vc_master": "0", 
4        "vc_mode": "Enabled", 
    ],    "version": "18.4R1.8", 
        "minorversion_RE0": "1"null, 
        "version_RE1": null, 
        "typeversion_info": "R"{
            "build": }8, 
            "virtualmajor": false[
     } }  PLAY RECAP *************************************************************************       18, 
                4
            ], 
            "minor": "1", 
            "type": "R"
        }, 
        "virtual": false
    }
}

PLAY RECAP *******************************************************************
172.30.95.194*****************************************************************************
172.30.95.194              : ok=3    changed=0    unreachable=0    failed=0


junos_facts ( ansible module)

!!!!! Host, username and password will be predicated in 2.9 !!!! 

Code Block
titlejunos_facts ansible module
collapsetrue
jlk@jkriker-T460:~$ more /etc/ansible/ex3400/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: EX3400
  connection: local
  gather_facts: no
  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_facts:
        host : "{{ inventory_hostname }}"
        username: "jansible"
        password: "jansible123"
      register: junos
    - name: ok=3 Print facts
      debug:
 changed=0    unreachable=0   var: failed=0junos







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

...