# merge dicts

**URL:** <https://forum.ansible.com/t/merge-dicts/30616>\
**Category:** Ansible Project\
**Created:** [June 20, 2019, 4:50pm UTC](https://forum.ansible.com/t/merge-dicts/30616 "2019-06-20T16:50:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Punit\_Jain](https://avatars.discourse-cdn.com/v4/letter/p/e56c9b/32.png) [@Punit\_Jain](https://forum.ansible.com/u/Punit_Jain)\
**Post date:** [June 20, 2019, 4:50pm UTC](https://forum.ansible.com/t/merge-dicts/30616/1 "2019-06-20T16:50:19Z")

</div>

Hi,

Seems I am missing something really simple.

ldap\_data: |  
{% set ldapdata = {} -%}  
{% if ldap\_content is defined -%}  
{{ ldapdata | combine({‘a’:10}, recursive=‘True’) }}  
{%- endif -%}  
{{ldapdata}}

populates ldap\_data with value:  
“ldap\_data”: “{‘a’: 10}\*\*{}\*\*n”

Dont understand why this last {} appears in output ?

Thanks  
Punit

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [June 21, 2019, 4:25am UTC](https://forum.ansible.com/t/merge-dicts/30616/2 "2019-06-21T04:25:21Z")

</div>

> Hi,
> 
> Seems I am missing something really simple.
> 
> ldap\_data: |  
> {% set ldapdata = {} -%}  
> {% if ldap\_content is defined -%}  
> {{ ldapdata | combine({‘a’:10}, recursive=‘True’) }}  
> {%- endif -%}  
> {{ldapdata}}
> 
> populates ldap\_data with value:  
> “ldap\_data”: “{‘a’: 10}\*\*{}\*\*n”
> 
> Dont understand why this last {} appears in output ?

First you set ldapdata to {}, and at the end you say {{ldapdata}}. So that makes sense.

---

<div class="post-metadata">

**Author:** ![Punit\_Jain](https://avatars.discourse-cdn.com/v4/letter/p/e56c9b/32.png) [@Punit\_Jain](https://forum.ansible.com/u/Punit_Jain)\
**Post date:** [June 21, 2019, 4:41am UTC](https://forum.ansible.com/t/merge-dicts/30616/3 "2019-06-21T04:41:48Z")

</div>

But it is not working. Adding extra {} . Am I doing something wrong

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [June 21, 2019, 5:22am UTC](https://forum.ansible.com/t/merge-dicts/30616/4 "2019-06-21T05:22:21Z")

</div>

What do you mean by ‘not working’?

What do you want to achieve?

---

<div class="post-metadata">

**Author:** ![Punit\_Jain](https://avatars.discourse-cdn.com/v4/letter/p/e56c9b/32.png) [@Punit\_Jain](https://forum.ansible.com/u/Punit_Jain)\
**Post date:** [June 21, 2019, 5:50am UTC](https://forum.ansible.com/t/merge-dicts/30616/5 "2019-06-21T05:50:09Z")

</div>

Here is the thing:

vars:  
test\_data:  
{% set testdata={} -%}  
{{ tesdata | combine({‘a’: 10, ‘b’: 20}, recursive=‘True’) }}  
{{ testdata}}

task:

- name: value of test\_data  
debug:  
var=test\_data

The output is:

ok: [10.3.12.2] =\> {

“test\_data” : "{‘a’: 10, ‘b’: 20} **\n{}\n"**

The extra char is something i dont want. I get the feeling I am missing something basic.  
Any ideas ?

Regards,  
Punit

---

<div class="post-metadata">

**Author:** ![Punit\_Jain](https://avatars.discourse-cdn.com/v4/letter/p/e56c9b/32.png) [@Punit\_Jain](https://forum.ansible.com/u/Punit_Jain)\
**Post date:** [June 21, 2019, 6:43am UTC](https://forum.ansible.com/t/merge-dicts/30616/6 "2019-06-21T06:43:08Z")

</div>

Please ignore my email. I understood my mistake.Issue Resolved.
