Nothing should be rendered unless a mandatory variable is supplied.
BeginnerScenarioVariables, Facts and Templates
Answer
Situation read → Fail early on missing input.
What I'd do →
- ansible.builtin.assert:
that:
- db_password is defined
- db_password | length >= 12
fail_msg: "db_password must be set and 12+ chars"
and use {{ db_host | mandatory }} in templates.
Why → A clear early failure beats a half-rendered config.
Interview tip → assert in pre_tasks or tasks/validate.yml of a role is common.
More on Variables, Facts and Templates
A variable you set in `group_vars` is being overridden and you do not know where. How do you find the source?IntermediateYou need different values per environment without copying playbooks.BeginnerYou must render an Nginx config with one `server` block per site from a list.IntermediateA template needs the IPs of all hosts in the `db` group, for example for a replication config.IntermediatePer-host values, like `server_id` for MySQL, must be unique and stable.IntermediateA fact you need is not collected by default, such as a custom application version.Intermediate