Add a new callback: tripleo_states
Summary: print out nodes which failed and were ignored
Within the context of max_fail_percentage, we want to improve UX by
displaying which nodes failed to be deployed or were unreachable, probably
because max_fail_percentage was set to a value which matches the play
results.
e.g. we tolerate 10% of compute node failures and two nodes failed
without blocking the whole deployment; the callback will display the
following message:
~~~~~~~~~~~~~~~~~~~ Summary Information ~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~Elapsed Time: 0:45:36.997 ~~~~~~~~~~~~~~~~~~~~
(...)
~~~~~~~ Number of nodes which did not deploy successfuly: 2 ~~~~
This or these node(s) failed to deploy: compute23, compute 45
In the future, this callback will be useful to improve state
informations that are displayed by Ansible when it's done running.
Change-Id: Ib337ea6c9c54a38cf11d021bce4edaf60e9928bd
(cherry picked from commit e3f551725b
)
This commit is contained in:
parent
fcf06e4018
commit
8ae51ffba1
63
tripleo_ansible/ansible_plugins/callback/tripleo_states.py
Normal file
63
tripleo_ansible/ansible_plugins/callback/tripleo_states.py
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
from ansible.plugins.callback import CallbackBase
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
DOCUMENTATION = '''
|
||||||
|
callback: tripleo_states
|
||||||
|
type: aggregate
|
||||||
|
short_description: adds states information
|
||||||
|
version_added: "2.9"
|
||||||
|
description:
|
||||||
|
- TripleO specific callback useful to print out deployment states.
|
||||||
|
requirements:
|
||||||
|
- whitelisting in configuration - see examples section below for details.
|
||||||
|
'''
|
||||||
|
|
||||||
|
|
||||||
|
class CallbackModule(CallbackBase):
|
||||||
|
|
||||||
|
CALLBACK_VERSION = 2.0
|
||||||
|
CALLBACK_TYPE = 'aggregate'
|
||||||
|
CALLBACK_NAME = 'tripleo_states'
|
||||||
|
CALLBACK_NEEDS_WHITELIST = True
|
||||||
|
|
||||||
|
def __init__(self, display=None):
|
||||||
|
super(CallbackModule, self).__init__(display)
|
||||||
|
|
||||||
|
def _output(self, msg, color=None):
|
||||||
|
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")
|
||||||
|
if isinstance(msg, list):
|
||||||
|
output = ' | '.join([timestamp] + msg)
|
||||||
|
else:
|
||||||
|
output = timestamp + ' | ' + msg
|
||||||
|
self._display.display(output, color=color)
|
||||||
|
|
||||||
|
def v2_playbook_on_stats(self, stats):
|
||||||
|
nodes_to_redeploy = []
|
||||||
|
|
||||||
|
# Find out which hosts failed to deploy; it would very likely
|
||||||
|
# happen when max_fail_percentage was set to a percentage value and the
|
||||||
|
# number of hosts which successfully deployed matched the criteria.
|
||||||
|
hosts = sorted(stats.processed.keys())
|
||||||
|
for h in hosts:
|
||||||
|
t = stats.summarize(h)
|
||||||
|
if t['failures'] or t['unreachable']:
|
||||||
|
nodes_to_redeploy.append(h)
|
||||||
|
|
||||||
|
# Only display if there are nodes in error state for now but it might
|
||||||
|
# change later if we add more information.
|
||||||
|
if len(nodes_to_redeploy) > 0:
|
||||||
|
self._output('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
|
||||||
|
' State Information '
|
||||||
|
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
|
||||||
|
|
||||||
|
self._output(
|
||||||
|
'~~~~~~~~~~~~~~~~~~'
|
||||||
|
'Number of nodes which did not deploy successfully: {} '
|
||||||
|
'~~~~~~~~~~~~~~~~~'.format(len(nodes_to_redeploy)))
|
||||||
|
nodes_to_redeploy_list = ", ".join(nodes_to_redeploy)
|
||||||
|
fail_msg = ' This or these node(s) failed to deploy: ' + \
|
||||||
|
'{}'.format(nodes_to_redeploy_list)
|
||||||
|
self._output(fail_msg, 'red')
|
||||||
|
self._output('~' * 89)
|
Loading…
Reference in New Issue
Block a user