# Merging two dictionaries from different files.

**URL:** <https://forum.ansible.com/t/merging-two-dictionaries-from-different-files/35415>\
**Category:** Ansible Project\
**Created:** [June 25, 2021, 6:49pm UTC](https://forum.ansible.com/t/merging-two-dictionaries-from-different-files/35415 "2021-06-25T18:49:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Steve\_Button](https://avatars.discourse-cdn.com/v4/letter/s/b5a626/32.png) [@Steve\_Button](https://forum.ansible.com/u/Steve_Button)\
**Post date:** [June 25, 2021, 6:49pm UTC](https://forum.ansible.com/t/merging-two-dictionaries-from-different-files/35415/1 "2021-06-25T18:49:15Z")

</div>

I’m have two files one which represents the default case, and another for a specific environment.

variables/all.yml:  
all:  
vars:  
myapp:  
COMPONENT\_NAME: “app”  
(and another hundred or so default settings for myapp)

variables/devenv.yml:  
all:  
vars:  
myapp:  
PORT\_NUMBER: 5678

I want Ansible to merge these inside a role :-

roles/tasks/main.yml:

- name: Create working Directory  
file:  
path: “{{ WORKING\_DIR }}/{{ Values.COMPONENT\_NAME }}”  
state: directory  
recurse: yes

Sorry, my Ansible is a little rusty. I guess I need to use a combine to merge the two yaml dictionaries, but not sure where to put it?

Have been looking at this solution, but it’s not quite what I need.

Also, the way I’ve inherited it the variables folder is shared across a bunch of roles.

Hope this is clear!? I’m just trying to figure out where I should utilise “combine”

Thanks!

---

<div class="post-metadata">

**Author:** ![Steve\_Button1](https://avatars.discourse-cdn.com/v4/letter/s/839c29/32.png) [@Steve\_Button1](https://forum.ansible.com/u/Steve_Button1)\
**Post date:** [June 25, 2021, 6:57pm UTC](https://forum.ansible.com/t/merging-two-dictionaries-from-different-files/35415/2 "2021-06-25T18:57:05Z")

</div>

When I said “This solution” I meant to post the link…

[https://groups.google.com/g/ansible-project/c/pGbRYZyqxZ4](https://groups.google.com/g/ansible-project/c/pGbRYZyqxZ4)
