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

1,624 views
Skip to first unread message

Norbert Klamann

unread,
Feb 22, 2023, 6:51:30 AM2/22/23
to Ansible Project
I want to copy some data from obne dictioneary to teh other and use a task like this, which works fine:

```
    - 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 :
```
    - 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 :

```
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




Norbert Klamann

unread,
Feb 22, 2023, 7:51:24 AM2/22/23
to Ansible Project
I should show the source datastructure , i think . It looks like this:
```
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

Todd Lewis

unread,
Feb 22, 2023, 7:54:07 AM2/22/23
to Ansible Project
You are over quoting. When you switch to "|"-style, you should then remove the beginning and ending double-quotes.

Norbert Klamann

unread,
Feb 22, 2023, 7:56:43 AM2/22/23
to Ansible Project
Ah, many thanks . That did it !
Reply all
Reply to author
Forward
0 new messages