Basic Question - About VAR usage in condition

I want to understand during conditions when to use curl braces and when not ! I have attached the snapshot. If i don’t use the {{ }} and double quotes it works but with them it fails.

Hi @himanshu.haritwal,

Thank you for your question

Using {{ }} means you use jinja2 syntax on your ansible-playbook but this syntax returns a string and it’s used to print variable or evaluation result.
when statement waits for a boolean so you can’t use {{ }} syntax.

Below an example of how to use jinja2 syntax :

- name: 'Am i an Adult or a child?'
  hosts: localhost
  vars:
    age: 25
  tasks:
    - name: i am young
      debug:
        msg: "With {{ age }} years old, i'm young. In {{ 18 - age}} years i will be adult"
      when: age < 18
    - name: i am a adult
      debug:
        msg: "With {{ age }} years old, i'm adult since {{ age - 18}} years"
      when: age >= 18

Some references :

Regards