2017-11-21 6 views
0

私はubuntu 16.04を実行しているVMを使用しており、それにはv2.4とapache2がインストールされています。私はWebサーバ経由でan-playbookを呼び出してください

curl localhost/cgi-bin/ansible-call.py 

は、しかし、私は次のエラーを取得するWebサービスへの要求を行うためにカールを使用すると、具体的subprocessモジュールを使用するCGIスクリプト「ansible_call.py」、

import os 
import subprocess 


print 'Content-type:text/html /r/n/r/n' 

with open(os.devnull, 'w') as devnull: 
    result = subprocess.check_output(['/usr/bin/ansible- 
playbook','/vagrant/playbooks/sample.yml'], stderr=devnull) 

print result 

を作成し

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> 
<html><head> 
<title>500 Internal Server Error</title> 
</head><body> 
<h1>Internal Server Error</h1> 
<p>The server encountered an internal error or 
misconfiguration and was unable to complete 
your request.</p> 
<p>Please contact the server administrator at 
[email protected] to inform them of the time this error occurred, 
and the actions you performed just before this error.</p> 
<p>More information about this error may be available 
in the server error log.</p> 
<hr> 
<address>Apache/2.4.18 (Ubuntu) Server at localhost Port 80</address> 
</body></html> 

私がログに見て、次

[Tue Nov 21 17:34:50.192002 2017] [cgi:error] [pid 3142:tid 140333400639232] [client 127.0.0.1:37534] AH01215: subprocess.CalledProcessError: Command '['/usr/bin/ansible-playbook', '/vagrant/playbooks/sample.yml']' returned non-zero exit status 2: /usr/lib/cgi-bin/ansible-call.py 
を見つけました

pythonスクリプト自体が正常に実行されます。終了ステータス2は私にとって謎です、誰にもアイデアはありますか?

答えて

0

可能ステータスコードについてansible "executable"を点検してください:

一部抜粋:

except AnsibleOptionsError as e: 
     ... 
     exit_code = 5 
    except AnsibleParserError as e: 
     ... 
     exit_code = 4 
# TQM takes care of these, but leaving comment to reserve the exit codes 
# except AnsibleHostUnreachable as e: 
#  ... 
#  exit_code = 3 
# except AnsibleHostFailed as e: 
#  ... 
#  exit_code = 2 
    except AnsibleError as e: 
     ... 
     exit_code = 1 
    except KeyboardInterrupt: 
     ... 
     exit_code = 99 
    except Exception as e: 
     ... 
     exit_code = 250 

ので、終了コード2を使用すると、ホストを失敗したことを示唆しています。あなたは、プロセスの例外をキャッチすることもできます。

try: 
     res = check_output(cmd) 
    except CalledProcessError as e: 
     print 'Error occurred: (Code {}) {}'.format(e.returncode, e.output) 
     res = None 
+0

は今、私はmakedirs MKDIR(名前、で、アクセス許可が拒否されました、 ファイル「/usr/lib/python2.7/os.py」のエラー、ライン157を取得しますモード) OSError:[Errno 13]許可が拒否されました: '〜' 致命的:[localhost]:FAILED! === { "failed":true、 "msgモジュールの実行中に予期しないエラーが発生しました。"、 "stdout": "" } –

関連する問題