# Join two variables

**URL:** <https://forum.ansible.com/t/join-two-variables/33015>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [May 24, 2020, 4:22pm UTC](https://forum.ansible.com/t/join-two-variables/33015 "2020-05-24T16:22:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Geo\_P.C](https://avatars.discourse-cdn.com/v4/letter/g/b3f665/32.png) [@Geo\_P.C](https://forum.ansible.com/u/Geo_P.C)\
**Post date:** [May 24, 2020, 4:22pm UTC](https://forum.ansible.com/t/join-two-variables/33015/1 "2020-05-24T16:22:37Z")

</div>

I have two variable definition files as follows

\*vars.yml\*  
aws\_common\_tags:  
Project: "{{ project\_name }}"  
Application: "{{ application\_name }}"  
Region: "{{ aws\_region }}"  
Ansible: "Yes"

\*instance.yml\*  
ec2\_instance\_tags:  
&nbsp;&nbsp;&nbsp;&nbsp;environment\_name: dev

Now in task.yml I am tryin to create aws ec2 instance with all tags but its  
not working.

ec2:  
&nbsp;&nbsp;&nbsp;&nbsp;key\_name: "{{ keypair\_name }}"  
&nbsp;&nbsp;&nbsp;&nbsp;instance\_type: "{{ ec2\_instance\_type }}"  
&nbsp;&nbsp;&nbsp;&nbsp;instance\_tags: "{{ aws\_common\_tags + ec2\_instance\_tags }}"

We are getting the following error:

"tags": {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"Ansible": "Yes",  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"Application": "webserver",  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"Project": "document\_upload",  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"Region": "us-west-2"  
&nbsp;&nbsp;&nbsp;&nbsp;},

fatal: [localhost]: FAILED! =\> {  
&nbsp;&nbsp;&nbsp;&nbsp;"msg": "Unexpected templating type error occurred on ({{  
aws\_common\_tags + ec2\_instance\_tags }}): unsupported operand type(s) for +:  
'dict' and 'dict'"  
}  
Thanks  
Geo

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [May 24, 2020, 5:00pm UTC](https://forum.ansible.com/t/join-two-variables/33015/2 "2020-05-24T17:00:03Z")

</div>

The error is correct. You can’t add one dict to another using the + operand.

Use combine instead:

[https://docs.ansible.com/ansible/latest/user\_guide/playbooks\_filters.html#combining-hashes-dictionaries](https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#combining-hashes-dictionaries)

---

<div class="post-metadata">

**Author:** ![Geo\_P.C](https://avatars.discourse-cdn.com/v4/letter/g/b3f665/32.png) [@Geo\_P.C](https://forum.ansible.com/u/Geo_P.C)\
**Post date:** [May 25, 2020, 4:23am UTC](https://forum.ansible.com/t/join-two-variables/33015/3 "2020-05-25T04:23:07Z")

</div>

Thanks… Working fine now.
