Interview Prep/Ansible/Variables, Facts and Templates

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.

All Ansible questions Roadmap: Ansible

More on Variables, Facts and Templates