On 08/07/2021 12:18, Charles Daniel wrote:
Hi Dick, Below is the complete output of the playbook,

[root@tower1 temp_play]#  ansible-playbook testplay2.yml -i 
/etc/ansible/temp_play/hosts

PLAY [Get the secondary router tunnel ip address] 
*****************************************************************

TASK [Obtain secondary tunnel interface ip address] 
***************************************************************
ok: [172.16.12.1]

TASK [debug] 
******************************************************************************************************
ok: [172.16.12.1] => {
     "msg": [
         "Internet address is 172.16.121.6/32 <http://172.16.121.6/32>"
     ]
}


Hello Charles,

the output looks like a string, so the map filter doesn't makes sense here.

Please try:

{{output.stdout | regex_search('(([0-9]+(.)[0-9]+(.)[0-9]+(.)[0-9]+))') }}

Regards
          Racke


TASK [set_fact] 
***************************************************************************************************
ok: [172.16.12.1]

TASK [debug] 
******************************************************************************************************
ok: [172.16.12.1] => {
     "msg": {
         "ansible_facts": {
             "intf": "- [u'172.16.121.6']\n"
         },
         "changed": false,
         "failed": false
     }
}

PLAY RECAP 
********************************************************************************************************
172.16.12.1                : ok=4    changed=0    unreachable=0    failed=0    
skipped=0    rescued=0    ignored=0

[root@tower1 temp_play]#

Thanks,
Charles Daniel


On Thu, 8 Jul 2021 at 15:34, Dick Visser <[email protected] 
<mailto:[email protected]>> wrote:

    You're sending only the output of the debug task with the regex_search
    applied to the output.stdout variable.
    We need to see the output.stdout variable before you mangled it.

    On Thu, 8 Jul 2021 at 09:56, Charles Daniel <[email protected] 
<mailto:[email protected]>> wrote:
     >
     > One more help needed, When I try to do regex to get the ip output, it 
comes along with the unicode characters such as - [u'
     > how to eliminate it while grepping it through regex_search itself.
     >
     > Actual output: "- [u'172.16.121.6']\n"
     >
     > I want it to be(expected): 172.16.121.6
     >
     >
     >   - name: Obtain secondary tunnel interface ip address
     >     ios_command:
     >       commands:
     >         - "show interface tunnel1 | sec Internet address"
     >     register: output
     >   - debug:
     >       msg: "{{ output.stdout}}"
     >   - set_fact:
     >       intf: |
     >           - {{output.stdout | 
map('regex_search','(([0-9]+(.)[0-9]+(.)[0-9]+(.)[0-9]+))') | list }}
     >     register: sec_tunnel_ip
     >   - debug:
     >        msg={{ sec_tunnel_ip }}
     >
     >
     > Output:
     > ********
     >
     > TASK [debug] 
******************************************************************************************************
     > ok: [172.16.12.1] => {
     >     "msg": {
     >         "ansible_facts": {
     >             "intf": "- [u'172.16.121.6']\n"
     >         },
     >         "changed": false,
     >         "failed": false
     >     }
     > }
     >
     > Thanks,
     > Charles Daniel
     >
     > --
     > 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 [email protected] 
<mailto:ansible-project%[email protected]>.
     > To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAPnV%3Dh%2B7LxPqEnbrezq3Maofib9Ak8UmLUsK10twE0DeqXKBPw%40mail.gmail.com
 
<https://groups.google.com/d/msgid/ansible-project/CAPnV%3Dh%2B7LxPqEnbrezq3Maofib9Ak8UmLUsK10twE0DeqXKBPw%40mail.gmail.com>.



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

-- 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 [email protected] 
<mailto:ansible-project%[email protected]>.
    To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAL8fbwPitsJ0-RyoEdfUWJkV%3DBusc8y7gx8r_YnB1YuvDwuCeQ%40mail.gmail.com
 
<https://groups.google.com/d/msgid/ansible-project/CAL8fbwPitsJ0-RyoEdfUWJkV%3DBusc8y7gx8r_YnB1YuvDwuCeQ%40mail.gmail.com>.

--
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 
[email protected] 
<mailto:[email protected]>.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAPnV%3DhLBRtLbu0RWnNodwDs7v7xfrtprATkeKhfKC6%2By98OVsQ%40mail.gmail.com
 
<https://groups.google.com/d/msgid/ansible-project/CAPnV%3DhLBRtLbu0RWnNodwDs7v7xfrtprATkeKhfKC6%2By98OVsQ%40mail.gmail.com?utm_medium=email&utm_source=footer>.


--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration.

--
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/db06aa70-d5d3-de3e-f7ab-2c608b915ed3%40linuxia.de.

Reply via email to