mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-26 12:21:26 -07:00
Save the command line arguments into a global context
* Once cli args are parsed, they're constant. So, save the parsed args into the global context for everyone else to use them from now on. * Port cli scripts to use the CLIARGS in the context * Refactor call to parse cli args into the run() method * Fix unittests for changes to the internals of CLI arg parsing * Port callback plugins to use context.CLIARGS * Got rid of the private self._options attribute * Use context.CLIARGS in the individual callback plugins instead. * Also output positional arguments in default and unixy plugins * Code has been simplified since we're now dealing with a dict rather than Optparse.Value
This commit is contained in:
parent
c18da65089
commit
afdbb0d9d5
36 changed files with 1033 additions and 868 deletions
|
@ -19,6 +19,7 @@ DOCUMENTATION = '''
|
|||
'''
|
||||
|
||||
from ansible import constants as C
|
||||
from ansible import context
|
||||
from ansible.playbook.task_include import TaskInclude
|
||||
from ansible.plugins.callback import CallbackBase
|
||||
from ansible.utils.color import colorize, hostcolor
|
||||
|
@ -370,15 +371,16 @@ class CallbackModule(CallbackBase):
|
|||
from os.path import basename
|
||||
self._display.banner("PLAYBOOK: %s" % basename(playbook._file_name))
|
||||
|
||||
# show CLI arguments
|
||||
if self._display.verbosity > 3:
|
||||
# show CLI 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']:
|
||||
continue
|
||||
val = getattr(self._options, option)
|
||||
if val and self._display.verbosity > 3:
|
||||
self._display.display('%s: %s' % (option, val), color=C.COLOR_VERBOSE, screen_only=True)
|
||||
if context.CLIARGS.get('args'):
|
||||
self._display.display('Positional arguments: %s' % ' '.join(context.CLIARGS['args']),
|
||||
color=C.COLOR_VERBOSE, screen_only=True)
|
||||
|
||||
for argument in (a for a in context.CLIARGS if a != 'args'):
|
||||
val = context.CLIARGS[argument]
|
||||
if val:
|
||||
self._display.display('%s: %s' % (argument, val), color=C.COLOR_VERBOSE, screen_only=True)
|
||||
|
||||
def v2_runner_retry(self, result):
|
||||
task_name = result.task_name or result._task
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue