# Problem with Ansible user and home directory on remote computers, pm2 process manager

**URL:** <https://forum.ansible.com/t/problem-with-ansible-user-and-home-directory-on-remote-computers-pm2-process-manager/34262>\
**Category:** Ansible Project\
**Created:** [December 1, 2020, 9:54am UTC](https://forum.ansible.com/t/problem-with-ansible-user-and-home-directory-on-remote-computers-pm2-process-manager/34262 "2020-12-01T09:54:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![magnifito](https://avatars.discourse-cdn.com/v4/letter/m/848f3c/32.png) [@magnifito](https://forum.ansible.com/u/magnifito)\
**Post date:** [December 1, 2020, 9:54am UTC](https://forum.ansible.com/t/problem-with-ansible-user-and-home-directory-on-remote-computers-pm2-process-manager/34262/1 "2020-12-01T09:54:29Z")

</div>

Hello,  
I am an Ansible beginner. I am trying to start Python script in pm2 process manager on my computers.  
I think I have narrowed the problem to Ansible not knowing proper home directory.  
Become, become\_user, changing environment path in config or playbook does not solve the problem.

whoami returns my remote user, with become it returns root, while “echo $HOME” gives me /home/my\_pc\_user instead /home/remote\_user

**Here is my playbook:**

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [December 1, 2020, 10:21am UTC](https://forum.ansible.com/t/problem-with-ansible-user-and-home-directory-on-remote-computers-pm2-process-manager/34262/2 "2020-12-01T10:21:38Z")

</div>

> Hello,  
> I am an Ansible beginner. I am trying to start Python script in pm2 process manager on my computers.  
> I think I have narrowed the problem to Ansible not knowing proper home directory.  
> Become, become\_user, changing environment path in config or playbook does not solve the problem.
> 
> whoami returns my remote user, with become it returns root, while "echo $HOME" gives me /home/my\_pc\_user instead  
> /home/remote\_user

1. Lookups always take place on the Ansible controller  
2. Use command module instead of shell unless you have a very good reason to not use command  
3. FileNotFoundError: [Errno 2] No such file or directory: 'iwconfig': 'iwconfig'  
&nbsp;&nbsp;&nbsp;iwconfig is in /usr/sbin, so that is probably missing in the $PATH Ansible uses (different from a regular ssh shell)

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![magnifito](https://avatars.discourse-cdn.com/v4/letter/m/848f3c/32.png) [@magnifito](https://forum.ansible.com/u/magnifito)\
**Post date:** [December 2, 2020, 11:55am UTC](https://forum.ansible.com/t/problem-with-ansible-user-and-home-directory-on-remote-computers-pm2-process-manager/34262/3 "2020-12-02T11:55:18Z")

</div>

Hello,  
Thank your for your reply.  
I have looked at my problem again and found out I was using **"** instead **’** while having a command with variable. Now the problem is clear.

data@pc:~/tester$ ansible tv -a ‘echo $HOME’  
10.10.20.254 | CHANGED | rc=0 \>\>  
/home/tester  
data@pc:~/tester$ ansible tv -a ‘echo $PATH’  
10.10.20.254 | CHANGED | rc=0 \>\>  
/usr/local/bin:/usr/bin:/bin:/usr/games

Ad 1.&3. The path to home was correct all the time, but my command while searching for solution was not. iwconfig is located inside /sbin/ which is not in known paths.  
How I can permanently add a path to /sbin/ or other directories unavailable to Ansible?

Ad 2. I was using a “command” at the beginning but switched to a “shell” thinking it was a part of my problem.

Best regards,  
Greg

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [December 2, 2020, 12:04pm UTC](https://forum.ansible.com/t/problem-with-ansible-user-and-home-directory-on-remote-computers-pm2-process-manager/34262/4 "2020-12-02T12:04:17Z")

</div>

> Hello,  
> Thank your for your reply.  
> I have looked at my problem again and found out I was using \*"\* instead \*'\* while having a command with variable. Now  
> the problem is clear.
> 
> data@pc:~/tester$ ansible tv -a 'echo $HOME'  
> 10.10.20.254 | CHANGED | rc=0 \>\>  
> /home/tester  
> data@pc:~/tester$ ansible tv -a 'echo $PATH'  
> 10.10.20.254 | CHANGED | rc=0 \>\>  
> /usr/local/bin:/usr/bin:/bin:/usr/games
> 
> Ad 1.&3. The path to home was correct all the time, but my command while searching for solution was not. iwconfig is  
> located inside /sbin/ which is not in known paths.  
> How I can permanently add a path to /sbin/ or other directories unavailable to Ansible?
> 
> Ad 2. I was using a "command" at the beginning but switched to a "shell" thinking it was a part of my problem.

You can set the PATH variable for the whole playbook or just for one task with:

&nbsp;&nbsp;&nbsp;&nbsp;environment:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PATH: /usr/local/bin:/usr/bin:/bin:/usr/games:/sbin

Or alternatively add a symlink to iwconfig in /usr/bin or another directory in $PATH.

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke
