Conditional variables

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.

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