def do_task(**post_data):
callback = post_data.get('callback_url')
acceptkey = post_data.get('accept_key')
task_id = post_data.get('task_id')
playbook = post_data.get('playbook')
extra_vars = post_data.get('extra_vars')
hosts = post_data.get('hosts')
p = Popen(
"/usr/bin/ansible-playbook -i %s %s --extra-vars='%s' -s" %
(hosts, playbook, extra_vars),
shell=True,
stdout=PIPE,
stderr=PIPE)
try:
stdout, stderr = p.communicate()
finally:
subprocess._cleanup()
p.stdout.close()
p.stderr.close()
rc = p.returncode
log_debug(
'task id %d in hosts %s playbook %s return stdout %s ,stderr %s!' %
(task_id, hosts, playbook, stdout, stderr))
return {
'task_id': task_id,
'callback_url': callback,
'accept_key': acceptkey,
'hosts': hosts,
'playbook': playbook,
'stdout': stdout,
'stderr': stderr,
'returncode': rc
}
评论列表
文章目录