aboutsummaryrefslogtreecommitdiffstats
path: root/deploy/status_callback.py
diff options
context:
space:
mode:
Diffstat (limited to 'deploy/status_callback.py')
-rwxr-xr-xdeploy/status_callback.py28
1 files changed, 18 insertions, 10 deletions
diff --git a/deploy/status_callback.py b/deploy/status_callback.py
index e430326b..aaca05b5 100755
--- a/deploy/status_callback.py
+++ b/deploy/status_callback.py
@@ -3,15 +3,14 @@ import json
import sys
import logging
+
def task_error(host, data):
logging.info("task_error: host=%s,data=%s" % (host, data))
-
- if type(data) == dict:
- invocation = data.pop('invocation', {})
-
notify_host("localhost", host, "failed")
+
class CallbackModule(object):
+
"""
logs playbook results, per host, in /var/log/ansible/hosts
"""
@@ -58,7 +57,8 @@ class CallbackModule(object):
def playbook_on_task_start(self, name, is_conditional):
pass
- def playbook_on_vars_prompt(self, varname, private=True, prompt=None, encrypt=None, confirm=False, salt_size=None, salt=None, default=None):
+ def playbook_on_vars_prompt(self, varname, private=True, prompt=None,
+ encrypt=None, confirm=False, salt_size=None, salt=None, default=None): # noqa: E501
pass
def playbook_on_setup(self):
@@ -101,7 +101,10 @@ class CallbackModule(object):
def raise_for_status(resp):
if resp.status < 200 or resp.status > 300:
- raise RuntimeError("%s, %s, %s" % (resp.status, resp.reason, resp.read()))
+ raise RuntimeError(
+ "%s, %s, %s" %
+ (resp.status, resp.reason, resp.read()))
+
def auth(conn):
credential = {}
@@ -116,6 +119,7 @@ def auth(conn):
raise_for_status(resp)
return json.loads(resp.read())["token"]
+
def notify_host(compass_host, host, status):
if status == "succ":
body = {"ready": True}
@@ -125,8 +129,8 @@ def notify_host(compass_host, host, status):
host = host.strip("host")
url = "/api/clusterhosts/%s/state" % host
else:
- logging.error("notify_host: host %s with status %s is not supported" \
- % (host, status))
+ logging.error("notify_host: host %s with status %s is not supported"
+ % (host, status))
return
headers = {"Content-type": "application/json",
@@ -135,12 +139,16 @@ def notify_host(compass_host, host, status):
conn = httplib.HTTPConnection(compass_host, 80)
token = auth(conn)
headers["X-Auth-Token"] = token
- logging.info("host=%s,url=%s,body=%s,headers=%s" % (compass_host,url,json.dumps(body),headers))
+ logging.info(
+ "host=%s,url=%s,body=%s,headers=%s" %
+ (compass_host, url, json.dumps(body), headers))
conn.request("POST", url, json.dumps(body), headers)
resp = conn.getresponse()
try:
raise_for_status(resp)
- logging.info("notify host status success!!! status=%s, body=%s" % (resp.status, resp.read()))
+ logging.info(
+ "notify host status success!!! status=%s, body=%s" %
+ (resp.status, resp.read()))
except Exception as e:
logging.error("http request failed %s" % str(e))
raise