Hello all...
I'm new to using ansible in our Juniper environment and have begun chipping away. At this point, I'm just looking to simply filter (cut down) the output returned from a show command.
For example, I'm using the junipernetworks.junos.junos_command module to run a 'show version' - I would like a more concise single line output. Pipes do not work with this module it seems , so (| match "string") is not useful.
Some older documentation indicated your uptime.stdout_lines can be appended with brackets and a number indicating the line you want to display - ie uptime.stdout_lines[4] - this causes an undefined variable error when running the playbook...and no output is displayed. (see below)
What is the preferred way to get this done - are there other modules that are more favorable to filtering? Any help and examples are appreciated !
My simple playbook is below ,,,, thank you, Dennis
TASK [display output] *********************************************************************************************************************************************
ok: [dining_core] => {
"uptime.stdout_lines[3]": "VARIABLE IS NOT DEFINED!"
---
- name: Den device info
hosts: test
gather_facts: no
connection: local
tasks:
- name: get version
junipernetworks.junos.junos_command:
commands:
- show version
register: uptime
- name: display output
debug:
var: uptime.stdout_lines
ASK [display output] *********************************************************************************************************************************************ok: [dining_core] => {"uptime.stdout_lines": [["fpc0:","--------------------------------------------------------------------------","Hostname: Dining_Core","Model: ex3400-48p","Junos: 20.2R3-S1.3","JUNOS OS Kernel 32-bit [20210429.58e41ab_builder_stable_11-204ab]","JUNOS OS libs [20210429.58e41ab_builder_stable_11-204ab]","JUNOS OS runtime [20210429.58e41ab_builder_stable_11-204ab]","JUNOS OS time zone information [20210429.58e41ab_builder_stable_11-204ab]","JUNOS py extensions2 [20210512.202604_builder_junos_202_r3_s1]","JUNOS py extensions [20210512.202604_builder_junos_202_r3_s1]","JUNOS py base2 [20210512.202604_builder_junos_202_r3_s1]","JUNOS py base [20210512.202604_builder_junos_202_r3_s1]","JUNOS OS crypto [20210429.58e41ab_builder_stable_11-204ab]","JUNOS OS boot-ve files [20210429.58e41ab_builder_stable_11-204ab]","JUNOS network stack and utilities [20210512.202604_builder_junos_202_r3_s1]","JUNOS libs [20210512.202604_builder_junos_202_r3_s1]","JUNOS runtime [20210512.202604_builder_junos_202_r3_s1]","JUNOS na telemetry [20.2R3-S1.3]","JUNOS Web Management Platform Package [20210512.202604_builder_junos_202_r3_s1]","JUNOS ex libs [20210512.202604_builder_junos_202_r3_s1]","JUNOS ex runtime [20210512.202604_builder_junos_202_r3_s1]","JUNOS ex platform support [20210512.202604_builder_junos_202_r3_s1]","JUNOS Openconfig [20.2R3-S1.3]","JUNOS dcp network modules [20210512.202604_builder_junos_202_r3_s1]","JUNOS modules [20210512.202604_builder_junos_202_r3_s1]","JUNOS ex modules [20210512.202604_builder_junos_202_r3_s1]","JUNOS ex Data Plane Crypto Support [20210512.202604_builder_junos_202_r3_s1]","JUNOS daemons [20210512.202604_builder_junos_202_r3_s1]","JUNOS SDN Software Suite [20210512.202604_builder_junos_202_r3_s1]","JUNOS Extension Toolkit [20210512.202604_builder_junos_202_r3_s1]","JUNOS Phone-home [20210512.202604_builder_junos_202_r3_s1]","JUNOS Packet Forwarding Engine Support (EX34XX) [20210512.202604_builder_junos_202_r3_s1]","JUNOS jdocs ex [20210512.202604_builder_junos_202_r3_s1]","JUNOS jail runtime [20210429.58e41ab_builder_stable_11-204ab]","JUNOS FIPS mode utilities [20210512.202604_builder_junos_202_r3_s1]","","fpc1:","--------------------------------------------------------------------------", ------------------------------
DENNIS TOPO
------------------------------