HI i am new to jinja2 and trying to use regular expression as shown below
{% if ansible_hostname == \'uat\' %}
{% set server = \'thinkingmonster.com\' %}
To my knowledge, there is no builtin filter for that in Jinja2 neither among Ansible's extra filters, but it's not a big deal to make your own:
certs = {'.*thinking.*': 'akash', '.*sleeping.*': 'akashthakur'}
def map_regex(value, mapping=certs):
for k, v in mapping.items():
if re.match(k, value):
return v
Then you'll need to add a filter plugin to Ansible, so that it will use the function above in templates (like {{server|ssl_cert}}
if you name the filter ssl_cert
).
That said, a plain old function or a plain old dictionary that is passed to the templates and used there explicitly might fit this job better.