Junos Automation (Scripting)
Highlighted
Junos Automation (Scripting)

How to get output "request support info" using ansible?

‎03-14-2018 09:01 AM

Hi all,

 

 

Is it possible to get the output for using ansible for command "request support info". I'm try to do it but not get the ouput "request support info". If just one by one command as per below url then there is no issue.

 

https://www.juniper.net/documentation/en_US/junos-ansible/topics/topic-map/junos-ansible-commands-rp...

 

Appreciate any help.

11 REPLIES 11
Highlighted
Junos Automation (Scripting)

Re: How to get output "request support info" using ansible?

‎03-14-2018 10:47 AM

Hi Kronic,

 

Check below helps your reuirement

 

---
- name: juniper_junos_command - Get RSI
hosts: all
connection: local
gather_facts: no
roles:
- Juniper.junos

vars_prompt:
- name: USER
prompt: Username
private: no
- name: PWD
prompt: Password
private: yes

tasks:
- name: CHECKING NETCONF CONNECTIVITY
wait_for: host={{ inventory_hostname }} port=830 timeout=5

- name: Request Support Information
juniper_junos_command:
commands: "request support information"
return_output: true
format: text
dest_dir: "./outputs/"
provider:
host: "{{ inventory_hostname }}"
user: "{{ USER }}"
passwd: "{{ PWD }}"
port: 830
timeout: 600
register: response

- name: Print the command output
debug:
var: response.stdout_lines

 

Hope this helps
--------------------------------------------------------------------------------------------------------
If this post was helpful, please mark this post as an "Accepted Solution".
Kudos are always appreciated!
--------------------------------------------------------------------------------------------------------

Highlighted
Junos Automation (Scripting)

Re: How to get output "request support info" using ansible?

‎03-15-2018 07:51 PM

Hi vvadivel,

 

 

It's look like the script that u give is not work. I get the error during run the script. May i know whether u already test in your lab.

 

 

Thanks

Highlighted
Junos Automation (Scripting)

Re: How to get output "request support info" using ansible?

‎03-17-2018 01:44 AM

Could you please try below, this worked in my lab:

 

---
- name: RSI from the device
hosts:
- all
roles:
- Juniper.junos
connection: local
gather_facts: no

vars_prompt:
- name: username
prompt: Junos Username
private: no

- name: password
prompt: Junos Password
private: yes

tasks:
- name: get RSI from the Device
junos_rpc:
rpc: get-support-information
format: text
dest: "{{ inventory_hostname }}-RSI.txt"
host: "{{ ansible_host }}"
port: 830
username: "{{ username }}"
password: "{{ password }}"

*********************************************

 

 

 

root@Automation:/home/vishruth/vish# ansible-playbook RSI-Save.yaml
Junos Username: root
Junos Password:

PLAY [RSI from the device] ***********************************************************************************************************************************************************

TASK [get RSI from the Device] *******************************************************************************************************************************************************
ok: [MX960]

PLAY RECAP ***************************************************************************************************************************************************************************
MX960 : ok=1 changed=0 unreachable=0 failed=0

root@Automation:/home/vishruth/vish#

-
VR
# Please mark my solution as accepted if it helped, Kudos are appreciated as well.
Highlighted
Junos Automation (Scripting)

Re: How to get output "request support info" using ansible?

‎03-18-2018 09:40 AM

Hi vishruth,

 

I do some change based on your config but I'm get error as per below. Not sure what wrong on my script compare to your script.

 

---
- name: juniper_junos_command - Get RSI
  hosts: all
  connection: local
  gather_facts: no
  roles:
    - Juniper.junos

  tasks:
    - name: Request Support Information
      juniper_junos_rpc:
        rpc: get-support-information
        format: text
        dest: "{{ inventory_hostname }}-RSI.txt"
        timeout: 600
      register: response

 

test@test-TS:~$ sudo ansible-playbook RSI.yml

PLAY [juniper_junos_command - Get RSI] *****************************************

TASK [Request Support Information] *********************************************
fatal: [11.11.11.171]: FAILED! => {"changed": false, "module_stderr": "/usr/local/lib/python2.7/dist-packages/jnpr/junos/device.py:794: RuntimeWarning: An unknown exception occured - please report.\n  RuntimeWarning)\nTraceback (most recent call last):\n  File \"/tmp/ansible_Lwndvm/ansible_module_juniper_junos_rpc.py\", line 662, in <module>\n    main()\n  File \"/tmp/ansible_Lwndvm/ansible_module_juniper_junos_rpc.py\", line 583, in main\n    normalize=bool(format == 'xml'))\n  File \"/usr/local/lib/python2.7/dist-packages/jnpr/junos/rpcmeta.py\", line 368, in __call__\n    return self._junos.execute(rpc_cmd, **kvargs)\n  File \"/usr/local/lib/python2.7/dist-packages/jnpr/junos/decorators.py\", line 71, in wrapper\n    return function(*args, **kwargs)\n  File \"/usr/local/lib/python2.7/dist-packages/jnpr/junos/decorators.py\", line 31, in wrapper\n    return function(*args, **kwargs)\n  File \"/usr/local/lib/python2.7/dist-packages/jnpr/junos/device.py\", line 770, in execute\n    ignore_warning=ignore_warning)\n  File \"/usr/local/lib/python2.7/dist-packages/jnpr/junos/decorators.py\", line 116, in wrapper\n    rsp = function(self, *args, **kwargs)\n  File \"/usr/local/lib/python2.7/dist-packages/jnpr/junos/device.py\", line 1321, in _rpc_reply\n    return self._conn.rpc(rpc_cmd_e)._NCElement__doc\n  File \"/usr/local/lib/python2.7/dist-packages/ncclient/manager.py\", line 172, in wrapper\n    return self.execute(op_cls, *args, **kwds)\n  File \"/usr/local/lib/python2.7/dist-packages/ncclient/manager.py\", line 232, in execute\n    raise_mode=self._raise_mode).request(*args, **kwds)\n  File \"/usr/local/lib/python2.7/dist-packages/ncclient/operations/third_party/juniper/rpc.py\", line 44, in request\n    return self._request(rpc)\n  File \"/usr/local/lib/python2.7/dist-packages/ncclient/operations/rpc.py\", line 326, in _request\n    raise self._error\nUnicodeDecodeError: 'utf8' codec can't decode byte 0xfc in position 1410: invalid start byte\n", "module_stdout": "", "msg": "MODULE FAILURE", "rc": 0}
fatal: [11.11.11.170]: FAILED! => {"changed": false, "module_stderr": "/usr/local/lib/python2.7/dist-packages/jnpr/junos/device.py:794: RuntimeWarning: An unknown exception occured - please report.\n  RuntimeWarning)\nTraceback (most recent call last):\n  File \"/tmp/ansible_hnlYW0/ansible_module_juniper_junos_rpc.py\", line 662, in <module>\n    main()\n  File \"/tmp/ansible_hnlYW0/ansible_module_juniper_junos_rpc.py\", line 583, in main\n    normalize=bool(format == 'xml'))\n  File \"/usr/local/lib/python2.7/dist-packages/jnpr/junos/rpcmeta.py\", line 368, in __call__\n    return self._junos.execute(rpc_cmd, **kvargs)\n  File \"/usr/local/lib/python2.7/dist-packages/jnpr/junos/decorators.py\", line 71, in wrapper\n    return function(*args, **kwargs)\n  File \"/usr/local/lib/python2.7/dist-packages/jnpr/junos/decorators.py\", line 31, in wrapper\n    return function(*args, **kwargs)\n  File \"/usr/local/lib/python2.7/dist-packages/jnpr/junos/device.py\", line 770, in execute\n    ignore_warning=ignore_warning)\n  File \"/usr/local/lib/python2.7/dist-packages/jnpr/junos/decorators.py\", line 116, in wrapper\n    rsp = function(self, *args, **kwargs)\n  File \"/usr/local/lib/python2.7/dist-packages/jnpr/junos/device.py\", line 1321, in _rpc_reply\n    return self._conn.rpc(rpc_cmd_e)._NCElement__doc\n  File \"/usr/local/lib/python2.7/dist-packages/ncclient/manager.py\", line 172, in wrapper\n    return self.execute(op_cls, *args, **kwds)\n  File \"/usr/local/lib/python2.7/dist-packages/ncclient/manager.py\", line 232, in execute\n    raise_mode=self._raise_mode).request(*args, **kwds)\n  File \"/usr/local/lib/python2.7/dist-packages/ncclient/operations/third_party/juniper/rpc.py\", line 44, in request\n    return self._request(rpc)\n  File \"/usr/local/lib/python2.7/dist-packages/ncclient/operations/rpc.py\", line 326, in _request\n    raise self._error\nUnicodeDecodeError: 'utf8' codec can't decode byte 0xfc in position 2069: invalid start byte\n", "module_stdout": "", "msg": "MODULE FAILURE", "rc": 0}
        to retry, use: --limit @/home/cvg/RSI.retry

Highlighted
Junos Automation (Scripting)

Re: How to get output "request support info" using ansible?

‎03-19-2018 12:04 AM

Can you try with my script and let me know if any error noticed?

-
VR
# Please mark my solution as accepted if it helped, Kudos are appreciated as well.
Highlighted
Junos Automation (Scripting)

Re: How to get output "request support info" using ansible?

‎03-21-2018 05:25 PM

Hi Vishru,

 

Using your script i the output just can get one only. For example in the "request support information" we can get multiple ouput but in this case it just have output for show version only. I'm testing with vSRX. Coould u check your ouput whether it have complete output from "request support info"

 

Thanks

 

 

Highlighted
Junos Automation (Scripting)

Re: How to get output "request support info" using ansible?

‎03-21-2018 10:18 PM

Hi kornicklez,

 

Yes in my case i am able to capture complete RSI.

 

-rw-r--r-- 1 root root  2857993 Mar 22 10:21 MX960-RSI.txt <<<< File size...

 

root@Automation:/home/vishruth/vish# head -n 50 MX960-RSI.txt


Current time: 2018-03-21 11:10:20 UTC
Time Source: LOCAL CLOCK
System booted: 2018-03-07 14:51:45 UTC (1w6d 20:18 ago)
Protocols started: 2018-03-07 14:52:43 UTC (1w6d 20:17 ago)
Last configured: 2018-03-20 14:21:39 UTC (20:48:41 ago) by root
11:10AM up 13 days, 20:19, 1 users, load averages: 0.29, 0.29, 0.25


root@MX-960-RE0> show version detail no-forwarding

Hostname: MX-960-RE0
Model: mx960
Junos: 15.1R5-S3.4
JUNOS OS Kernel 64-bit [20160927.337663_builder_stable_10]
JUNOS OS libs [20160927.337663_builder_stable_10]
JUNOS OS runtime [20160927.337663_builder_stable_10]
JUNOS OS time zone information [20160927.337663_builder_stable_10]
JUNOS OS libs compat32 [20160927.337663_builder_stable_10]
JUNOS OS 32-bit compatibility [20160927.337663_builder_stable_10]
JUNOS py base [20170406.144034_builder_junos_151_r5_s3]
JUNOS OS crypto [20160927.337663_builder_stable_10]
JUNOS network stack and utilities [20170406.144034_builder_junos_151_r5_s3]
JUNOS libs compat32 [20170406.144034_builder_junos_151_r5_s3]
JUNOS runtime [20170406.144034_builder_junos_151_r5_s3]
JUNOS platform support [20170406.144034_builder_junos_151_r5_s3]
JUNOS modules [20170406.144034_builder_junos_151_r5_s3]
JUNOS libs [20170406.144034_builder_junos_151_r5_s3]
JUNOS mtx Data Plane Crypto Support [20170406.144034_builder_junos_151_r5_s3]
JUNOS daemons [20170406.144034_builder_junos_151_r5_s3]
JUNOS Voice Services Container package [20170406.144034_builder_junos_151_r5_s3]
JUNOS Services SSL [20170406.144034_builder_junos_151_r5_s3]
JUNOS Services Stateful Firewall [20170406.144034_builder_junos_151_r5_s3]
JUNOS Services RPM [20170406.144034_builder_junos_151_r5_s3]
JUNOS Services PTSP Container package [20170406.144034_builder_junos_151_r5_s3]
JUNOS Services NAT [20170406.144034_builder_junos_151_r5_s3]
JUNOS Services Mobile Subscriber Service Container package [20170406.144034_builder_junos_151_r5_s3]
JUNOS Services MobileNext Software package [20170406.144034_builder_junos_151_r5_s3]
JUNOS Services LL-PDF Container package [20170406.144034_builder_junos_151_r5_s3]
JUNOS Services Jflow Container package [20170406.144034_builder_junos_151_r5_s3]
JUNOS Services IPSec [20170406.144034_builder_junos_151_r5_s3]
JUNOS IDP Services [20170406.144034_builder_junos_151_r5_s3]
JUNOS Services HTTP Content Management package [20170406.144034_builder_junos_151_r5_s3]
JUNOS Services Crypto [20170406.144034_builder_junos_151_r5_s3]
JUNOS Services Captive Portal and Content Delivery Container package [20170406.144034_builder_junos_151_r5_s3]
JUNOS Services COS [20170406.144034_builder_junos_151_r5_s3]
JUNOS Border Gateway Function package [20170406.144034_builder_junos_151_r5_s3]
JUNOS AppId Services [20170406.144034_builder_junos_151_r5_s3]
JUNOS Services Application Level Gateways [20170406.144034_builder_junos_151_r5_s3]
root@Automation:/home/vishruth/vish#

-
VR
# Please mark my solution as accepted if it helped, Kudos are appreciated as well.
Highlighted
Junos Automation (Scripting)

Re: How to get output "request support info" using ansible?

‎03-26-2018 02:46 AM

Hi Vishru,

 

May i know what version of ansible that u used? I'm using ver 2.0.2 and it have error when using your script and i tune it using my config below but have an error also. Can u test using my script on your ansible whether it work or not?

 

---
- name: Examples of juniper_junos_command
  hosts: vSRX
  connection: local
  gather_facts: no
  roles:
    - Juniper.junos


  tasks:
    - name: get RSI from the Device
      juniper_junos_rpc:
        rpcs: "get-software-information"
        format: "text"
        dest: "{{ inventory_hostname }}-RSI.txt"

 

 

Thanks

Highlighted
Junos Automation (Scripting)

Re: How to get output "request support info" using ansible?

‎03-26-2018 02:47 AM

Hi Vishru,

 

This working for get-software-information but not work on get-support-information.

 

 

Thanks and appreciate your feedback.

Highlighted
Junos Automation (Scripting)

Re: How to get output "request support info" using ansible?

‎03-28-2018 08:15 AM

Hi vishruth,

 

 

Appreciate your help regarding this.

 

Thanks

Highlighted
Junos Automation (Scripting)

Re: How to get output "request support info" using ansible?

‎06-30-2018 10:58 AM

Hi Folks,

Day One: Automating Junos® with Ansible is a book worth to read…

 

https://www.juniper.net/us/en/training/jnbooks/day-one/automation-series/automating-junos-ansible/

 

-Python JNCIE 3X [SP|DC|ENT] JNCIP-SEC JNCDS 3X [ WAN | DC|SEC] JNCIS-Cloud JNCIS-DevOps CCIP ITIL
#Please mark my solution as accepted if it helped, Kudos are appreciated as well.