# Concatenation of vars ?

**URL:** <https://forum.ansible.com/t/concatenation-of-vars/11583>\
**Category:** Ansible Project\
**Created:** [May 29, 2012, 11:34am UTC](https://forum.ansible.com/t/concatenation-of-vars/11583 "2012-05-29T11:34:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ansibleguest](https://avatars.discourse-cdn.com/v4/letter/a/b4bc9f/32.png) [@ansibleguest](https://forum.ansible.com/u/ansibleguest)\
**Post date:** [May 29, 2012, 11:34am UTC](https://forum.ansible.com/t/concatenation-of-vars/11583/1 "2012-05-29T11:34:32Z")

</div>

Hi,

i am new to ansible and just rewrote some puppet-recipe with ansible  
now...  
I am looking for a way to reassign and also concatenate variables ?

&nbsp;&nbsp;user: myuser

&nbsp;&nbsp;vars:  
&nbsp;&nbsp;&nbsp;&nbsp;base: /opt/productsuite

&nbsp;&nbsp;vars\_files:  
&nbsp;&nbsp;&nbsp;&nbsp;- vars/product.yml # this brings a piece of a directory-path  
also: product: sqldb

&nbsp;&nbsp;tasks:  
&nbsp;&nbsp;&nbsp;&nbsp;- action file path=$base/$user/$product/bin state=directory owner=  
$user group=$group

So the directory string is long and i would like to replace it with a  
new variable to make the playbook even shorter.  
&nbsp;&nbsp;$thepath = "$base/$user/$product"  
&nbsp;&nbsp;&nbsp;action file path=$thepath/bin state=directory owner=$user group=  
$group

What i also cannot do is to invoke vars block a second time for  
assignment of variables again which would help:  
&nbsp;&nbsp;vars:  
&nbsp;&nbsp;vars\_files:  
&nbsp;&nbsp;vars:

Some ideas ?

(ansible-0.3.1-1.el6, Centos 6.2)

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [May 29, 2012, 12:05pm UTC](https://forum.ansible.com/t/concatenation-of-vars/11583/2 "2012-05-29T12:05:11Z")

</div>

> Hi,
> 
> i am new to ansible and just rewrote some puppet-recipe with ansible  
> now…  
> I am looking for a way to reassign and also concatenate variables ?

There’s no way to add variables together and store them in other variables presently.

> What i also cannot do is to invoke vars block a second time for  
> assignment of variables again which would help:  
> vars:  
> vars\_files:  
> vars:

This isn’t possible because a playbook is a YAML document and each play is a dictionary/hash data structure.

Each element can only occur once and are actually unordered, though there is some business logic that does handle order.
