[英]Ansible through Apache: Authentication or permission failure
我尝试通过Apache2 CGI运行Ansible。
这是我的脚本:
#!/usr/bin/env python
# -*- coding: UTF-8 -*-# enable debugging
print "Content-type: text/html"
print
import cgitb
cgitb.enable()
print "<html><head>"
print ""
print "</head><body>"
import os
import ansible.runner
import sys
results = ansible.runner.Runner(
# transport='ssh',
# remote_user='root',
# remote_pass='pass',
transport='local',
# su='yes',
# su_user='root',
# su_pass='su_pass',
sudo='yes',
sudo_user='root',
sudo_pass='sudo_pass',
pattern='127.0.0.1',
module_name='service',
module_args='name=shoc-lxc-net state=started enabled=yes',
forks=10,
).run()
if results is None:
print "No hosts found"
sys.exit(1)
import json
print(json.dumps(results,
default=lambda obj: vars(obj),
indent=1))
for (hostname, result) in results['contacted'].items():
if not 'failed' in result:
print "%s >>> %s" % (hostname, result['enabled'])
print "</body></html>"
当我运行它时,我得到:
{“ dark”:{“ 127.0.0.1”:{“ msg”:“身份验证或权限失败。在某些情况下,您可能已经可以进行身份验证,并且对远程目录没有权限。请考虑更改远程临时路径失败的命令是:mkdir -p $ HOME / .ansible / tmp / ansible-1420984254.94-125323999727459 && chmod a + rx $ HOME / .ansible / tmp / ansible。 -1420984254.94-125323999727459 && echo $ HOME / .ansible / tmp / ansible-1420984254.94-125323999727459,以结果1退出,“失败”:true}},“ contacted”:{}}
但是,当我通过shell运行此脚本时,会得到:
$ /lxc/www/py/index.py
Content-type: text/html
<html><head> </head><body> { "dark": {}, "contacted": {
"127.0.0.1": { "invocation": {
"module_name": "service",
"module_args": "name=shoc-lxc-net state=started enabled=yes" }, "state": "started", "changed": false, "enabled": true,
"name": "shoc-lxc-net" } } }
127.0.0.1 >>> True
当我检查时:
# ls -la /var/www/
total 20
drwxrwxrwx 4 root root 4096 Jan 11 15:57 .
drwxr-xr-x 14 root root 4096 Jan 8 15:58 ..
drwxr-xr-x 2 root root 4096 Jan 11 14:54 etc
-rw-r--r-- 1 root root 177 Mar 18 2013 index.html
drwx------ 2 www-data www-data 4096 Jan 11 15:36 .ssh
# su www-data
$ mkdir /var/www/.ansible/tmp -p
$
# ls -la /var/www/.ansible/
total 12
drwxrwxr-x 3 www-data www-data 4096 Jan 11 15:57 .
drwxrwxrwx 5 root root 4096 Jan 11 15:57 ..
drwxrwxr-x 2 www-data www-data 4096 Jan 11 15:57 tmp
在Molecule中运行Ansible项目时遇到了相同的错误。 这是我发现的:
当运行命令molecule test --destroy=never
我重现了与tmp文件夹/文件相同的问题。 如果我跳过destroy
标志并仅运行molecule test
-它将正常工作。
以社区成员的身份发布此答案可能会遇到此问题。 解决方法是,您可以在分子完成verify
步骤之后,即将执行完成之前Ctrl+C
也就是destroy
分子步骤:
└── default ├── lint ├── destroy ├── dependency ├── syntax ├── create ├── prepare ├── converge ├── idempotence ├── side_effect ├── verify └── destroy
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.