Merge variables (dicts, lists) with same names from different yml files

Hi,

I need to loop over a directory with yml files all containing the same variable names (dicts, list, simple vars) e.g.

---- file1.yml ----

serviceconf:
document:
xxx: “{{ ansible_hostname }}”:8080

proxyconf:

  • /api/document

---- file2.yml ----
serviceconf:
portalcode:
val: “{{ binary_content_dir }}/special”

proxyconf:

  • /api/portalcode
  • /api/imports

And would like to have as result:

serviceconf:

document:
xxx: “{{ ansible_hostname }}”:8080

portalcode:
val: “{{ binary_content_dir }}/special”

proxyconf:

  • /api/document1

  • /api/other1

  • /api/portalcode

  • /api/imports

While searching on google, I found include_vars_merged action plugin (https://gist.github.com/udondan/b730206056a018cf9838) which I though could be suitable for my task - but unfortunatly it is not compatible with Ansible 2+.

My question: Is there a possiblity to do the desired task (with standard ansible means) or has someone developed a similiar include_vars_merged for Ansible 2.7+ and like to share it?

Tnx in advance
Frank

I think this issue is because of you are trying to merge different data format please check you data format you have used at different places like group_vars and vars.

Regards/Surjeet

Hi Frank,
There is an option you can add to the default section of the ansible.cfg to merge the results instead of replacing them which is the default.

hash_behaviour = replace

You can find more information at
https://docs.ansible.com/ansible/2.4/intro_configuration.html#hash-behaviour

Cheers,
Tony Chia