>From the below output, i need to extract only the IP 10.1.1.10 (it is ok if 
the entire line starting from asterix is extracted). 

I wrote below script and it seemed to work when i tested in regex101.com 
but failing when i used it in playbook. What am i doing wrong? How can it 
be improved?

*SWITCH COMMAND:*

    CORE-SWITCH#sh ip route 0.0.0.0
    Routing entry for 0.0.0.0/0, supernet
    Known via "static", distance 1, metric 0, candidate default path
    Redistributing via eigrp 500
    Advertised by eigrp 500
    Routing Descriptor Blocks:
    * 10.1.1.10
      Route metric is 0, traffic share count is 1

*SCRIPT:*

    tasks:
    - name: GATHER DEFAULT ROUTE INFO
      ios_command:
        commands: "show ip route 0.0.0.0"

      register: default_route

    - debug:
        msg: "{{ default_route.stdout[0] | regex_findall('(.*)') }}"


*OUTPUT:*

    ERROR! We were unable to read either as JSON nor YAML, these are the 
errors we got from each:
    JSON: Expecting value: line 1 column 1 (char 0)

    Syntax Error while loading YAML.
    found unknown escape character

    The error appears to be in '/root/sample12.yaml': line 19, column 59, 
but may be elsewhere in the file depending on the exact syntax problem.

    The offending line appears to be:

    - debug:
        msg: "{{ default_route.stdout[0] | regex_findall('\* (.*)') }}"
                                                          ^ here
    We could be wrong, but this one looks like it might be an issue with 
missing quotes. Always quote template expression brackets when they start a 
value. For instance:

    with_items:
      - {{ foo }}

    Should be written as:

    with_items:
      - "{{ foo }}"

Thanks,
Vikram

-- 
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-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/0ae9c617-c120-4d65-a291-82f7f0167184n%40googlegroups.com.

Reply via email to