Current version of Ansible (1.7.1) does not merge hashes in the include_vars
task even if told so via hash_behaviour = merge
in your ansible.cfg. ansible/ansible#9116
This action plugin will merge hashes no matter how you have configured your hash_behaviour
.
Save include_vars_merged.py to library/plugins/action/include_vars_merged.py
Save include_vars_merged to library/custom/include_vars_merged
The library folder needs to be on the same level as your playbook
Facts are merged in the runner and not in the plugin. You can access and modify those facts in the plugin when you call include_vars_merged for each file in a separate task, like so:
- include_vars_merged: /path/to/file-A.yml
- include_vars_merged: /path/to/file-B.yml
Though when called in a loop (e.g. with
) each task is executed in parallel and at execution time these facts are not yet available. You can't merge what you can't access. Therefore the facts are additionally buffered in the parents runner object.
- include_vars_merged: /path/to/{{ item }}
with:
- file-A.yml
- file-B.yml
Thanks for that plugin, very useful!
I have fixed a small bug in this version where it was impossible to merge variables for host aliases.
You can take a look at my fork here:
https://gist.github.com/alexandrem/50c42da4345c4decef1c