# How do i compare the parsed output against a value?

**URL:** <https://forum.ansible.com/t/how-do-i-compare-the-parsed-output-against-a-value/35028>\
**Category:** Ansible Project\
**Created:** [April 21, 2021, 6:30pm UTC](https://forum.ansible.com/t/how-do-i-compare-the-parsed-output-against-a-value/35028 "2021-04-21T18:30:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vikram\_S](https://avatars.discourse-cdn.com/v4/letter/v/90db22/32.png) [@Vikram\_S](https://forum.ansible.com/u/Vikram_S)\
**Post date:** [April 21, 2021, 6:30pm UTC](https://forum.ansible.com/t/how-do-i-compare-the-parsed-output-against-a-value/35028/1 "2021-04-21T18:30:28Z")

</div>

Hi,

I used TTP parser to parse the output of ‘sh run int gi0/0’ and below is output.

Say for example, i want to compare bandwidth value againt a number and check if it higher/lower than a certain value, how do i write the syntax for that?

TASK [Display facts]

ok: [ROUTER] =\> {  
“msg”: [  
[  
{  
“show\_flash”: {  
“bandwidth”: “50000”,  
“description”: “ISP”,  
“interface”: “GigabitEthernet0/0/2”,

Thanks,  
Vikram

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [April 21, 2021, 7:40pm UTC](https://forum.ansible.com/t/how-do-i-compare-the-parsed-output-against-a-value/35028/2 "2021-04-21T19:40:26Z")

</div>

I have no idea what TTP parser is, but you also didn't tell how that  
is relevant, so I'll ignore that.

What about something basic like:

when: show\_flash.bandwidth|int \>= 50000

---

<div class="post-metadata">

**Author:** ![Vikram\_S](https://avatars.discourse-cdn.com/v4/letter/v/90db22/32.png) [@Vikram\_S](https://forum.ansible.com/u/Vikram_S)\
**Post date:** [April 22, 2021, 5:03am UTC](https://forum.ansible.com/t/how-do-i-compare-the-parsed-output-against-a-value/35028/3 "2021-04-22T05:03:41Z")

</div>

Hi Dick,

I assumed everyone using ansible would have atleast heard about parsing (even if not used it), that’s why i didn’t elaborate on it. Maybe i was wrong.

Parsing is used to extract data from output saved in a custom variable and use that data for comparison purpose (for example). This is useful when there is no module or filter available that can be used to manipulate certain kind of data. There are several parsers available like TTP parser, PYATS/genie, etc.

What i have done above is save contents os ‘show flash:’ in a custom variable and then use TTP parser to extract various data. If ididn’t extract it, the output would be seen as just a ‘string of characters’. But after parsing data, i can now convert the string into integer like in the case of ‘bandwidth’.  
[https://docs.ansible.com/ansible/latest/network/user\_guide/cli\_parsing.html#parsing-with-ttp](https://docs.ansible.com/ansible/latest/network/user_guide/cli_parsing.html#parsing-with-ttp)

I will try your syntax and let you know if it works or not.

Thanks,  
Vikram
