...
jlk@ubuntu:/etc/ansible$ more /etc/ansible/hosts
[vsrx]
vsrx1
[srx300]
192.168.0.2
jlk@ubuntu[EX4300]
172.30.95.194
new Module | https:/ |
---|
...
# 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 | ||||||||||
Code Block | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
title | get facts | /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
| |||||||||
junos_get_facts | ansible-playbook pl_get_facts_new.yml -i hosts hosts is in the same directory
Code Block | | ||||||||
|
"{{ inventory_hostname }}"
user: "Netbox"
passwd: "Netbox"
register: junos
- name: Print facts
debug:
var: junos
OLD version:
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
|
Code Block | ||||
---|---|---|---|---|
| ||||
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] ************************************************************************************************************* 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 "up_timeshutdown.", "mastership_state": "31 daysmaster", 4 hours, 18 minutes, 40 seconds" }, "RE1"model": "EX4300-48T", "status": "OK"}}}, "re_master": {"default": "0"}, "re_name": "fpc0", "serialnumber": "PE3717290399", "srx_cluster": null, "RE_hw_mi"srx_cluster_id": falsenull, "current_re"srx_cluster_redundancy_group": [ "master", "node", "fwdd", "member", "pfem", "re0", "fpc0", "localre" ],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": { "domainHOME": null"/var/home/jansible", "fqdnRE0": "EX4300-R103-34",{ "haslast_reboot_2REreason": false,"Router rebooted after a normal shutdown.", "hostname": "EX4300-R103-34", "hostnamemastership_infostate": {"master", "fpc0model": "EX4300-R103-3448T", }, "ifd_style"status": "SWITCHOK", "junosup_infotime": {"31 days, 4 hours, 18 minutes, 40 seconds" "fpc0": { }, "objectRE1": {null, "RE_hw_mi": false, "buildcurrent_re": 8,[ "master", "major": [ "node", "fwdd", 18, "member", "pfem", 4 "re0", ]"fpc0", "localre" "minor": "1" ], "domain": null, "typefqdn": "REX4300-R103-34", }"has_2RE": false, "hostname": "EX4300-R103-34", "text "hostname_info": "18.4R1.8"{ }"fpc0": "EX4300-R103-34" }, "masterifd_style": "RE0SWITCH", "masterjunos_stateinfo": true,{ "modelfpc0": "EX4300-48T",{ "model_infoobject": { "fpc0": "EX4300-48T" "build": 8, }, "personalitymajor": "SWITCH", [ "re_info": { 18, "default": { "0": { 4 "last_reboot_reason": "Router rebooted after a normal shutdown."], "mastership_stateminor": "master1", "modeltype": "EX4300-48TR", }, "status": "OK" "text": "18.4R1.8" }, } "default": {}, "master": "RE0", "lastmaster_reboot_reasonstate": "Router rebooted after a normal shutdown."true, "model": "EX4300-48T", "mastershipmodel_stateinfo": "master", { "modelfpc0": "EX4300-48T", }, "statuspersonality": "OKSWITCH", "re_info": { } "default": { } }, "0": { "re_master": { "defaultlast_reboot_reason": "0"Router rebooted after a normal shutdown.", }, "re_name": "fpc0", "serialnumber"mastership_state": "PE3717290399master", "srx_cluster": null, "srx_cluster_idmodel": null"EX4300-48T", "srx_cluster_redundancy_group": null, "switch_stylestatus": "VLAN_L2NGOK", "vc_capable": true, }, "vc_fabric": false, "vc_masterdefault": "0",{ "vc_mode": "Enabled", "versionlast_reboot_reason": "18.4R1.8Router rebooted after a normal shutdown.", "version_RE0": null, "versionmastership_RE1state": null"master", "version_info": { "buildmodel": 8"EX4300-48T", "major": [ "status": "OK" 18, } 4 } ]}, "minor"re_master": "1",{ "typedefault": "R0" }, "virtualre_name": false"fpc0", } } PLAY RECAP ****************************************************************************************************************************** 172.30.95.194 : ok=3 changed=0 unreachable=0 failed=0 "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 } } PLAY RECAP ****************************************************************************************************************************** 172.30.95.194 : ok=3 changed=0 unreachable=0 failed=0 |
!!!!! Host, username and password will be predicated in 2.9 !!!!
Code Block | ||||
---|---|---|---|---|
| ||||
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: 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
...