Ansible-Playbook to display output of multiple show commands (using stdout_lines with Loop)

 In this playbook, we we'll see how we can get display of multiple show commands in stdout_lines format. We can make use of loops (or with_items) for submitting multiple commands, but debug output with stdout_lines does not gives the formatted result as it would give for single command. So in case of multiple commands, we can debug the output of each command separately in stdout_lines format.

#Ansible-Playbook to display Output of multiple show commands

- name: Display Output of multiple show commands
  hosts: all
  gather_facts: no
  connection: network_cli
  become: no
  become_method: enable

   - name: Get the config
      command: "{{ item }}"
     register: result

       - show ip access-lists TestACL-1 | include 150
       - show ip access-lists TestACL-2 | include 250
       - show run | include file|bgp
       - show snmp user | i snmp-user

   - debug:
         - "{{ result.results[0].stdout_lines }}"
         - "{{ result.results[1].stdout_lines }}"
         - "{{ result.results[2].stdout_lines }}"
         - "{{ result.results[3].stdout_lines }}"

# Debug output can also be displayed using following lines
#  - debug:
#      msg: "{{ item.stdout_lines }}"
#    with_item


Popular posts from this blog

Anyconnect SSL-Client VPN with Self-signed Certificate on Cisco ASA

Filtering Routes in BGP using Route-maps and Prefix-list

Open Shortest Path First (OSPF)

IKEv2 IPsec Site-to-Site VPN configuration on Cisco ASA 8.4(x)

IPsec VPN as a Backup for Point-to-Point Link using IP SLA

Border Gateway Protocol (BGP)

Cisco ASA Active/Active Failover Configuration

Bypassing Proxy Server in Google Chrome

Cisco ASA Active/Standby Failover Configuration