# Getting cisco command output based on matched condition

**URL:** <https://forum.ansible.com/t/getting-cisco-command-output-based-on-matched-condition/31694>\
**Category:** Ansible Project\
**Created:** [November 20, 2019, 3:57pm UTC](https://forum.ansible.com/t/getting-cisco-command-output-based-on-matched-condition/31694 "2019-11-20T15:57:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pushparaj\_Gothandam](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/pushparaj_gothandam/32/5538_2.png) [@Pushparaj\_Gothandam](https://forum.ansible.com/u/Pushparaj_Gothandam)\
**Post date:** [November 20, 2019, 3:57pm UTC](https://forum.ansible.com/t/getting-cisco-command-output-based-on-matched-condition/31694/1 "2019-11-20T15:57:47Z")

</div>

Hi Team

I want get output of **“show mac add int {{ item.key }}”** as report for each interface, Can anyone guide me how to export the command output only matched condition as text file?

**Playbook:**

**roles:**  
**- ansible-network.network-engine**

**tasks:**  
**- name: Collect switchport interface information**  
**ios\_command:**  
**commands:**  
**- show interface status**  
**register: show\_interface\_status**

**- name: Parser the interface facts**  
**command\_parser:**  
**file: “parser/ios/show\_interface\_status.yaml”**  
**content: “{{ show\_interface\_status.stdout.0 }}”**

**- name: print the vlan 30 interface**  
**ios\_command:**  
**commands:**  
**- “show running interface {{ item.key }}”**  
**when: item.value.data.vlan == ‘100’**  
**with\_dict: “{{ interfaces\_status\_facts }}”**  
**register: vlan30\_output**

**- name: print the vlan 30 interface**  
**ios\_command:**  
**commands:**  
**- “show mac add int {{ item.key }}”**  
**when: item.value.data.vlan == ‘1’**  
**with\_dict: “{{ interfaces\_status\_facts }}”**  
**register: vlan30\_output**
