Exercise 3: A Conditional Line Inside a Jinja2 Template — Possible Solution ==================================================================== {% if ssl_enabled %} MaxConnections {{ max_connections }} {% endif %} -- Why this has to be a {% if %} block, not the task-level when: -- -- -- when: controls whether an entire TASK runs at all -- in this case, -- that would mean the whole template task either renders the ENTIRE -- config file, or skips deploying the file completely, with no -- in-between. That's the wrong granularity for what's being asked -- here: the requirement is that only ONE SPECIFIC LINE inside an -- otherwise-normal config file should be conditionally included, -- while the rest of the file still needs to be rendered and deployed -- regardless of ssl_enabled's value. {% if %} operates at the level -- of the template's own CONTENT, deciding what text appears inside -- the rendered file, which is exactly the right tool for -- conditionally including or excluding one line (or a whole block of -- lines) while the surrounding file is still generated normally. -- when: and {% if %} are solving genuinely different problems -- -- whether to run a task at all, versus what content ends up inside a -- file that task produces -- and this scenario specifically needs -- the second one. WHY THIS WORKS AS AN ANSWER ------------------------------ This writes a correctly structured Jinja2 conditional block matching the chapter's own {% if %}/{% endif %} syntax, then explains the when:-vs-{% if %} distinction by identifying the specific granularity mismatch (whole-task vs. one-line-inside-a-file) that makes when: unsuitable for this particular requirement.