# how to pass the variable holding the value to regex\_search for matching the output?

**URL:** <https://forum.ansible.com/t/how-to-pass-the-variable-holding-the-value-to-regex-search-for-matching-the-output/35525>\
**Category:** Ansible Project\
**Created:** [July 20, 2021, 12:37pm UTC](https://forum.ansible.com/t/how-to-pass-the-variable-holding-the-value-to-regex-search-for-matching-the-output/35525 "2021-07-20T12:37:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Charles\_Daniel](https://avatars.discourse-cdn.com/v4/letter/c/3d9bf3/32.png) [@Charles\_Daniel](https://forum.ansible.com/u/Charles_Daniel)\
**Post date:** [July 20, 2021, 12:37pm UTC](https://forum.ansible.com/t/how-to-pass-the-variable-holding-the-value-to-regex-search-for-matching-the-output/35525/1 "2021-07-20T12:37:07Z")

</div>

Team,

I would like to pass the variable holding value to regex to match the output.

prim\_b2b\_ip is the variable which i need to use inside the regex search for matching whether the return output comes as expected or not.

Here I dont know how to use it, hence passing the ip directly.

- name: Ensure vpnv4 b2b bgp neighborship peering between Secondary to Primary  
hosts: secondary  
gather\_facts: false  
connection: local  
vars:  
prim\_b2b\_ip: 172.16.200.5  
tags:
- “sec\_b2b\_check”  
tasks:
- name: bgp vpnv4 neighborship peering validation on Secondary  
ios\_command:  
commands:
- “show ip bgp vpnv4 all summary”  
register: output
- debug:  
msg: “{{output}}”
- set\_fact:  
intf: |
- {{ output.stdout | map(‘regex\_search’,‘((172.16.200.5)([\s]+)([\d])([\s]+)([\d]+)([\s]+)([\d]+)([\s]+)([\d]+)([\s]+)([\d]+)([\s]+)([\d]+)([\s]+)([\d]+)([\s]+)(.\*)([\s]+)([\d]+))’) | list }}  
register: output
- debug:  
msg: “{{ output }}”
- name: Check B2B interface address presence on secondary  
fail:  
msg: “B2B peering interface address is not present on secondary”  
failed\_when: prim\_b2b\_ip not in intf

---

<div class="post-metadata">

**Author:** ![Charles\_Daniel](https://avatars.discourse-cdn.com/v4/letter/c/3d9bf3/32.png) [@Charles\_Daniel](https://forum.ansible.com/u/Charles_Daniel)\
**Post date:** [July 21, 2021, 7:29am UTC](https://forum.ansible.com/t/how-to-pass-the-variable-holding-the-value-to-regex-search-for-matching-the-output/35525/2 "2021-07-21T07:29:16Z")

</div>

help would be much appreciated!!
