setting variables depending on other variable value

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

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

rep_user: “{{ (ansible_user == fval)|ternary(‘/home/’ + ansible_user, ansible_user) }}”

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 }}