Display specific lines from cisco output

I have a situation my script is

hosts: Branch
gather_facts: false
connection: local

tasks:

  • name: Facts
    ios_command:
    commands:

  • show inter gi0/0
    register: output

  • debug:
    msg: “{{ output.stdout_lines }}”

The output is like…

"GigabitEthernet0/0 is up, line protocol is up “,
" Hardware is CN Gigabit Ethernet, address is d8b1.
" Description: LAN”,
" MTU 1500 bytes, BW 100000 Kbit/sec, DLY 100 usec, ",

" reliability 255/255, txload 1/255, rxload 1/255",
" Encapsulation 802.1Q Virtual LAN, Vlan ID 1., loopback not set",
" Keepalive set (10 sec)“,
" Full Duplex, 100Mbps, media type is RJ45”,
" output flow-control is unsupported, input flow-control is unsupported",
" ARP type: ARPA, ARP Timeout 04:00:00",
" Last input 00:00:00, output 00:00:00, output hang never",
" Last clearing of "show interface" counters never",
" Input queue: 0/75/0/0 (size/max/drops/flushes); Total output drops: 0",
" Queueing strategy: fifo",
" Output queue: 0/40 (size/max)“,
" 5 minute input rate 64000 bits/sec, 46 packets/sec”,
" 5 minute output rate 81000 bits/sec, 38 packets/sec",
" 64022727 packets input, 3777167804 bytes, 0 no buffer",
" Received 7566193 broadcasts (0 IP multicasts)“,
" 0 runts, 0 giants, 0 throttles “,
" 0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored”,
" 0 watchdog, 904385 multicast, 0 pause input”,
" 60376363 packets output, 1696679415 bytes, 0 underruns",
" 0 output errors, 0 collisions, 0 interface resets",
" 115659 unknown protocol drops",
" 0 babbles, 0 late collision, 0 deferred",
" 0 lost carrier, 0 no carrier, 0 pause output",
" 0 output buffer failures, 0 output buffers swapped out"

But how can i display an specific line rather then whole output as i want the lines starts with “5 minute”

Please Help

You could use ansible-network.network-engine's command_parser. The example is on show interfaces.

I published more example on my github: https://github.com/kvernNC/cisco_config_parser/blob/master/README.md

Can you please explain me in detail because i have tried the solution but failed. Please help me

As I said , the documentation is about what your trying to do : https://github.com/ansible-network/network-engine/blob/devel/docs/user_guide/command_parser.md, but on show interfaces with a loop, not on a specific interface.

For your example, without loop, It should be something like this (not tested) :

1°) playbook

hosts: Branch
gather_facts: false
connection: local

tasks:

  • name: Facts
    ios_command:
    commands:

  • show inter gi0/0
    register: output

  • command_parser:
    file: “parser_templates/ios/show_interfaces.yaml”
    content: “{{ output.stdout.0 }}”

  • debug:
    var: input_rate.matches

  • debug:
    var: output_rate.matches

2°) content of the template: