How do you merge two dictionaries, and what happened to `hash_behaviour`?
AdvancedConceptVariables, Facts and Precedence
Answer
By default, a higher-precedence dict replaces a lower one completely instead of merging. The hash_behaviour = merge setting changes that globally, but it is deprecated because it makes variables unpredictable.
Merge explicitly with the combine filter:
app_config: "{{ app_config_defaults | combine(app_config_overrides | default({}), recursive=true) }}"
recursive=true merges nested dicts; lists are not merged and are replaced. The same pattern, a *_defaults dict plus a *_overrides dict, is a clean way to design role variables.
More on Variables, Facts and Precedence
Where can you define variables in Ansible?BeginnerHow do you reference a variable, and when must you quote it?BeginnerGive a summary of variable precedence.IntermediateWhat are the lowest and highest precedence sources, and why does that matter?IntermediateWhat is the difference between a role's `defaults/` and `vars/`?IntermediateWhat are facts and how are they gathered?Beginner