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

46 views
Skip to first unread message

Charles Daniel

unread,
Jul 20, 2021, 8:37:43 AM7/20/21
to ansible...@googlegroups.com
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

Thanks,
Charles Daniel

Charles Daniel

unread,
Jul 21, 2021, 3:29:16 AM7/21/21
to Ansible Project
help would be much appreciated!!
Reply all
Reply to author
Forward
0 new messages