`group_vars/prod.yml` defines `app_config: {log_level: warn}` and the other keys from `group_vars/all.yml` disappear
IntermediateTroubleshootingVariables, Facts and Precedence Problems
Answer
Likely causes → Dictionaries are replaced, not merged. The default hash_behaviour is replace, so the more specific app_config replaces the whole dictionary.
Fix → Use separate names for each layer and merge them explicitly:
# all.yml
app_config_defaults: {log_level: info, workers: 4, port: 8080}
# prod.yml
app_config_overrides: {log_level: warn}
# role
app_config: "{{ app_config_defaults | combine(app_config_overrides | default({}), recursive=true) }}"
Prevent → Do not set hash_behaviour = merge globally. It is deprecated in spirit and changes behaviour everywhere. Prefer flat variables for values that need overriding.
More on Variables, Facts and Precedence Problems
Variables in `group_vars/webservers.yml` are silently ignoredBeginnerYou set `nginx_port: 8443` in inventory `group_vars`, but the role still uses `80`Intermediate`set_fact: release_tag=v2` runs, but later tasks still see `v1`Intermediate`'ansible.vars.hostvars.HostVarsVars object' has no attribute 'ansible_default_ipv4'` when templating `hostvars['db01']`Intermediate`'ansible_eth0' is undefined` on new cloud instancesBeginnerFacts like `ansible_hostname` became undefined after someone changed `ansible.cfg`Intermediate