Interview Prep/Ansible/Variables, Facts and Precedence Problems

`{{ proxy_url | default('http://proxy:3128') }}` still renders as an empty string

IntermediateTroubleshootingVariables, Facts and Precedence Problems
Answer

Likely causes → default only fires when the variable is undefined. Here it is defined but empty (proxy_url: "" or null from an AWX survey or a group_vars placeholder).

Fix → Pass true as the second argument, so falsy values also fall back to the default:

"{{ proxy_url | default('http://proxy:3128', true) }}"

Prevent → Do not define placeholder empty values in group_vars. Leave the variable undefined and keep defaults in the role.

All Ansible questions Roadmap: Ansible

More on Variables, Facts and Precedence Problems