# Hash merging not working for me (hash\_behaviour = merge)

**URL:** <https://forum.ansible.com/t/hash-merging-not-working-for-me-hash-behaviour-merge/16306>\
**Category:** Ansible Project\
**Created:** [September 23, 2014, 11:12am UTC](https://forum.ansible.com/t/hash-merging-not-working-for-me-hash-behaviour-merge/16306 "2014-09-23T11:12:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel\_Schroeder](https://avatars.discourse-cdn.com/v4/letter/d/54ee81/32.png) [@Daniel\_Schroeder](https://forum.ansible.com/u/Daniel_Schroeder)\
**Post date:** [September 23, 2014, 11:12am UTC](https://forum.ansible.com/t/hash-merging-not-working-for-me-hash-behaviour-merge/16306/1 "2014-09-23T11:12:04Z")

</div>

Hello,

I want to merge hashes of config files. My _ansible.cfg_ includes this line:

`hash_behaviour = merge`

The _ansible.cfg_ file is in the same directory as my playbook, in other words, the current directly where I’m cd’ed in when running _ansible-playbook_. I confirmed it’s being used by adding a syntax error which ansible then complains about. _ANSIBLE\_CONFIG_ is empty so it should be the first and last to check.

But my hash is not merged, but overridden.

In my example I have 3 tasks:

`

- include\_vars: /path/to/file/A

- include\_vars: /path/to/file/B

- debug: var=test

`

Content of file A:  
`test:`

Content of file B:  
`test: b: 1`

When I run my playbook, this is the result:

`  
TASK: [include\_vars /path/to/file/A] \*\*\*  
ok: [test1.local]

TASK: [include\_vars /path/to/file/B] \*\*\*  
ok: [test1.local]

TASK: [debug var=test] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [test1.local] =\> {  
“test”: {  
“b”: 1  
}  
}  
`

Is this expected? How can I archive that the hash is merged and the resulting value is

`test: { "a": 1, "b": 1 }`

Thanks,  
Daniel

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [September 23, 2014, 12:20pm UTC](https://forum.ansible.com/t/hash-merging-not-working-for-me-hash-behaviour-merge/16306/2 "2014-09-23T12:20:46Z")

</div>

For starters, can you please share what version of Ansible you are using?

(It very well could be that include\_vars isn’t aware of hash merging, as it was a more recent addition and hash merging is used most frequently with different groups of inventory and such - I am not sure it makes sense here - but it may)

Thanks!

---

<div class="post-metadata">

**Author:** ![Daniel\_Schroeder](https://avatars.discourse-cdn.com/v4/letter/d/54ee81/32.png) [@Daniel\_Schroeder](https://forum.ansible.com/u/Daniel_Schroeder)\
**Post date:** [September 23, 2014, 12:46pm UTC](https://forum.ansible.com/t/hash-merging-not-working-for-me-hash-behaviour-merge/16306/3 "2014-09-23T12:46:23Z")

</div>

I’m running the most recent version available via homebrew, 1.7.1

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [September 23, 2014, 8:31pm UTC](https://forum.ansible.com/t/hash-merging-not-working-for-me-hash-behaviour-merge/16306/4 "2014-09-23T20:31:32Z")

</div>

Ok, I would file a ticket on this one, I think the include\_vars just needs to call our usual combine\_vars function.

Thanks!

–Michael

---

<div class="post-metadata">

**Author:** ![Daniel\_Schroeder](https://avatars.discourse-cdn.com/v4/letter/d/54ee81/32.png) [@Daniel\_Schroeder](https://forum.ansible.com/u/Daniel_Schroeder)\
**Post date:** [September 24, 2014, 11:18am UTC](https://forum.ansible.com/t/hash-merging-not-working-for-me-hash-behaviour-merge/16306/5 "2014-09-24T11:18:27Z")

</div>

Thanks Michael,

I filed the ticket here: [https://github.com/ansible/ansible/issues/9116](https://github.com/ansible/ansible/issues/9116)

Best,  
Daniel

---

<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:** [September 24, 2014, 12:41pm UTC](https://forum.ansible.com/t/hash-merging-not-working-for-me-hash-behaviour-merge/16306/6 "2014-09-24T12:41:33Z")

</div>

After a quick look in the action module, I see those vars are actually returned as ansible\_facts, so merging include\_vars would mean merging ansible\_facts AFAICS. (playbook/ **init**.py)
