Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

about ansible, Permission denied when trying to execute a script

i am newbee with ansible, so i am getting an error when trying to run my own playbook.

My playbook fails with this action:

# run check-feed-adapter-folders script. the script tries to create some folders on HDFS.
- command: "{{check_feed_adapter_folders_outputpath}}/check.sh"

This is the output of the ansible-playbook command:

TASK: [command {{check_feed_adapter_folders_outputpath}}/check-feed.sh] *******
<127.0.0.1> REMOTE_MODULE command /var/app/check-feed-adapter-folders/check-feed.sh
<127.0.0.1> EXEC ['/bin/sh', '-c', 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1423231416.19-167270274703096 && echo $HOME/.ansible/tmp/ansible-tmp-1423231416.19-167270274703096']
<127.0.0.1> PUT /tmp/tmpvB4uTB TO /root/.ansible/tmp/ansible-tmp-1423231416.19-167270274703096/command
<127.0.0.1> EXEC ['/bin/sh', '-c', u'LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python /root/.ansible/tmp/ansible-tmp-1423231416.19-167270274703096/command; rm -rf /root/.ansible/tmp/ansible-tmp-1423231416.19-167270274703096/ >/dev/null 2>&1']
failed: [127.0.0.1] => {"cmd": "/var/app/check-feed-adapter-folders/check-feed.sh", "failed": true, "rc": 13}
msg: [Errno 13] Permission denied

FATAL: all hosts have already failed -- aborting

It is weird because if i try to run manually the script, it works perfectly

[root@dub-vcd-vms171 core2door.ansible]# sh /var/app/check-feed-adapter-folders/check-feed.sh     [INFO][CheckTopologyFolder][2015-02-06 14:05:32] CheckFeedFolder:41 - Started main method CheckTopologyFolder. param1: /var/app/feed-adapter/feed-adapter-SIP-Pub.properties
[INFO][CheckTopologyFolder][2015-02-06 14:05:32] CheckFeedFolder:47 - Trying to create the folder on HDFS
[INFO][CheckTopologyFolder][2015-02-06 14:05:32] MyHadoopUtils:28 - Started using hdfs://dub-vcd-vms169.global.tektronix.net:8020/
[WARN][CheckTopologyFolder][2015-02-06 14:05:33] NativeCodeLoader:62 - Unable to load native-hadoop library for your platform... using builtin-java classes where applicable

If i try to change command by shell, the same error:

failed: [127.0.0.1] => {"changed": true, "cmd": "/var/app/check-feed-adapter-folders/check-feed.sh", "delta": "0:00:00.004738", "end": "2015-02-06 14:12:10.257034", "rc": 126, "start": "2015-02-06 14:12:10.252296", "warnings": []}
stderr: /bin/sh: /var/app/check-feed-adapter-folders/check-feed.sh: Permission denied

FATAL: all hosts have already failed -- aborting

Can anybody help me?

like image 778
aironman Avatar asked Feb 06 '15 14:02

aironman


1 Answers

If you can run the command via sh /.../check.sh and the run within the command module doesn't work (permission denied), then I think that the file is not executable.

To solve this call explicitly /bin/sh /.../check.shin your playbook:

# run check-feed-adapter-folders script. the script tries to create some folders on HDFS.
- command: /bin/sh "{{check_feed_adapter_folders_outputpath}}/check.sh"

Alternativly you could check whether your script has a shebang line at the beginning of the file (#!/bin/sh) and make it executeable (chmod 755 /.../check.sh).

like image 98
Sebastian Stigler Avatar answered Nov 15 '22 11:11

Sebastian Stigler