Create a template. For example,

shell> cat create_test.j2
{% for i in strings %}
{{ i }} = {{ '{{' }} {{ i }} {{ '}}' }}
{% endfor %}

Then, the below playbook

shell> cat pb.yml
- hosts: localhost
  tasks:
    - template:
        src: create_test.j2
        dest: /tmp/test.j2
      vars:
        strings:
          - '0'
          - '1'
          - "['aa', 'bb', 'cc']|intersect(['bb', 'cc'])"
          - "['aa', 'bb', 'cc']|intersect(['bb', 'cc'])|length > 0"
    - debug:
        msg: "{{ lookup('template', '/tmp/test.j2') }}"

gives abridged

  msg: |-
    0 = 0
    1 = 1
    ['aa', 'bb', 'cc']|intersect(['bb', 'cc']) = ['bb', 'cc']
    ['aa', 'bb', 'cc']|intersect(['bb', 'cc'])|length > 0 = True

-- 
Vladimir Botka

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20230728052731.289a5791%40gmail.com.

Attachment: pgpgWSQj23O6C.pgp
Description: OpenPGP digital signature

Reply via email to