Reputation: 110
I am encountering a problem where I am running the same tasks on 2 remote nodes and the directories that those commands are executed at are different.
If I run pwd
through Ansible on each remote host before this command, they return different paths. For example /usr
and /usr/src
. If I log into the remote host manually I go to /usr/src
for both (As specified in their configuration files).
Can anyone explain to me why is this happening? To what directory does Ansible go if you run a command without specifying a chdir
?
Upvotes: 0
Views: 736
Reputation: 39264
I would expect this difference to happen because, when login in manually, you have a .bashrc
that cd
you in the right folder in one of those two hosts, when Ansible does not source the .bashrc
file.
Per default, ssh, and, so, Ansible, logs you into the $HOME
folder of the user you define Ansible to connect with, which you can also find in /etc/passwd
Another reason I could see for this to happen would be because you use one user to log into the node but then become another one.
inventory.yml:
all:
hosts:
some.example.com:
ansible_user: some_user
playbook.yml:
- hosts: all
tasks:
- command: pwd # still you will be in /home/some_user
become: yes
become_user: some_other_user
Upvotes: 1