how to pass the variable holding the value to regex_search for matching the output?

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

help would be much appreciated!!