# unable to run a remote script with Ansible

**URL:** <https://forum.ansible.com/t/unable-to-run-a-remote-script-with-ansible/21540>\
**Category:** Ansible Project\
**Created:** [May 24, 2016, 1:23pm UTC](https://forum.ansible.com/t/unable-to-run-a-remote-script-with-ansible/21540 "2016-05-24T13:23:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![fanvalt](https://avatars.discourse-cdn.com/v4/letter/f/2bfe46/32.png) [@fanvalt](https://forum.ansible.com/u/fanvalt)\
**Post date:** [May 24, 2016, 1:23pm UTC](https://forum.ansible.com/t/unable-to-run-a-remote-script-with-ansible/21540/1 "2016-05-24T13:23:38Z")

</div>

Hello,

Here is my issue.  
I have a script start.sh with the following lines:

#!/bin/ksh  
dispatcher.sh --command=start --directory=…  
returnCode=$?  
exit $returnCode

the both scripts are in the same directory, with the 755 rights.

I run the task this way:

- name: Start  
shell: /bin/ksh start.sh  
args:  
chdir: “/{{ rep\_user }}/{{ openhrname }}/bin”  
register: start\_op

and I receive the following error:

fatal: [integ]: FAILED! =\> {“changed”: true, “cmd”: “/bin/ksh start.sh”, “delta”: “0:00:00.007132”, “end”: “2016-05-24 15:13:36.666862”, “failed”: true, “rc”: 127, “start”: “2016-05-24 15:13:36.659730”, “stderr”: “start\_openhr.sh[2]: dispatcher.sh: not found [No such file or directory]”, “stdout”: “”, “stdout\_lines”: , “warnings”: }

I have tried to run dos2unix on these files before, without success.  
I tried also many different ways to write the shell command, without any success:  
shell: /bin/ksh ./start.sh

shell: chdir=/{{ rep\_user }}/{{ openhrname }}/bin /bin/ksh ./start.sh

shell: /bin/ksh /{{ rep\_user }}/{{ openhrname }}/bin/start.sh

args:  
chdir: “/{{ rep\_user }}/{{ openhrname }}/bin”

etc …

when I run it manually from the directory where the files are installed, I have no issue.  
If I try to run the start.sh shell from another directory manually, the error occurs, which is normal.  
Could it be an issue with chdir command ? I run Ansible version 2.1.0

Thanks a lot,  
regards

---

<div class="post-metadata">

**Author:** ![fanvalt](https://avatars.discourse-cdn.com/v4/letter/f/2bfe46/32.png) [@fanvalt](https://forum.ansible.com/u/fanvalt)\
**Post date:** [May 24, 2016, 2:46pm UTC](https://forum.ansible.com/t/unable-to-run-a-remote-script-with-ansible/21540/2 "2016-05-24T14:46:23Z")

</div>

Is it normal that when running with the -vvvv options, in the invocation display, the module\_name displayed is “command” and not “shell” ?

fatal: [integ]: FAILED! =\> {“changed”: true, “cmd”: “/bin/ksh start.sh”, “delta”: “0:00:00.005499”, “end”: “2016-05-24 16:43:55.780568”, “failed”: true, “invocation”: {“module\_args”: {“\_raw\_params”: “/bin/ksh start.sh”, “\_uses\_shell”: true, “chdir”: “/integuno/openhr/bin”, “creates”: null, “executable”: “/bin/ksh”, “removes”: null, “warn”: true}, “module\_name”: “command”}, “rc”: 127, “start”: “2016-05-24 16:43:55.775069”, “stderr”: “start.sh[2]: dispatcher.sh: not found [No such file or directory]”, “stdout”: “”, “stdout\_lines”: , “warnings”: }

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [May 24, 2016, 2:47pm UTC](https://forum.ansible.com/t/unable-to-run-a-remote-script-with-ansible/21540/3 "2016-05-24T14:47:49Z")

</div>

The biggest problem looks like all of your scripts assume relative paths. As a result it looks like things cannot be located. I’d recommend either adding pathing detection, or using full paths to those files.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [May 24, 2016, 2:50pm UTC](https://forum.ansible.com/t/unable-to-run-a-remote-script-with-ansible/21540/4 "2016-05-24T14:50:09Z")

</div>

The error message says, start\_openhr.sh can't find dispatcher.sh.  
So dispatcher.sh is not in path or you should use absolute path.

---

<div class="post-metadata">

**Author:** ![fanvalt](https://avatars.discourse-cdn.com/v4/letter/f/2bfe46/32.png) [@fanvalt](https://forum.ansible.com/u/fanvalt)\
**Post date:** [May 24, 2016, 3:09pm UTC](https://forum.ansible.com/t/unable-to-run-a-remote-script-with-ansible/21540/5 "2016-05-24T15:09:05Z")

</div>

the script dispatcher.sh is in the directory where start.sh is launched.  
I understand your meaning but it is hard to modify scripts that are downloaded from a package and I do not own.

because chdir is supposed to change directory before running a script, it should find all files from that directory when running the script.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [May 24, 2016, 3:55pm UTC](https://forum.ansible.com/t/unable-to-run-a-remote-script-with-ansible/21540/6 "2016-05-24T15:55:06Z")

</div>

No it won't, ksh will first check if it find dispatcher.sh built-in command if not, it will search all directories in the PATH. It will not check the directory command is started from unless it is in PATH.
