Interview Prep/Ansible/Variables, Facts and Precedence

How do you reference a variable, and when must you quote it?

BeginnerConceptVariables, Facts and Precedence
Answer

Use Jinja2 syntax {{ var }}. If a YAML value starts with {{, the whole value must be quoted, or YAML will try to parse it as a dictionary. Inside when:, failed_when: and until: you write bare expressions with no braces.

vars:
  greeting: "{{ prefix }}-world"        # quoted, required
tasks:
  - ansible.builtin.debug: { msg: "Hi {{ greeting }}" }
    when: prefix is defined             # no braces here
All Ansible questions Roadmap: Ansible

More on Variables, Facts and Precedence