kyriakak71
kyriakak71

Reputation: 33

"when" condition is not working in ansible

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?

Upvotes: 1

Views: 356

Answers (1)

U880D
U880D

Reputation: 12008

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

Upvotes: 1

Related Questions