# I get "failed to combine variables, expected dicts but got a 'AnsibleUnsafeText' and a 'dict' when I use folded or literal style

**URL:** <https://forum.ansible.com/t/i-get-failed-to-combine-variables-expected-dicts-but-got-a-ansibleunsafetext-and-a-dict-when-i-use-folded-or-literal-style/37687>\
**Category:** Ansible Project\
**Created:** [February 22, 2023, 11:51am UTC](https://forum.ansible.com/t/i-get-failed-to-combine-variables-expected-dicts-but-got-a-ansibleunsafetext-and-a-dict-when-i-use-folded-or-literal-style/37687 "2023-02-22T11:51:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Norbert\_Klamann](https://avatars.discourse-cdn.com/v4/letter/n/ce73a5/32.png) [@Norbert\_Klamann](https://forum.ansible.com/u/Norbert_Klamann)\
**Post date:** [February 22, 2023, 11:51am UTC](https://forum.ansible.com/t/i-get-failed-to-combine-variables-expected-dicts-but-got-a-ansibleunsafetext-and-a-dict-when-i-use-folded-or-literal-style/37687/1 "2023-02-22T11:51:30Z")

</div>

I want to copy some data from obne dictioneary to teh other and use a task like this, which works fine:

```auto

- name: Create dg_helper for usage information about data_groups
ansible.builtin.set_fact:
dg_helper: "{{ dg_helper| default({}) | combine( { item: {'handled_in': [], 'backed_up_in': [], 'content' : data_groups[item].content }} ) }}"
with_items:
"{{ data_groups }}"
no_log: true
tags: data_overview

```

When I used folded or literal style used folded stype and literal style, I get the above mentioned error :

```auto

- name: Create dg_helper for usage information about data_groups
ansible.builtin.set_fact:
dg_helper: |
"{{ dg_helper| default({}) | combine(
{ item:
{'handled_in':[], 'backed_up_in':[], 'content': data_groups[item].content }
}
) }}"
with_items:
"{{ data_groups }}"
tags: data_overview

```

This gives :

```auto
ansible-playbook --tags data_overview reports_scripts_pb.yml

PLAY [Generate Reports] ****************************************************************************************************************************************************************************************************************************

TASK [Create dg_helper for usage information about data_groups] ************************************************************************************************************************************************************************************
ok: [localhost] => (item=assets)
fatal: [localhost]: FAILED! => {"msg": "failed to combine variables, expected dicts but got a 'AnsibleUnsafeText' and a 'dict': \n\"\\"{'assets': {'handled_in': [], 'backed_up_in': [], 'content': 'Software, Graphiken, Fonts usw'}}\\"\n\"\n{\"audio\": {\"handled_in\": [], \"backed_up_in\": [], \"content\": \"Musik, H\u00f6rspiele, H\u00f6rb\u00fccher\"}}"}

```

Why is this ?

Thanks a lot

Norbert

---

<div class="post-metadata">

**Author:** ![Norbert\_Klamann](https://avatars.discourse-cdn.com/v4/letter/n/ce73a5/32.png) [@Norbert\_Klamann](https://forum.ansible.com/u/Norbert_Klamann)\
**Post date:** [February 22, 2023, 12:51pm UTC](https://forum.ansible.com/t/i-get-failed-to-combine-variables-expected-dicts-but-got-a-ansibleunsafetext-and-a-dict-when-i-use-folded-or-literal-style/37687/2 "2023-02-22T12:51:23Z")

</div>

I should show the source datastructure , i think . It looks like this:

```auto

data_groups: {
"assets": {content: "Software, Graphiken, Fonts usw", backup_required: true },
"audio": {content: "Musik, Hörspiele, Hörbücher", backup_required: true },
"fileserver": {content: "Samba-Konfguration", backup_required: true },
"fossil": {content: "Fossil-Repositories", backup_required: true }
}

```

And the error message suggests that it tried to,load the data from ‘audio’ in the entry for ‘assets’, but why ?

BTW changing the | operator above to \> does not change the problem

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [February 22, 2023, 12:54pm UTC](https://forum.ansible.com/t/i-get-failed-to-combine-variables-expected-dicts-but-got-a-ansibleunsafetext-and-a-dict-when-i-use-folded-or-literal-style/37687/3 "2023-02-22T12:54:07Z")

</div>

You are over quoting. When you switch to “|”-style, you should then remove the beginning and ending double-quotes.

---

<div class="post-metadata">

**Author:** ![Norbert\_Klamann](https://avatars.discourse-cdn.com/v4/letter/n/ce73a5/32.png) [@Norbert\_Klamann](https://forum.ansible.com/u/Norbert_Klamann)\
**Post date:** [February 22, 2023, 12:56pm UTC](https://forum.ansible.com/t/i-get-failed-to-combine-variables-expected-dicts-but-got-a-ansibleunsafetext-and-a-dict-when-i-use-folded-or-literal-style/37687/4 "2023-02-22T12:56:42Z")

</div>

Ah, many thanks . That did it !
