toggle missing handler errors/warnings via config
(cherry picked from commit b169a61c20
)
This commit is contained in:
parent
a94db01b89
commit
b6e317c045
3 changed files with 15 additions and 8 deletions
|
@ -70,6 +70,9 @@
|
||||||
#task_includes_static = True
|
#task_includes_static = True
|
||||||
#handler_includes_static = True
|
#handler_includes_static = True
|
||||||
|
|
||||||
|
# Controls if a missing handler for a notification event is an error or a warning
|
||||||
|
#error_on_missing_handler = True
|
||||||
|
|
||||||
# change this for alternative sudo implementations
|
# change this for alternative sudo implementations
|
||||||
#sudo_exe = sudo
|
#sudo_exe = sudo
|
||||||
|
|
||||||
|
|
|
@ -191,6 +191,7 @@ DEFAULT_FORCE_HANDLERS = get_config(p, DEFAULTS, 'force_handlers', 'ANSIBLE_F
|
||||||
DEFAULT_INVENTORY_IGNORE = get_config(p, DEFAULTS, 'inventory_ignore_extensions', 'ANSIBLE_INVENTORY_IGNORE', ["~", ".orig", ".bak", ".ini", ".cfg", ".retry", ".pyc", ".pyo"], islist=True)
|
DEFAULT_INVENTORY_IGNORE = get_config(p, DEFAULTS, 'inventory_ignore_extensions', 'ANSIBLE_INVENTORY_IGNORE', ["~", ".orig", ".bak", ".ini", ".cfg", ".retry", ".pyc", ".pyo"], islist=True)
|
||||||
DEFAULT_VAR_COMPRESSION_LEVEL = get_config(p, DEFAULTS, 'var_compression_level', 'ANSIBLE_VAR_COMPRESSION_LEVEL', 0, integer=True)
|
DEFAULT_VAR_COMPRESSION_LEVEL = get_config(p, DEFAULTS, 'var_compression_level', 'ANSIBLE_VAR_COMPRESSION_LEVEL', 0, integer=True)
|
||||||
DEFAULT_INTERNAL_POLL_INTERVAL = get_config(p, DEFAULTS, 'internal_poll_interval', None, 0.001, floating=True)
|
DEFAULT_INTERNAL_POLL_INTERVAL = get_config(p, DEFAULTS, 'internal_poll_interval', None, 0.001, floating=True)
|
||||||
|
ERROR_ON_MISSING_HANDLER = get_config(p, DEFAULTS, 'error_on_missing_handler', 'ANSIBLE_ERROR_ON_MISSING_HANDLER', True, boolean=True)
|
||||||
|
|
||||||
# static includes
|
# static includes
|
||||||
DEFAULT_TASK_INCLUDES_STATIC = get_config(p, DEFAULTS, 'task_includes_static', 'ANSIBLE_TASK_INCLUDES_STATIC', False, boolean=True)
|
DEFAULT_TASK_INCLUDES_STATIC = get_config(p, DEFAULTS, 'task_includes_static', 'ANSIBLE_TASK_INCLUDES_STATIC', False, boolean=True)
|
||||||
|
|
|
@ -388,6 +388,7 @@ class StrategyBase:
|
||||||
# So, per the docs, we reassign the list so the proxy picks up and
|
# So, per the docs, we reassign the list so the proxy picks up and
|
||||||
# notifies all other threads
|
# notifies all other threads
|
||||||
for handler_name in result_item['_ansible_notify']:
|
for handler_name in result_item['_ansible_notify']:
|
||||||
|
found = False
|
||||||
# Find the handler using the above helper. First we look up the
|
# Find the handler using the above helper. First we look up the
|
||||||
# dependency chain of the current task (if it's from a role), otherwise
|
# dependency chain of the current task (if it's from a role), otherwise
|
||||||
# we just look through the list of handlers in the current play/all
|
# we just look through the list of handlers in the current play/all
|
||||||
|
@ -395,15 +396,15 @@ class StrategyBase:
|
||||||
if handler_name in self._listening_handlers:
|
if handler_name in self._listening_handlers:
|
||||||
for listening_handler_name in self._listening_handlers[handler_name]:
|
for listening_handler_name in self._listening_handlers[handler_name]:
|
||||||
listening_handler = search_handler_blocks(listening_handler_name, iterator._play.handlers)
|
listening_handler = search_handler_blocks(listening_handler_name, iterator._play.handlers)
|
||||||
if listening_handler is None:
|
if listening_handler is not None:
|
||||||
raise AnsibleError("The requested handler listener '%s' was not found in any of the known handlers" % listening_handler_name)
|
found = True
|
||||||
if original_host not in self._notified_handlers[listening_handler]:
|
if original_host not in self._notified_handlers[listening_handler]:
|
||||||
self._notified_handlers[listening_handler].append(original_host)
|
self._notified_handlers[listening_handler].append(original_host)
|
||||||
display.vv("NOTIFIED HANDLER %s" % (listening_handler_name,))
|
display.vv("NOTIFIED HANDLER %s" % (listening_handler_name,))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
target_handler = search_handler_blocks(handler_name, iterator._play.handlers)
|
target_handler = search_handler_blocks(handler_name, iterator._play.handlers)
|
||||||
if target_handler is not None:
|
if target_handler is not None:
|
||||||
|
found = True
|
||||||
if original_host not in self._notified_handlers[target_handler]:
|
if original_host not in self._notified_handlers[target_handler]:
|
||||||
self._notified_handlers[target_handler].append(original_host)
|
self._notified_handlers[target_handler].append(original_host)
|
||||||
# FIXME: should this be a callback?
|
# FIXME: should this be a callback?
|
||||||
|
@ -411,7 +412,6 @@ class StrategyBase:
|
||||||
else:
|
else:
|
||||||
# As there may be more than one handler with the notified name as the
|
# As there may be more than one handler with the notified name as the
|
||||||
# parent, so we just keep track of whether or not we found one at all
|
# parent, so we just keep track of whether or not we found one at all
|
||||||
found = False
|
|
||||||
for target_handler in self._notified_handlers:
|
for target_handler in self._notified_handlers:
|
||||||
if parent_handler_match(target_handler, handler_name):
|
if parent_handler_match(target_handler, handler_name):
|
||||||
self._notified_handlers[target_handler].append(original_host)
|
self._notified_handlers[target_handler].append(original_host)
|
||||||
|
@ -420,8 +420,11 @@ class StrategyBase:
|
||||||
|
|
||||||
# and if none were found, then we raise an error
|
# and if none were found, then we raise an error
|
||||||
if not found:
|
if not found:
|
||||||
raise AnsibleError("The requested handler '%s' was found in neither the main handlers list nor the listening handlers list" % handler_name)
|
msg = "The requested handler '%s' was not found in either the main handlers list nor in the listening handlers list" % handler_name
|
||||||
|
if C.ERROR_ON_MISSING_HANDLER:
|
||||||
|
raise AnsibleError(msg)
|
||||||
|
else:
|
||||||
|
display.warning(msg)
|
||||||
|
|
||||||
if 'add_host' in result_item:
|
if 'add_host' in result_item:
|
||||||
# this task added a new host (add_host module)
|
# this task added a new host (add_host module)
|
||||||
|
|
Loading…
Reference in a new issue