Conditional variables

22 views
Skip to first unread message

Pavel Stratil

unread,
Jun 14, 2016, 8:09:39 PM6/14/16
to Ansible Project
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.


Brian Coca

unread,
Jun 15, 2016, 12:05:20 PM6/15/16
to ansible...@googlegroups.com
 file: path={{ (ssh_keygen_user == root)|ternary('/root','/home/' + ansible_user)}}/.ssh state=directory mode=0700 owner={{ ansible_user }} group={{ ansible_user }}



----------
Brian Coca
Reply all
Reply to author
Forward
0 new messages