Hi all…
I have the below vars:
`
client_destinations:
apache-servers:
pre_cmd: ‘$template custom,“/logs/apache-servers/%source%.log”’
rules:
- var: ‘$syslogfacility-text’
operator: ‘contains’
search: ‘local5’
destination: ‘-?custom’
path: ‘/logs/apache-servers/*.log’ - var: ‘$syslogtag’
search: ‘apache-access:’
operator: ‘contains’
destination: ‘/logs/apache-servers/access.log’ - var: ‘$syslogtag’
search: ‘apache-error:’
operator: ‘contains’
destination: ‘/logs/apache-servers/error.log’ - destination: ‘/logs/apache-servers/other.log’
`
I have the below Jinja2 code embedded in a playbook:
`
- name: Create new log dest
set_fact:
log_dest2: |
[
{% for group in client_destinations.keys() %}
{% set group_dest = client_destinations[group] %}
{% for dest in group_dest.rules %}
{% if dest.destination matches ‘^-?’ %}
‘{{ dest.path }}’,
{% else %}
‘{{ dest.destination }}’,
{% endif %}
{% endfor %}
{% endfor %}
]
`
WIth “if” statement in the Jinja2 code, I’m trying to match any destination
(in above vars) that begins with -?. I’ve tried the operator matches and starts with. Nothing works.
( What works is only this - {% if dest.destination == ‘-?custom’ %} )
How do I use regex here to achieve the match?
Thanks in advance.