Hello,
In the ‘vars’ directory of my ‘base-user’ role, I added :
homedir_prefix: “{% if user != ‘root’%}/home{% endif %}”
I thought I would be able to have the correct homedir for all users this way but I can’t seem to make it work.
The following works :
- name: bash history conservation for user ‘{{ user }}’
lineinfile: dest={% if user != “root”%}/home{% endif %}/{{ user }}/.bashrc
regexp=“PROMPT_COMMAND”
line=“export PROMPT_COMMAND=‘history -a; history -c; history -r’”
sudo_user: “{{ user }}”
but I would like to extract the {% if user != “root”%}/home{% endif %} part.
Did you find a solution for this ?
You can do this
vars:
homedir: “{% if user != ‘root’ }/home/{{user}}{% else %}/root{% end if %}”
…
dest={{ homedir }}/.bashrc
Hello,
I tried
role/myrole/vars/main.yml:
homedir: “{% if user != ‘root’ }/home/{{user}}{% else %}/root{% end if %}”
role/myrole/tasks/main.yml
…
dest={{ homedir }}/.bashrc
but I get an error :
failed: […] => {“failed”: true, “item”: “”}
msg: this module requires key=value arguments ([‘dest={%’, ‘if’, ‘user’, ‘!=’, ‘root’, ‘}/home/{{user}}{%’, ‘else’, ‘%}/root{%’, ‘end’, ‘if’, ‘%}/.bashrc’, ’
trying with
…
dest=‘{{ homedir }}/.bashrc’
I get :
failed: […] => {“failed”: true, “item”: “”, “rc”: 257}
msg: Destination {% if user != root }/home/{{user}}{% else %}/root{% end if %}/.bashrc does not exist !
I don’t understand why the templating is not working.
I also tried with
role/myrole/vars/main.yml:
homedir: “{% if user != ‘root’ }/home/{{user}}{% else %}/root{% endif %}”
(note the “endif” instead of “end if”)
Am I missing something ?
Thanks for your help
Ok I found the error :
instead of :
vars:
homedir: “{% if user != ‘root’ }/home/{{user}}{% else %}/root{% end if %}”
use
vars:
homedir: “{% if user != ‘root’ %}/home/{{user}}{% else %}/root{% endif %}”
Those typos always seem so obvious after they’re found
Sorry for the noise.