merge dicts

32 views
Skip to first unread message

Punit Jain

unread,
Jun 20, 2019, 12:50:42 PM6/20/19
to ansible...@googlegroups.com
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

Dick Visser

unread,
Jun 21, 2019, 12:25:53 AM6/21/19
to ansible...@googlegroups.com
First you set ldapdata to {}, and at the end you say {{ldapdata}}. So that makes sense. 




Thanks
Punit

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAFXWBQKEmjsQ3PNz-hG5QrqfNCKepooe0rA2tsc_ijT%3D8Taevw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
--
Sent from a mobile device - please excuse the brevity, spelling and punctuation.

Punit Jain

unread,
Jun 21, 2019, 12:42:08 AM6/21/19
to ansible...@googlegroups.com
But it is not working. Adding extra {} . Am I doing something wrong 

Dick Visser

unread,
Jun 21, 2019, 1:22:53 AM6/21/19
to ansible...@googlegroups.com
What do you mean by ‘not working’?
What do you want to achieve?



For more options, visit https://groups.google.com/d/optout.

Punit Jain

unread,
Jun 21, 2019, 1:50:37 AM6/21/19
to ansible...@googlegroups.com
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




Punit Jain

unread,
Jun 21, 2019, 2:43:27 AM6/21/19
to ansible...@googlegroups.com
Please ignore my email. I understood my mistake.Issue Resolved. 
Reply all
Reply to author
Forward
0 new messages