How do i compare the parsed output against a value?

13 views
Skip to first unread message

Vikram S

unread,
Apr 21, 2021, 2:30:28 PM4/21/21
to Ansible Project
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

Dick Visser

unread,
Apr 21, 2021, 3:40:51 PM4/21/21
to ansible...@googlegroups.com
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
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/76c877da-318c-4b92-94ea-02ddf079a693n%40googlegroups.com.



--
Dick Visser
Trust & Identity Service Operations Manager
GÉANT

Vikram S

unread,
Apr 22, 2021, 1:03:41 AM4/22/21
to Ansible Project
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'.

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

Thanks,
Vikram
Reply all
Reply to author
Forward
0 new messages