# setting variables depending on other variable value

**URL:** <https://forum.ansible.com/t/setting-variables-depending-on-other-variable-value/21492>\
**Category:** Ansible Project\
**Created:** [May 19, 2016, 2:47pm UTC](https://forum.ansible.com/t/setting-variables-depending-on-other-variable-value/21492 "2016-05-19T14:47:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![fanvalt](https://avatars.discourse-cdn.com/v4/letter/f/2bfe46/32.png) [@fanvalt](https://forum.ansible.com/u/fanvalt)\
**Post date:** [May 19, 2016, 2:47pm UTC](https://forum.ansible.com/t/setting-variables-depending-on-other-variable-value/21492/1 "2016-05-19T14:47:14Z")

</div>

Hello,

I would like to set in my playbook a variable depending on the ansible\_user value.

If I set it twice, an error occurs, how can I write it:

vars:  
rep\_user: {{ ansible\_user }}  
rep\_user: /home/{{ ansible\_user }}  
when: ansible\_user == fval

Si I would test my playbook with the fval ansible\_user to deploy in my home directory, and when I will tun it for good, it will deploy on another directory.

Thank you

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [May 19, 2016, 5:00pm UTC](https://forum.ansible.com/t/setting-variables-depending-on-other-variable-value/21492/2 "2016-05-19T17:00:55Z")

</div>

when: ONLY applies to tasks, for vars use ternary filter.

rep\_user: “{{ (ansible\_user == fval)|ternary(‘/home/’ + ansible\_user, ansible\_user) }}”

---

<div class="post-metadata">

**Author:** ![fanvalt](https://avatars.discourse-cdn.com/v4/letter/f/2bfe46/32.png) [@fanvalt](https://forum.ansible.com/u/fanvalt)\
**Post date:** [May 23, 2016, 8:50am UTC](https://forum.ansible.com/t/setting-variables-depending-on-other-variable-value/21492/3 "2016-05-23T08:50:55Z")

</div>



---

<div class="post-metadata">

**Author:** ![fanvalt](https://avatars.discourse-cdn.com/v4/letter/f/2bfe46/32.png) [@fanvalt](https://forum.ansible.com/u/fanvalt)\
**Post date:** [May 24, 2016, 10:46am UTC](https://forum.ansible.com/t/setting-variables-depending-on-other-variable-value/21492/4 "2016-05-24T10:46:47Z")

</div>

I did bypass the issue by using a variable that I set previously when testing to /home/fval  
When I will test for real, I will set it to {{ ansible\_user }}
