A template needs the IPs of all hosts in the `db` group, for example for a replication config.
IntermediateScenarioVariables, Facts and Templates
Answer
Situation read → Cross-host data inside a template.
What I'd do →
{% for h in groups['db'] %}
host replication repl {{ hostvars[h].ansible_default_ipv4.address }}/32 md5
{% endfor %}
Make sure facts for the db hosts exist, either by gathering in an earlier play or via fact caching.
Why → hostvars exposes other hosts' variables and facts, but only if gathered in this run or cached.
Interview tip → Facts missing causes 'ansible_default_ipv4' is undefined; gather facts for db hosts first.
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.IntermediateNothing should be rendered unless a mandatory variable is supplied.BeginnerPer-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