I am trying to dynamically create a conditional by declaring the following variable
in_tags: in ansible_run_tags or "all" in ansible_run_tags
and use it in a when condition like so
- include: zsh.yml
when: '"zsh" {{ in_tags }}'
However Ansible gives the following warning when I do so
[WARNING]: conditional statements should not include jinja2 templating delimiters such as {{ }} or {%
%}. Found: "zsh" {{ in_tags }}
Removing the {{ }}
causes this to fail.
fatal: [localhost]: FAILED! => {"msg": "The conditional check '\"zsh\" in_tags' failed. The error was: template error while templating string: expected token 'end of statement block', got 'in_tags'. String: {% if \"zsh\" in_tags %} True {% else %} False {% endif %}\n\nThe error appears to be in '[REDACTED]/playbook/roles/fzf/tasks/zsh.yml': line 1, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Ensure zsh integration\n ^ here\n"}
Is there a better way to write this to avoid templating within the conditional statement?