Member-only story
Case
Get the HOME environment variable of the executing user during sudo with ansible.
When sudo: yes
using with ansible, it {{ ansible_env.HOME }}
becomes root’s. This is a problem when you want to place files under the home directory of the execution user, such as when building a development environment. In ansible, the execution user name is {{ ansible_ssh_user }}
set to, so you can use this to get the HOME environment variable of the execution user and use it.
By pre_taskexecuting the above task with , {{ ansible_home }}
the HOME environment variable of the executing user is set, so you can use it from other tasks.
By the way, {{ ansible_ssh_user }}
it is connection: local
available without a problem because it is set even when.