Skip to content

Instantly share code, notes, and snippets.

@johnsondnz
Last active July 25, 2017 23:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnsondnz/9814a6de37823c31452b1a2aba27fe9c to your computer and use it in GitHub Desktop.
Save johnsondnz/9814a6de37823c31452b1a2aba27fe9c to your computer and use it in GitHub Desktop.
Ansible Junos JSON variables
I am running ver 2.3
ubuntu@ansible-jsnapy:~$ ansible --version
ansible 2.3.1.0
config file =
configured module search path = Default w/o overrides
python version = 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]
I found this pull request which looks like it would resolve this issue.
https://github.com/ansible/ansible/pull/26382
Here is my task that produced the above output;
- name: Get version
junos_command:
commands: show version
display: xml
provider: "{{ netconf }}"
register: show_version
- debug: var=show_version
ok: [LAB-DEVICE] => {
"show_version": {
"changed": false,
"stdout": [
"<rpc-reply message-id=\"urn:uuid:3173c3a8-f33b-41ba-a4de-db7381e85d75\">\n<software-information>\n<host-name>LAB-DEVICE</host-name>\n<product-model>mx5-t</product-model>\n<product-name>mx5-t</product-name>\n<package-information>\n<name>junos</name>\n<comment>JUNOS Base OS boot [12.3R6.6]</comment>\n</package-information>\n<package-information>\n<name>jbase</name>\n<comment>JUNOS Base OS Software Suite [12.3R6.6]</comment>\n</package-information>\n<package-information>\n<name>jkernel</name>\n<comment>JUNOS Kernel Software Suite [12.3R6.6]</comment>\n</package-information>\n<package-information>\n<name>jcrypto</name>\n<comment>JUNOS Crypto Software Suite [12.3R6.6]</comment>\n</package-information>\n<package-information>\n<name>jpfe</name>\n<comment>JUNOS Packet Forwarding Engine Support (MX80) [12.3R6.6]</comment>\n</package-information>\n<package-information>\n<name>jdocs</name>\n<comment>JUNOS Online Documentation [12.3R6.6]</comment>\n</package-information>\n<package-information>\n<name>jroute</name>\n<comment>JUNOS Routing Software Suite [12.3R6.6]</comment>\n</package-information>\n<package-information>\n<name>jais</name>\n<comment>JUNOS AIS Script Suite [4.0R2.1]</comment>\n</package-information>\n</software-information>\n</rpc-reply>"
],
"stdout_lines": [
[
"<rpc-reply message-id=\"urn:uuid:3173c3a8-f33b-41ba-a4de-db7381e85d75\">",
"<software-information>",
"<host-name>LAB-DEVICE</host-name>",
"<product-model>mx5-t</product-model>",
"<product-name>mx5-t</product-name>",
"<package-information>",
"<name>junos</name>",
"<comment>JUNOS Base OS boot [12.3R6.6]</comment>",
"</package-information>",
"<package-information>",
"<name>jbase</name>",
"<comment>JUNOS Base OS Software Suite [12.3R6.6]</comment>",
"</package-information>",
"<package-information>",
"<name>jkernel</name>",
"<comment>JUNOS Kernel Software Suite [12.3R6.6]</comment>",
"</package-information>",
"<package-information>",
"<name>jcrypto</name>",
"<comment>JUNOS Crypto Software Suite [12.3R6.6]</comment>",
"</package-information>",
"<package-information>",
"<name>jpfe</name>",
"<comment>JUNOS Packet Forwarding Engine Support (MX80) [12.3R6.6]</comment>",
"</package-information>",
"<package-information>",
"<name>jdocs</name>",
"<comment>JUNOS Online Documentation [12.3R6.6]</comment>",
"</package-information>",
"<package-information>",
"<name>jroute</name>",
"<comment>JUNOS Routing Software Suite [12.3R6.6]</comment>",
"</package-information>",
"<package-information>",
"<name>jais</name>",
"<comment>JUNOS AIS Script Suite [4.0R2.1]</comment>",
"</package-information>",
"</software-information>",
"</rpc-reply>"
]
]
}
}
I repeated this with show arp and it has the same results (I can't post results here as the contents contains secure information -
our LAB emulates our operational network.)
I can confirm that unless you use "show arp | display xml" or use "display: xml" in the play the returned results are plain-text
or as you would get from the cli.
I then installed ansible dev branch and reran to see if pull request 26382 was implimented.
ubuntu@ansible-jsnapy:$ sudo pip install git+https://github.com/ansible/ansible.git@devel
ubuntu@ansible-jsnapy:~$ ansible --version
ansible 2.4.0
config file = None
configured module search path = [u'/home/ubuntu/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python2.7/dist-packages/ansible
executable location = /usr/local/bin/ansible
python version = 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]
The xml output shows not only xml in stdout but now also imcludes json. see below.
- name: Get version
junos_command:
commands: show version
display: xml
provider: "{{ netconf }}"
register: show_version
- debug: var=show_version
ok: [LAB-DEVICE] => {
"show_version": {
"changed": false,
"failed": false,
"output": [
{
"rpc-reply": {
"software-information": {
"host-name": "LAB-DEVICE",
"package-information": [
{
"comment": "JUNOS Base OS boot [12.3R6.6]",
"name": "junos"
},
{
"comment": "JUNOS Base OS Software Suite [12.3R6.6]",
"name": "jbase"
},
{
"comment": "JUNOS Kernel Software Suite [12.3R6.6]",
"name": "jkernel"
},
{
"comment": "JUNOS Crypto Software Suite [12.3R6.6]",
"name": "jcrypto"
},
{
"comment": "JUNOS Packet Forwarding Engine Support (MX80) [12.3R6.6]",
"name": "jpfe"
},
{
"comment": "JUNOS Online Documentation [12.3R6.6]",
"name": "jdocs"
},
{
"comment": "JUNOS Routing Software Suite [12.3R6.6]",
"name": "jroute"
},
{
"comment": "JUNOS AIS Script Suite [4.0R2.1]",
"name": "jais"
}
],
"product-model": "mx5-t",
"product-name": "mx5-t"
}
}
}
],
"stdout": [
"<rpc-reply message-id=\"urn:uuid:0a9dfcec-decf-47fd-870f-552e83e17cbe\">\n<software-information>\n<host-name>LAB-DEVICE</host-name>\n<product-model>mx5-t</product-model>\n<product-name>mx5-t</product-name>\n<package-information>\n<name>junos</name>\n<comment>JUNOS Base OS boot [12.3R6.6]</comment>\n</package-information>\n<package-information>\n<name>jbase</name>\n<comment>JUNOS Base OS Software Suite [12.3R6.6]</comment>\n</package-information>\n<package-information>\n<name>jkernel</name>\n<comment>JUNOS Kernel Software Suite [12.3R6.6]</comment>\n</package-information>\n<package-information>\n<name>jcrypto</name>\n<comment>JUNOS Crypto Software Suite [12.3R6.6]</comment>\n</package-information>\n<package-information>\n<name>jpfe</name>\n<comment>JUNOS Packet Forwarding Engine Support (MX80) [12.3R6.6]</comment>\n</package-information>\n<package-information>\n<name>jdocs</name>\n<comment>JUNOS Online Documentation [12.3R6.6]</comment>\n</package-information>\n<package-information>\n<name>jroute</name>\n<comment>JUNOS Routing Software Suite [12.3R6.6]</comment>\n</package-information>\n<package-information>\n<name>jais</name>\n<comment>JUNOS AIS Script Suite [4.0R2.1]</comment>\n</package-information>\n</software-information>\n</rpc-reply>"
],
"stdout_lines": [
[
"<rpc-reply message-id=\"urn:uuid:0a9dfcec-decf-47fd-870f-552e83e17cbe\">",
"<software-information>",
"<host-name>LAB-DEVICE</host-name>",
"<product-model>mx5-t</product-model>",
"<product-name>mx5-t</product-name>",
"<package-information>",
"<name>junos</name>",
"<comment>JUNOS Base OS boot [12.3R6.6]</comment>",
"</package-information>",
"<package-information>",
"<name>jbase</name>",
"<comment>JUNOS Base OS Software Suite [12.3R6.6]</comment>",
"</package-information>",
"<package-information>",
"<name>jkernel</name>",
"<comment>JUNOS Kernel Software Suite [12.3R6.6]</comment>",
"</package-information>",
"<package-information>",
"<name>jcrypto</name>",
"<comment>JUNOS Crypto Software Suite [12.3R6.6]</comment>",
"</package-information>",
"<package-information>",
"<name>jpfe</name>",
"<comment>JUNOS Packet Forwarding Engine Support (MX80) [12.3R6.6]</comment>",
"</package-information>",
"<package-information>",
"<name>jdocs</name>",
"<comment>JUNOS Online Documentation [12.3R6.6]</comment>",
"</package-information>",
"<package-information>",
"<name>jroute</name>",
"<comment>JUNOS Routing Software Suite [12.3R6.6]</comment>",
"</package-information>",
"<package-information>",
"<name>jais</name>",
"<comment>JUNOS AIS Script Suite [4.0R2.1]</comment>",
"</package-information>",
"</software-information>",
"</rpc-reply>"
]
]
}
}
results now contain xml to json transformation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment