# Conditional variables

**URL:** <https://forum.ansible.com/t/conditional-variables/21780>\
**Category:** Ansible Project\
**Created:** [June 15, 2016, 12:08am UTC](https://forum.ansible.com/t/conditional-variables/21780 "2016-06-15T00:08:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pavel\_Stratil](https://avatars.discourse-cdn.com/v4/letter/p/f07891/32.png) [@Pavel\_Stratil](https://forum.ansible.com/u/Pavel_Stratil)\
**Post date:** [June 15, 2016, 12:08am UTC](https://forum.ansible.com/t/conditional-variables/21780/1 "2016-06-15T00:08:15Z")

</div>

Hey all,

i’m trying to write a task to manage ssh keys. depending on that the ansible\_user, i want teo work either in /root/.ssh or /home/$user/.ssh. So I naively googled how to do that and only ended confused with

- set\_fact: userdir=“/home/{{ ansible\_user }}”  
when: ssh\_keygen\_user != “root”

- set\_fact: userdir=“/root”  
when: ssh\_keygen\_user == “root”

- name: Check .ssh dir  
file: path={{ userdir }}/.ssh state=directory mode=0700 owner={{ ansible\_user }} group={{ ansible\_user }}

when playing this, if fails because “path”: “/home//.ssh”, so obviously i’m not passing the right values. could you help out please? thanks in adavance, P.

---

<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:** [June 15, 2016, 4:05pm UTC](https://forum.ansible.com/t/conditional-variables/21780/2 "2016-06-15T16:05:11Z")

</div>

file: path={{ (ssh\_keygen\_user == root)|ternary(‘/root’,‘/home/’ + ansible\_user)}}/.ssh state=directory mode=0700 owner={{ ansible\_user }} group={{ ansible\_user }}
