# Error when combining variables

**URL:** <https://forum.ansible.com/t/error-when-combining-variables/17608>\
**Category:** Ansible Project\
**Created:** [February 24, 2015, 1:21pm UTC](https://forum.ansible.com/t/error-when-combining-variables/17608 "2015-02-24T13:21:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jiri](https://avatars.discourse-cdn.com/v4/letter/j/53a042/32.png) [@Jiri](https://forum.ansible.com/u/Jiri)\
**Post date:** [February 24, 2015, 1:21pm UTC](https://forum.ansible.com/t/error-when-combining-variables/17608/1 "2015-02-24T13:21:19Z")

</div>

I’m getting the following error:

`  
ERROR: failed to combine variables, expected dicts but got a ‘dict’ and a ‘str’

`

with the following setup:

`

# ./site.yaml

---

<div class="post-metadata">

**Author:** ![Jiri](https://avatars.discourse-cdn.com/v4/letter/j/53a042/32.png) [@Jiri](https://forum.ansible.com/u/Jiri)\
**Post date:** [February 24, 2015, 2:30pm UTC](https://forum.ansible.com/t/error-when-combining-variables/17608/2 "2015-02-24T14:30:58Z")

</div>

I have created the following pull request to fix this issue:  
[https://github.com/ansible/ansible/pull/10328](https://github.com/ansible/ansible/pull/10328)

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [February 24, 2015, 2:53pm UTC](https://forum.ansible.com/t/error-when-combining-variables/17608/3 "2015-02-24T14:53:29Z")

</div>

​That reason seems to be, merging happens on higher-level internal  
variables (setup cache, various ​play vars, inventory vars, etc.)  
The merge\_hash then happens recursively, which is why you see that error,  
even if you don;t have the merge setting.

I'm not sure your proposed patch solves the deeper issue, only what happens  
in your case, and might potentially break other things.

The issue here is {{ my\_xxx }} being cast to a string instead of a  
dictionary.

---

<div class="post-metadata">

**Author:** ![Jiri](https://avatars.discourse-cdn.com/v4/letter/j/53a042/32.png) [@Jiri](https://forum.ansible.com/u/Jiri)\
**Post date:** [February 24, 2015, 3:07pm UTC](https://forum.ansible.com/t/error-when-combining-variables/17608/4 "2015-02-24T15:07:13Z")

</div>

Thanks for your comments, Serge.

> I’m not sure your proposed patch solves the deeper issue, only what happens in your case, and might potentially break other things.

It depends for what the function is used. If it’s used to merge variables on the same level (vars\_files, vars, …), then it should not break anything.

> The issue here is `{{ my_xxx }}` being cast to a string instead of a dictionary.

Yes, that’s exactly the problem. It’s interesting that in the case of lists it works just fine. One would expect that the same concept could be used for lists as well as for dicts.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [February 24, 2015, 3:19pm UTC](https://forum.ansible.com/t/error-when-combining-variables/17608/5 "2015-02-24T15:19:40Z")

</div>

I am currently testing, [https://github.com/ansible/ansible/pull/10329](https://github.com/ansible/ansible/pull/10329)  
\<= attempt to correct the deeper issue, this is has been in 1.8 since  
a re-factoring on variable merging started using the wrong function.

Any help testing this PR will be appreciated, this can have far  
reaching consequences.
