我是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
有人能帮助我吗?
答案 0 :(得分:7)
如果您可以通过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"
另外,你可以检查你的脚本是否在文件的开头(#!/bin/sh
)有一个shebang行,并使其可执行(chmod 755 /.../check.sh
)。