Hello list,
I have encountered some not expected results when i tried to include (with include_vars) multiple var files in the beginning of a play.
I normally use the “merge” hash behavior (ansible.cfg) because it seems more natural to me: i usually have highly nested variable dicts
and i wish to add or override just parts of them based on the group/host hierarchy.
Now, i tried to include some variables in the beginning of a play (at “pre_tasks” phase, but i don’t thing it’s relevant), to override some
parts of existing dicts with piece of information regarding other present hosts (e.g. IPs for standby servers). It didn’t succeed.
Consider the following example:
# vars file: play_vars/baz-a.yml
baz:
a: 1
# vars file: play_vars/baz-b.yml
baz:
b: 2
---
# playbook: play.yml
- hosts: all
pre_tasks:
- include_vars: play_vars/baz-a.yml
- include_vars: play_vars/baz-b.yml
tasks:
- debug: var=baz
When playing play.yml, i get: “baz”: {“b”: 2} while expecting “baz”: {“a”:1, “b”:2}.
Is this normal? Note, this is happening under hash_behavior=merge.