When I sudo as a user, ansible_env does not have the correct HOME set - "/ root" . However, if I repeat the HOME env variable, it is correct - "/ var / lib / pgsql" . Is there any other way to get sudo'ed's home directory?
In addition, I already set "sudo_flags = -H" to ansible.cfg, and I cannot log in as the postgres user.
- name: ansible_env->HOME sudo: yes sudo_user: postgres debug: msg="{{ ansible_env.HOME }}" - name: echo $HOME sudo: yes sudo_user: postgres shell: "echo $HOME" register: postgres_homedir - name: postgres_homedir.stdout sudo: yes sudo_user: postgres debug: msg="{{ postgres_homedir.stdout }}"
Result:
TASK: [PostgreSQL | ansible_env->HOME] **************************************** ok: [postgres] => { "msg": "/root" } TASK: [PostgreSQL | echo $HOME] *********************************************** changed: [postgres] TASK: [PostgreSQL | postgres_homedir.stdout] ********************************** ok: [postgres] => { "msg": "/var/lib/pgsql" }
source share