merge dicts

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

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.

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

What do you mean by ‘not working’?

What do you want to achieve?

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

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