# ansible concatenate variables

**URL:** <https://forum.ansible.com/t/ansible-concatenate-variables/30025>\
**Category:** Ansible Project\
**Created:** [March 29, 2019, 3:14pm UTC](https://forum.ansible.com/t/ansible-concatenate-variables/30025 "2019-03-29T15:14:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Krzysztof\_Kulaj](https://avatars.discourse-cdn.com/v4/letter/k/2acd7d/32.png) [@Krzysztof\_Kulaj](https://forum.ansible.com/u/Krzysztof_Kulaj)\
**Post date:** [March 29, 2019, 3:14pm UTC](https://forum.ansible.com/t/ansible-concatenate-variables/30025/1 "2019-03-29T15:14:18Z")

</div>

Hello,

I have simple question about concatenating variables in Ansible.

I am using a role [https://github.com/singleplatform-eng/ansible-users](https://github.com/singleplatform-eng/ansible-users) . I would like to define root user in group\_vars/all . It works well.

The problem is, when I would like to specify additional users for group of machines, or single host. If I define users variable, then the users in group\_vars/all variable is not seen.

Is there any way to concatenate the variables in this scenerio?

Best Regards,

Krzysztof Kulaj

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [April 3, 2019, 9:35pm UTC](https://forum.ansible.com/t/ansible-concatenate-variables/30025/2 "2019-04-03T21:35:27Z")

</div>

Variables are lazy loaded so :

vars:  
&nbsp;&nbsp;x: '{{ x + [1] }}'

will not work since the value of x is not known before you try to use  
x creating a self referential loop.

But you can get around it with `set_fact` as we evaluate variables at  
the time of module execution and set\_fact is a module that sets a new  
variable:

set\_fact:  
&nbsp;&nbsp;&nbsp;&nbsp;x : '{{ x + [1] }}'

this defines a 'new x' that is the 'old x + [1]' (add a list with the  
number 1 as an element, assumes x is already a list, you might use
