unable to run a remote script with Ansible

655 views
Skip to first unread message

fanvalt

unread,
May 24, 2016, 9:23:38 AM5/24/16
to Ansible Project
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

fanvalt

unread,
May 24, 2016, 10:46:23 AM5/24/16
to Ansible Project
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": []}

Matt Martz

unread,
May 24, 2016, 10:48:36 AM5/24/16
to ansible...@googlegroups.com
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.

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/24f9d4b3-53c4-4d85-8cc2-fc76c6926a3d%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Matt Martz
@sivel
sivel.net

Kai Stian Olstad

unread,
May 24, 2016, 10:50:25 AM5/24/16
to ansible...@googlegroups.com
On 24. mai 2016 15:23, fanvalt wrote:
> 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": []}

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.


--
Kai Stian Olstad

fanvalt

unread,
May 24, 2016, 11:09:05 AM5/24/16
to Ansible Project, ansible-pr...@olstad.com
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.

Kai Stian Olstad

unread,
May 24, 2016, 11:55:25 AM5/24/16
to ansible...@googlegroups.com
On 24. mai 2016 17:09, fanvalt wrote:
> 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.

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.

--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages