cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2536
Views
0
Helpful
2
Replies

Ansible Playbook out with many !

Steven Williams
Level 4
Level 4

I am running an ansible playbook to pull running configs of my switches. I do get this to work but my output has many lines of ! that I want to eliminate. 

 

Does ios_command have something build into for this filtering? I have written this yml but 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 }}"

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: [R03]

ok: [R02]

ok: [R01]

ok: [R04]

 

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",

            "!",

            "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.101 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",

            "!",

            "!",

            "snmp-server location EveLab",

            "!",

            "!",

            "control-plane",

            "!",

            "!",

            "!",

            "!",

            "!",

            "!",

            "!",

            "!",

            "line con 0",

            " logging synchronous",

            "line aux 0",

            "line vty 0 4",

            " login local",

            " transport input ssh",

            "!",

            "!",

            "end"

        ]

    ]

}

1 Accepted Solution

Accepted Solutions

Ben Walters
Level 3
Level 3

If you don't want any "!" in the output use show run | exclude ! it should only provide the running-config without all of the ! padding.  

View solution in original post

2 Replies 2

Ben Walters
Level 3
Level 3

If you don't want any "!" in the output use show run | exclude ! it should only provide the running-config without all of the ! padding.  

Well that was much easier than creating a filter on the output.

 

Thanks.