Interview Prep/Ansible/Variables, Facts and Templates

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.

All Ansible questions Roadmap: Ansible

More on Variables, Facts and Templates