eos_command module waitfor - IP address in json structure

66 views
Skip to first unread message

Martin Baro

unread,
Mar 21, 2016, 12:56:35 PM3/21/16
to Ansible Project
Hi

I`m trying to catch a specific route in the waitfor statment if it is present from a show ip route output.
However I think ansible misinterprets the statement because of the dots in the IP address.
(I can successfully test other values like vrfs.default.defaultRouteState )
The playbook:
---

- name: test playbook
  hosts: veos
  gather_facts: no
  connection: local
  vars:
   route: "1.2.3.4/30"
  tasks:
   - name: show ip route
     eos_command:
      commands:
       - show ip route | json
      username: ansible
      password: ansible
      host: x.x.x.x
      transport: cli
      waitfor:
       - "result[0].vrfs.default.routes.{{ route }}.hardwareProgrammed eq true"


The error was: ValueError: result[0].vrfs.default.routes.1.2.3.4/30.hardwareProgrammed

The json structure is:
"vrfs": {
                    "default": {
                        "allRoutesProgrammedHardware": true,
                        "allRoutesProgrammedKernel": true,
                        "defaultRouteState": "notSet",
                        "routes": {
                            "1.2.3.4/30": {
                                "directlyConnected": true,
                                "hardwareProgrammed": true,
                                "kernelProgrammed": true,
                                "routeAction": "forward",
                                "routeType": "connected",
                                "vias": [
                                    {
                                        "interface": "Ethernet2"
                                    }
                                ]
                            },
                            "192.168.48.0/24": {
                                "directlyConnected": true,
                                "hardwareProgrammed": true,
                                "kernelProgrammed": true,
                                "routeAction": "forward",
                                "routeType": "connected",
                                "vias": [
                                    {
                                        "interface": "Ethernet1"
                                    }
                                ]
                            }

Is there any way I can reference the specific route?

Thanks,

Martin


Uditha Desilva

unread,
Mar 21, 2016, 1:07:43 PM3/21/16
to Ansible Project
The dotted form is a shorthand for using braces, so maybe this will work:

       - "result[0].vrfs.default.routes['{{ route }}'].hardwareProgrammed eq true"

Martin Baro

unread,
Mar 21, 2016, 1:26:07 PM3/21/16
to Ansible Project
Hi,

It seems it`s not evaluating the routes[] part:
with your waitfor:

ValueError: result[0].vrfs.default.routes[1.2.3.4/30].hardwareProgrammed

I also tried to index it with [0] without success:

ValueError: result[0].vrfs.default.routes[0].hardwareProgrammed

Uditha Desilva

unread,
Mar 22, 2016, 9:50:05 AM3/22/16
to Ansible Project
It may need more protection for those quotes -- perhaps this?

Martin Baro

unread,
Mar 22, 2016, 2:17:57 PM3/22/16
to Ansible Project
Hi Uditha,

Thanks for the reply.
I've simplified the problem a bit (just removed the variable) and with removing the "" around the whole statement I managed to preserve the quotes.
Unfortunately it didn't solve the problem:

    waitfor:
       - result[0].vrfs.default.routes[\'1.2.3.4/30\'].hardwareProgrammed eq true


The error was: ValueError: result[0].vrfs.default.routes['1.2.3.4/30'].hardwareProgrammed

The issue is the same with double quotes around the IP address.

Peter Sprygada

unread,
Mar 22, 2016, 4:25:31 PM3/22/16
to ansible...@googlegroups.com
Thats a bug... could you file an issue at github.com/ansible/ansible-modules-core please?

--
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 post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/7f5a3e93-84cc-43c7-b11f-50ccb849971a%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Peter Sprygada

unread,
Mar 23, 2016, 2:39:46 AM3/23/16
to ansible...@googlegroups.com
Ignore the request for filing an issue, I committed a change that should fix this problem. The fix is available for testing in ansible/ansible devel

Peter Sprygada

unread,
Mar 23, 2016, 2:40:56 AM3/23/16
to ansible...@googlegroups.com
(ansible)[ansible-eos]$ cat route.yaml
---
- hosts: veos01
  gather_facts: no

  vars:
    route: 1.1.1.1/32

  tasks:
    - eos_command:
        commands:
          - show ip route | json
        waitfor:
          - "result[0].vrfs.default.routes[{{ route }}].hardwareProgrammed eq true"
        provider: "{{ cli }}"


(ansible)[ansible-eos]$ ansible-playbook route.yaml

PLAY [veos01] ******************************************************************

TASK [eos_command] *************************************************************
ok: [veos01]

PLAY RECAP *********************************************************************
veos01                     : ok=1    changed=0    unreachable=0    failed=0

Martin Baro

unread,
Mar 23, 2016, 3:41:14 PM3/23/16
to Ansible Project
Thanks Peter, much appreciated.
Also thanks for the great network webinar, was really informative.

Martin

Peter Sprygada

unread,
Mar 23, 2016, 4:33:15 PM3/23/16
to ansible...@googlegroups.com
My pleasure, glad you found it helpful.

Reply all
Reply to author
Forward
0 new messages