Re: [ansible-project] Default shell behavior: Where are scripts executed? No such file or directory.

11 views
Skip to first unread message

Brian Coca

unread,
Mar 12, 2018, 4:56:20 PM3/12/18
to Ansible Project
shell executes on the remote machine, it does not look for any
resources 'local' to the controller, the 'working directory' depends
on login/become setup used on the target machine (normally
/home/<remote_user|become_user>.

But this is only important for relative paths.

--
----------
Brian Coca

Patrick Hunt

unread,
Mar 13, 2018, 8:29:49 AM3/13/18
to Ansible Project
Your subject line has a question in it, but the body does not.  Is your question "Where are scripts executed?"  If that is your question then yes, you're correct, it should be the home directory of the user you logged into the remote server with.  You can see by doing something like 


ansible servera
-m shell -a "ls"-u username

This will print the contents of the working directory when a user logs in.  Try it with the become options to see what the result is.  You can use an absolute path to call a script.  Or use the "chdir" option for shell, something like

---
- hosts: collector
  become
: true
  become_method
: su
  become_user
: root


  tasks
:


 
- name: stop eum
    shell
: bin/eum.sh stop
    args
:
      chdir
: /opt/AppDynamics/EUEM/eum-processor/



should guarantee that you're in the correct location.
Reply all
Reply to author
Forward
0 new messages