Anyway to get output without all the "!"?

23 views
Skip to first unread message

Steven Williams

unread,
Aug 22, 2019, 11:49:27 AM8/22/19
to Ansible Project

---

- name: show version and other user level commands

  hosts: IOL_Routers

  gather_facts: false

  connection: network_cli

  become: yes


  tasks:

    - name: run multiple commands on remote nodes

      ios_command:

        commands:

          - show run

          - show ip int br


      register: print_output


    - debug: var=print_output.stdout_lines

~                                              

ok: [R01] => {

    "print_output.stdout_lines": [

        [

            "Building configuration...", 

            "", 

            "Current configuration : 1037 bytes", 

            "!", 

            "! Last configuration change at 20:30:43 EET Wed Aug 21 2019", 

            "!", 

            "version 15.4", 

            "service timestamps debug datetime msec", 

            "service timestamps log datetime msec", 

            "no service password-encryption", 

            "!", 

            "hostname R1", 

            "!", 

            "boot-start-marker", 

            "boot-end-marker", 

            "!", 

            "aqm-register-fnf", 

            "!", 

            "!", 

            "no aaa new-model", 

            "clock timezone EET 2 0", 

            "mmi polling-interval 60", 

            "no mmi auto-configure", 

            "no mmi pvc", 

            "mmi snmp-timeout 180", 

            "!", 

            "!", 

            "!", 

            "!", 

            "!", 

            "!", 

            "", 

            "", 

            "!", 

            "!", 

            "!", 

            "!", 

            "ip domain name lab.net", 

            "ip cef", 

            "no ipv6 cef", 

            "!", 

            "multilink bundle-name authenticated", 

            "!", 

            "!", 

            "!", 

            "!", 

            "!", 

            "!", 

            "!", 

            "!", 

            "username cisco privilege 15 password 0 cisco", 

            "!", 

            "redundancy", 

            "!", 

            "!", 

            "! ", 

            "!", 

            "!", 

            "!", 

            "!", 

            "!", 

            "!", 

            "!", 

            "!", 

            "!", 

            "!", 

            "!", 

            "!", 

            "interface Ethernet0/0", 

            " ip address 10.20.250.100 255.255.255.0", 

            "!", 

            "interface Ethernet0/1", 

            " no ip address", 

            " shutdown", 

            "!", 

            "interface Ethernet0/2", 

            " no ip address", 

            " shutdown", 

            "!", 

            "interface Ethernet0/3", 

            " no ip address", 

            " shutdown", 

            "!", 

            "ip forward-protocol nd", 

            "!", 

            "!", 

            "no ip http server", 

            "no ip http secure-server", 

            "ip route 0.0.0.0 0.0.0.0 10.20.250.1", 

            "!", 

            "!", 

            "!", 

            "!", 

            "control-plane", 

            "!", 

            "!", 

            "!", 

            "!", 

            "!", 

            "!", 

            "!", 

            "!", 

            "line con 0", 

            " logging synchronous", 

            "line aux 0", 

            "line vty 0 4", 

            " login local", 

            " transport input all", 

            "!", 

            "!", 

            "end"

Kai Stian Olstad

unread,
Aug 22, 2019, 1:25:48 PM8/22/19
to ansible...@googlegroups.com
On 22.08.2019 17:49, Steven Williams wrote:
> ---
>
> - name: show version and other user level commands
>
> hosts: IOL_Routers
>
> gather_facts: false
>
> connection: network_cli
>
> become: yes
>
>
> tasks:
>
> - name: run multiple commands on remote nodes
>
> ios_command:
>
> commands:
>
> - show run
>
> - show ip int br
>
>
> register: print_output
>
>
> - debug: var=print_output.stdout_lines


You can filter them out after the fact at least

For only ! lines
{{ print_output.stdout_lines | reject('equalto', '!') | list }}

All lines starting with !
{{ print_output.stdout_lines | reject('search', '^!') | list }}

--
Kai Stian Olstad

Steven Williams

unread,
Aug 22, 2019, 2:24:02 PM8/22/19
to Ansible Project
Where would this go within the yml file?

Steven Williams

unread,
Aug 22, 2019, 3:21:27 PM8/22/19
to Ansible Project
Doesn't seem to work.

---
- name: show version and other user level commands
  hosts: IOL_Routers
  gather_facts: false
  connection: network_cli
  become: yes

  tasks:
    - name: run multiple commands on remote nodes
      ios_command:
        commands:
          - show run

      register: print_output

- name: result of running commands above
    - debug: 
        msg: "{{ print_output.stdout_lines | reject('equalto', '!') | list }}"

Kai Stian Olstad

unread,
Aug 22, 2019, 5:16:20 PM8/22/19
to ansible...@googlegroups.com
You could give us the courtesy and give us the error message, we are not
mind readers.

But your indentation is not correct and you need to remove the dash on
debug.


--
Kai Stian Olstad

Steven Williams

unread,
Aug 22, 2019, 8:08:52 PM8/22/19
to Ansible Project
There is not error. It runs but doesn't remove the "!".

---

- name: show version and other user level commands

  hosts: IOL_Routers

  gather_facts: false

  connection: network_cli

  become: yes


  tasks:

    - name: run multiple commands on remote nodes

      ios_command:

        commands:

          - show run


      register: print_output


    - name: result of running commands above

      debug:  msg="{{ print_output.stdout_lines | reject('equalto', '^!') | list }}"


bnapwks120:ansible stevenwiliams$ ansible-playbook showrunrv1.yml -u cisco -k

SSH password: 


PLAY [show version and other user level commands] ***********************************************************************************************************


TASK [run multiple commands on remote nodes] ****************************************************************************************************************

ok: [R02]

ok: [R04]

ok: [R01]

ok: [R03]


TASK [result of running commands above] *********************************************************************************************************************

ok: [R02] => {

    "msg": [

        [

            "Building configuration...", 

            "", 

            "Current configuration : 1075 bytes", 

            "!", 

            "! Last configuration change at 18:03:17 EET Thu Aug 22 2019 by cisco", 

            "!", 

            "version 15.4", 

            "service timestamps debug datetime msec", 

            "service timestamps log datetime msec", 

            "no service password-encryption", 

            "!", 

            "hostname R02", 

Kai Stian Olstad

unread,
Aug 23, 2019, 2:59:06 AM8/23/19
to ansible...@googlegroups.com
On 23.08.2019 02:08, Steven Williams wrote:
>> - name: result of running commands above
>>
>> debug: msg="{{ print_output.stdout_lines | reject('equalto',
>> '^!')
>> | list }}"
>>

If you look at my post you'll see that you are mixing the syntax
together.
equalto is without the caret and search is with caret character.


--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages