Interview Prep/Ansible/YAML, Syntax and Jinja2 Errors

A `when: enable_tls` task runs even though the job was started with `-e enable_tls=false`

AdvancedTroubleshootingYAML, Syntax and Jinja2 Errors
Answer

Likely causes → -e key=value always passes a string. The string "false" is not empty, so Jinja treats it as truthy. On ansible-core 2.19+ this is an error instead: Conditionals must have a boolean result.

Diagnose →

- ansible.builtin.debug:
    msg: "{{ enable_tls | type_debug }}"   # prints AnsibleUnicode / str

Fix →

ansible-playbook site.yml -e '{"enable_tls": false}'   # JSON keeps the type

or in the play: when: enable_tls | bool.

Prevent → Use | bool on every flag that can come from -e, a survey or an environment variable, and declare flag types in meta/argument_specs.yml so bad input fails early.

All Ansible questions Roadmap: Ansible

More on YAML, Syntax and Jinja2 Errors