summaryrefslogtreecommitdiffstats
path: root/deploy/status_callback.py
diff options
context:
space:
mode:
Diffstat (limited to 'deploy/status_callback.py')
-rw-r--r--deploy/status_callback.py50
1 files changed, 32 insertions, 18 deletions
diff --git a/deploy/status_callback.py b/deploy/status_callback.py
index 9136804f..4bbbc321 100644
--- a/deploy/status_callback.py
+++ b/deploy/status_callback.py
@@ -13,6 +13,8 @@ import sys # noqa:F401
from ansible.plugins.callback import CallbackBase
+COMPASS_HOST = "compass-deck"
+
def task_error(display, host, data):
display.display("task_error: host=%s,data=%s" % (host, data))
@@ -20,7 +22,7 @@ def task_error(display, host, data):
# if isinstance(data, dict):
# invocation = data.pop('invocation', {})
- notify_host(display, "localhost", host, "failed")
+ notify_host(display, COMPASS_HOST, host, "failed")
class CallbackModule(CallbackBase):
@@ -38,10 +40,11 @@ class CallbackModule(CallbackBase):
def v2_on_any(self, *args, **kwargs):
pass
- def v2_runner_on_failed(self, host, res, ignore_errors=False):
- task_error(self._display, host, res)
+ def v2_runner_on_failed(self, res, ignore_errors=False):
+ # task_error(self._display, host, res)
+ pass
- def v2_runner_on_ok(self, host, res):
+ def v2_runner_on_ok(self, res):
pass
def v2_runner_on_skipped(self, host, item=None):
@@ -60,7 +63,8 @@ class CallbackModule(CallbackBase):
pass
def v2_runner_on_async_failed(self, host, res, jid):
- task_error(self._display, host, res)
+ # task_error(self._display, host, res)
+ pass
def v2_playbook_on_start(self):
pass
@@ -97,29 +101,39 @@ class CallbackModule(CallbackBase):
def v2_playbook_on_stats(self, stats):
self._display.display("playbook_on_stats enter")
- all_vars = self.play.get_variable_manager().get_vars(self.loader)
- host_vars = all_vars["hostvars"]
hosts = sorted(stats.processed.keys())
- cluster_name = host_vars[hosts[0]]['cluster_name']
failures = False
unreachable = False
for host in hosts:
summary = stats.summarize(host)
+ # self._display.display("host: %s \nsummary: %s\n" % (host, summary)) # noqa
if summary['failures'] > 0:
failures = True
if summary['unreachable'] > 0:
unreachable = True
+ headers = {"Content-type": "application/json",
+ "Accept": "*/*"}
+
+ conn = httplib.HTTPConnection(COMPASS_HOST, 80)
+ token = auth(conn)
+ headers["X-Auth-Token"] = token
+ get_url = "/api/hosts"
+ conn.request("GET", get_url, "", headers)
+ resp = conn.getresponse()
+ raise_for_status(resp)
+ host_data = json.loads(resp.read())
+ clusterhosts = [item["name"] for item in host_data]
+
if failures or unreachable:
- for host in hosts:
- notify_host(self._display, "localhost", host, "error")
- return
+ host_status = "error"
+ else:
+ host_status = "succ"
- for host in hosts:
- clusterhost_name = host + "." + cluster_name
- notify_host(self._display, "localhost", clusterhost_name, "succ")
+ for host in clusterhosts:
+ notify_host(self._display, "compass-deck", host, host_status)
def raise_for_status(resp):
@@ -144,13 +158,13 @@ def auth(conn):
def notify_host(display, compass_host, host, status):
+ display.display("hostname: %s" % host)
+ host = host.strip("host")
+ url = "/api/clusterhosts/%s/state" % host
if status == "succ":
- body = {"ready": True}
- url = "/api/clusterhosts/%s/state_internal" % host
+ body = {"state": "SUCCESSFUL"}
elif status == "error":
body = {"state": "ERROR"}
- host = host.strip("host")
- url = "/api/clusterhosts/%s/state" % host
else:
display.error("notify_host: host %s with status %s is not supported"
% (host, status))