ansible - Showing warning "conditional statements should not include jinja2 templating delimiters”

Viewed 2314
- name: creating  task 
  shell: my_commnad
  when: ns.stdout.find('{{lookup('env',env')}}') == -1

warning

[WARNING]: conditional statements should not include jinja2 templating
delimiters such as {{ }} or {% %}. Found:
ns.stdout.find("{{lookup('env','NAMESPACE')}}") == -1

my playbook showing Warning "conditional statements should not include jinja2 templating delimiters".The task is to run the shell command if a paricular env is not present . how should I avoid this warning and keep task working?

1 Answers

You never nest {{...}} markers inside a Jinja templating context. The arguments to the when keyword are implicitly inside a Jinja context, so you don't need any {{...}} markers. Just write e.g:

when: ns.stdout.find(lookup('env','NAMESPACE')) == -1
Related