mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
fixed issue with default callback inheritance (#30427)
* fixed issue with default callback inheritance - callbacks need to document same options as callbacks they inherit from to get them configured - since default is also used by many 3rd party callbacks for inheritance, making the code 'tolerate' the missing docs and fallback to using the direct constant to configure it's options.
This commit is contained in:
parent
5d404af76e
commit
81fd67c10f
8 changed files with 50 additions and 28 deletions
|
@ -14,6 +14,8 @@ DOCUMENTATION = '''
|
||||||
- Use this callback when you dont care about OK nor Skipped.
|
- Use this callback when you dont care about OK nor Skipped.
|
||||||
- This callback suppreses any non Failed or Changed status.
|
- This callback suppreses any non Failed or Changed status.
|
||||||
version_added: "2.1"
|
version_added: "2.1"
|
||||||
|
extends_documentation_fragment:
|
||||||
|
- default_callback
|
||||||
requirements:
|
requirements:
|
||||||
- set as stdout callback in configuration
|
- set as stdout callback in configuration
|
||||||
'''
|
'''
|
||||||
|
|
|
@ -11,6 +11,8 @@ DOCUMENTATION = '''
|
||||||
description:
|
description:
|
||||||
- Use this callback to sort though extensive debug output
|
- Use this callback to sort though extensive debug output
|
||||||
version_added: "2.4"
|
version_added: "2.4"
|
||||||
|
extends_documentation_fragment:
|
||||||
|
- default_callback
|
||||||
requirements:
|
requirements:
|
||||||
- set as stdout in configuration
|
- set as stdout in configuration
|
||||||
'''
|
'''
|
||||||
|
|
|
@ -12,27 +12,8 @@ DOCUMENTATION = '''
|
||||||
version_added: historical
|
version_added: historical
|
||||||
description:
|
description:
|
||||||
- This is the default output callback for ansible-playbook.
|
- This is the default output callback for ansible-playbook.
|
||||||
options:
|
extends_documentation_fragment:
|
||||||
show_skipped_hosts:
|
- default_callback
|
||||||
name: Show skipped hosts
|
|
||||||
description: "Toggle to control displaying skipped task/host results in a task"
|
|
||||||
default: True
|
|
||||||
env:
|
|
||||||
- name: DISPLAY_SKIPPED_HOSTS
|
|
||||||
ini:
|
|
||||||
- key: display_skipped_hosts
|
|
||||||
section: defaults
|
|
||||||
type: boolean
|
|
||||||
show_custom_stats:
|
|
||||||
name: Show custom stats
|
|
||||||
description: 'This adds the custom stats set via the set_stats plugin to the play recap'
|
|
||||||
default: False
|
|
||||||
env:
|
|
||||||
- name: ANSIBLE_SHOW_CUSTOM_STATS
|
|
||||||
ini:
|
|
||||||
- key: show_custom_stats
|
|
||||||
section: defaults
|
|
||||||
type: bool
|
|
||||||
requirements:
|
requirements:
|
||||||
- set as stdout in configuration
|
- set as stdout in configuration
|
||||||
'''
|
'''
|
||||||
|
@ -118,9 +99,8 @@ class CallbackModule(CallbackBase):
|
||||||
self._display.display(msg, color=color)
|
self._display.display(msg, color=color)
|
||||||
|
|
||||||
def v2_runner_on_skipped(self, result):
|
def v2_runner_on_skipped(self, result):
|
||||||
if self._plugin_options['show_skipped_hosts']:
|
if self._plugin_options.get('show_skipped_hosts', C.DISPLAY_SKIPPED_HOSTS): # fallback on constants for inherited plugins missing docs
|
||||||
|
|
||||||
delegated_vars = result._result.get('_ansible_delegated_vars', None)
|
|
||||||
self._clean_results(result._result, result._task.action)
|
self._clean_results(result._result, result._task.action)
|
||||||
|
|
||||||
if self._play.strategy == 'free' and self._last_task_banner != result._task._uuid:
|
if self._play.strategy == 'free' and self._last_task_banner != result._task._uuid:
|
||||||
|
@ -247,7 +227,7 @@ class CallbackModule(CallbackBase):
|
||||||
self._display.display(msg + " (item=%s) => %s" % (self._get_item(result._result), self._dump_results(result._result)), color=C.COLOR_ERROR)
|
self._display.display(msg + " (item=%s) => %s" % (self._get_item(result._result), self._dump_results(result._result)), color=C.COLOR_ERROR)
|
||||||
|
|
||||||
def v2_runner_item_on_skipped(self, result):
|
def v2_runner_item_on_skipped(self, result):
|
||||||
if self._plugin_options['show_skipped_hosts']:
|
if self._plugin_options.get('show_skipped_hosts', C.DISPLAY_SKIPPED_HOSTS): # fallback on constants for inherited plugins missing docs
|
||||||
self._clean_results(result._result, result._task.action)
|
self._clean_results(result._result, result._task.action)
|
||||||
msg = "skipping: [%s] => (item=%s) " % (result._host.get_name(), self._get_item(result._result))
|
msg = "skipping: [%s] => (item=%s) " % (result._host.get_name(), self._get_item(result._result))
|
||||||
if (self._display.verbosity > 0 or '_ansible_verbose_always' in result._result) and '_ansible_verbose_override' not in result._result:
|
if (self._display.verbosity > 0 or '_ansible_verbose_always' in result._result) and '_ansible_verbose_override' not in result._result:
|
||||||
|
@ -286,7 +266,7 @@ class CallbackModule(CallbackBase):
|
||||||
self._display.display("", screen_only=True)
|
self._display.display("", screen_only=True)
|
||||||
|
|
||||||
# print custom stats
|
# print custom stats
|
||||||
if self._plugin_options['show_custom_stats'] and stats.custom:
|
if self._plugin_options.get('show_custom_stats', C.SHOW_CUSTOM_STATS) and stats.custom: # fallback on constants for inherited plugins missing docs
|
||||||
self._display.banner("CUSTOM STATS: ")
|
self._display.banner("CUSTOM STATS: ")
|
||||||
# per host
|
# per host
|
||||||
# TODO: come up with 'pretty format'
|
# TODO: come up with 'pretty format'
|
||||||
|
@ -307,11 +287,12 @@ class CallbackModule(CallbackBase):
|
||||||
self._display.banner("PLAYBOOK: %s" % basename(playbook._file_name))
|
self._display.banner("PLAYBOOK: %s" % basename(playbook._file_name))
|
||||||
|
|
||||||
if self._display.verbosity > 3:
|
if self._display.verbosity > 3:
|
||||||
if self._plugin_options is not None:
|
# show CLI options
|
||||||
for option in dir(self._plugin_options):
|
if self._options is not None:
|
||||||
|
for option in dir(self._options):
|
||||||
if option.startswith('_') or option in ['read_file', 'ensure_value', 'read_module']:
|
if option.startswith('_') or option in ['read_file', 'ensure_value', 'read_module']:
|
||||||
continue
|
continue
|
||||||
val = getattr(self._plugin_options, option)
|
val = getattr(self._options, option)
|
||||||
if val:
|
if val:
|
||||||
self._display.vvvv('%s: %s' % (option, val))
|
self._display.vvvv('%s: %s' % (option, val))
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,8 @@ DOCUMENTATION = '''
|
||||||
callback: dense
|
callback: dense
|
||||||
type: stdout
|
type: stdout
|
||||||
short_description: minimal stdout output
|
short_description: minimal stdout output
|
||||||
|
extends_documentation_fragment:
|
||||||
|
- default_callback
|
||||||
description:
|
description:
|
||||||
- When in verbose mode it will act the same as the default callback
|
- When in verbose mode it will act the same as the default callback
|
||||||
version_added: "2.3"
|
version_added: "2.3"
|
||||||
|
|
|
@ -13,6 +13,8 @@ DOCUMENTATION = '''
|
||||||
description:
|
description:
|
||||||
- Use this plugin when you dont care about any output for tasks that were completly skipped
|
- Use this plugin when you dont care about any output for tasks that were completly skipped
|
||||||
version_added: "2.4"
|
version_added: "2.4"
|
||||||
|
extends_documentation_fragment:
|
||||||
|
- default_callback
|
||||||
requirements:
|
requirements:
|
||||||
- set as stdout in configuation
|
- set as stdout in configuation
|
||||||
'''
|
'''
|
||||||
|
|
|
@ -13,6 +13,8 @@ DOCUMENTATION = '''
|
||||||
- set as main display callback
|
- set as main display callback
|
||||||
short_description: Ansible screen output that ignores skipped status
|
short_description: Ansible screen output that ignores skipped status
|
||||||
version_added: "2.0"
|
version_added: "2.0"
|
||||||
|
extends_documentation_fragment:
|
||||||
|
- default_callback
|
||||||
description:
|
description:
|
||||||
- This callback does the same as the default except it does not output skipped host/task/item status
|
- This callback does the same as the default except it does not output skipped host/task/item status
|
||||||
'''
|
'''
|
||||||
|
|
|
@ -13,6 +13,8 @@ DOCUMENTATION = '''
|
||||||
- set as main display callback
|
- set as main display callback
|
||||||
short_description: Splits output, sending failed tasks to stderr
|
short_description: Splits output, sending failed tasks to stderr
|
||||||
version_added: "2.4"
|
version_added: "2.4"
|
||||||
|
extends_documentation_fragment:
|
||||||
|
- default_callback
|
||||||
description:
|
description:
|
||||||
- This is the stderr callback plugin, it behaves like the default callback plugin but sends error output to stderr.
|
- This is the stderr callback plugin, it behaves like the default callback plugin but sends error output to stderr.
|
||||||
- Also it does not output skipped host/task/item status
|
- Also it does not output skipped host/task/item status
|
||||||
|
|
29
lib/ansible/utils/module_docs_fragments/default_callback.py
Normal file
29
lib/ansible/utils/module_docs_fragments/default_callback.py
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
# (c) 2017 Ansible Project
|
||||||
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
|
||||||
|
|
||||||
|
class ModuleDocFragment(object):
|
||||||
|
|
||||||
|
DOCUMENTATION = """
|
||||||
|
options:
|
||||||
|
show_skipped_hosts:
|
||||||
|
name: Show skipped hosts
|
||||||
|
description: "Toggle to control displaying skipped task/host results in a task"
|
||||||
|
default: True
|
||||||
|
env:
|
||||||
|
- name: DISPLAY_SKIPPED_HOSTS
|
||||||
|
ini:
|
||||||
|
- key: display_skipped_hosts
|
||||||
|
section: defaults
|
||||||
|
type: boolean
|
||||||
|
show_custom_stats:
|
||||||
|
name: Show custom stats
|
||||||
|
description: 'This adds the custom stats set via the set_stats plugin to the play recap'
|
||||||
|
default: False
|
||||||
|
env:
|
||||||
|
- name: ANSIBLE_SHOW_CUSTOM_STATS
|
||||||
|
ini:
|
||||||
|
- key: show_custom_stats
|
||||||
|
section: defaults
|
||||||
|
type: bool
|
||||||
|
"""
|
Loading…
Reference in a new issue