关于ansible,尝试执行脚本时权限被拒绝

about ansible, Permission denied when trying to execute a script

我是 ansible 的新手,所以我在尝试 运行 我自己的剧本时遇到错误。

我的剧本因该操作失败:

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

这是 ansible-playbook 命令的输出:

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

这很奇怪,因为如果我尝试 运行 手动脚本,它会完美运行

[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

如果我尝试通过 shell 更改命令,同样的错误:

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

有人可以帮我吗?

如果您可以通过 sh /.../check.sh 运行 命令并且命令模块中的 运行 不起作用(权限被拒绝),那么我认为该文件不可执行.

要在您的剧本中/bin/sh /.../check.sh显式解决此调用:

# 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"

或者,您可以检查您的脚本是否在文件开头有一个 shebang 行 (#!/bin/sh) 并使其可执行 (chmod 755 /.../check.sh)。