"when" condition is not working in ansible

Viewed 26

I have an ansible playbook where I define a local variable and I want to execute a statement when this local variable is equal with the system variable. For example:

vars:
  dev_env: DEV
....
TASK
- name:
  win_copy:
   ...
  when: {{ system_variable}} == dev_env

However I always get an error even if I enclose the dev_env into {{}}, if I use "", etc. I have tried all potential combinations. Do you have a working example so that I could use it as a template?

1 Answers

I want to execute a statement when this local variable is equal with the system variable.

According Ansible documentation Conditionals

  when: system_variable == dev_env

Further Documentation

Related