# Combine 2 dictionary in ansible / jinja2 (simple)

**URL:** <https://forum.ansible.com/t/combine-2-dictionary-in-ansible-jinja2-simple/32723>\
**Category:** Ansible Project\
**Created:** [April 18, 2020, 5:47am UTC](https://forum.ansible.com/t/combine-2-dictionary-in-ansible-jinja2-simple/32723 "2020-04-18T05:47:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tom\_Cheung](https://avatars.discourse-cdn.com/v4/letter/t/ed655f/32.png) [@Tom\_Cheung](https://forum.ansible.com/u/Tom_Cheung)\
**Post date:** [April 18, 2020, 5:47am UTC](https://forum.ansible.com/t/combine-2-dictionary-in-ansible-jinja2-simple/32723/1 "2020-04-18T05:47:12Z")

</div>

Hi friends,

I want to use ansible to merge below 2 dictionary to become 1.  
I have been stucking for few days already. Headache.

I have 2 variables now.

**1. variable “my\_directories”:**

`{ "directoryA": ["/bar/foo/file1.txt", "/bar/foo/file2.txt"], "directoryB": ["/bar/baz/file3.txt", "/bar/baz/file4.txt", "/bar/baz/file5.txt"] }`

**2. variable “my\_filecontents”:**

`{ "/bar/foo/file1.txt": "file1Content", "/bar/foo/file2.txt": "file2Content", "/bar/baz/file3.txt": "file3Content", "/bar/baz/file4.txt": "file4Content", "/bar/baz/file5.txt": "file5Content" }`

i want to merge it to become:

**Result variable: “my\_result”**

`  
{  
“directoryA”: {  
“/bar/foo/file1.txt”: “file1Content”,  
“/bar/foo/file2.txt”: “file2Content”  
},  
“directoryB”: {  
“/bar/baz/file3.txt”: “file3Content”,  
“/bar/baz/file4.txt”: “file4Content”,  
“/bar/baz/file5.txt”: “file5Content”  
}  
}

`

The directories and files could be dynamic.  
I tried so many codes but still did not work.

Thank you!
