Le 2019-03-20 09:23, Ashok a écrit :
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.

Hi,

Did you try match (not matches) ? Be careful you need brackets

https://docs.ansible.com/ansible/latest/user_guide/playbooks_tests.html

Regards,

JYL

--
You received this message because you are subscribed to the Google Groups "Ansible 
Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/b65efa2d322cfa971b94a38ee9f0fe57%40lenhof.eu.org.
For more options, visit https://groups.google.com/d/optout.

Reply via email to