Per-host values, like `server_id` for MySQL, must be unique and stable.
IntermediateScenarioVariables, Facts and Templates
Answer
Situation read → Generate unique but deterministic values.
What I'd do → Either set them in host_vars/, or derive from inventory position.
mysql_server_id: "{{ groups['db'].index(inventory_hostname) + 1 }}"
Why → Index in the group is stable as long as hosts are only appended. If you reorder, IDs change, so explicit host_vars is safer for databases.
Interview tip → Call out the trade-off between convenience and stability.
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.IntermediateNothing should be rendered unless a mandatory variable is supplied.BeginnerA fact you need is not collected by default, such as a custom application version.Intermediate