# Join two variables and store in new variable in playbook

**URL:** <https://forum.ansible.com/t/join-two-variables-and-store-in-new-variable-in-playbook/30592>\
**Category:** Ansible Project\
**Created:** [June 18, 2019, 1:11pm UTC](https://forum.ansible.com/t/join-two-variables-and-store-in-new-variable-in-playbook/30592 "2019-06-18T13:11:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shruthilaya\_Gunda](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@Shruthilaya\_Gunda](https://forum.ansible.com/u/Shruthilaya_Gunda)\
**Post date:** [June 18, 2019, 1:11pm UTC](https://forum.ansible.com/t/join-two-variables-and-store-in-new-variable-in-playbook/30592/1 "2019-06-18T13:11:51Z")

</div>

I want to join two variables in ansible playbook to store in another variable to use it further in the code.

I tried as below, but encountering errors

- debug: msg = “{{ ver1 ~ ver2 }}”  
set\_fact:  
version{{msg}}

ERROR! conflicting action statements (debug, set\_fact)

The error appears to have been in ‘/home/devOps/upgradeTeradata/shruthi.yml’: line 63, column 7, but may  
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

# - debug: msg = “value is {{ ver1 ~ ver2 }}”

- debug: msg = “{{ ver1 ~ ver2 }}”  
^ here  
We could be wrong, but this one looks like it might be an issue with  
missing quotes. Always quote template expression brackets when they  
start a value. For instance:

with\_items:

- {{ foo }}

Should be written as:

with\_items:

- “{{ foo }}”

please help…

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [June 19, 2019, 9:19am UTC](https://forum.ansible.com/t/join-two-variables-and-store-in-new-variable-in-playbook/30592/2 "2019-06-19T09:19:41Z")

</div>

You can only have one module in one task. Debug is a module and set\_fact is a module.  
Debug is just for printing test to the console of the user running the play/playbook.

When using Ansible style YAML you can't have spaces in front or after the equal sign.  
So your debug need to be written like this

- debug: msg="{{ ver1 ~ ver2 }}"

The msg in debug is not a variable, it's a parameter to debug to specify what message you would like to print out to the user.

set\_fact must be it own task, all task start with a dash.

- set\_fact:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;version: '{{ ver1 ~ ver2 }}'

or

- set\_fact:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;version: '{{ ver1 }}{{ ver2 }}'

Then you can print out this version variable with debug like so

- debug: msg="The version is {{ version }}"

or

- debug: var=version

---

<div class="post-metadata">

**Author:** ![Shruthilaya\_Gunda](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@Shruthilaya\_Gunda](https://forum.ansible.com/u/Shruthilaya_Gunda)\
**Post date:** [June 19, 2019, 11:18am UTC](https://forum.ansible.com/t/join-two-variables-and-store-in-new-variable-in-playbook/30592/3 "2019-06-19T11:18:20Z")

</div>

Thankyou so much for explaining me so patiently. Am new to ansible.
