Find and replace filter

Heyo,

I was looking for a built-in filter either in Ansible or in Jinja2 that supported regex based find and replace. It doesn’t appear a real straight forward implementation exists today. I was able to achieve what I wanted by adding the following bit to ‘core.py’ for testing purposes.

def regex_replace(s, find, replace):
return re.sub(find, replace, s)

I was then able to take an existing variable do what I wanted.

i.e.

bgp router-id {{external_ipv4_self_ip|regex_replace(“[/].*”, “”)}}