diff options
author | James Cammarata <jimi@sngx.net> | 2016-09-06 10:02:15 -0500 |
---|---|---|
committer | James Cammarata <jimi@sngx.net> | 2016-09-06 10:48:49 -0500 |
commit | bff8202211074f168b9e1a6f8b7db794c6c646c3 (patch) | |
tree | 772374dcaa5f3081f07a7d836bd106bb4915c46f | |
parent | 9fe430867063a0a63316e9bb71e9ba03a475a989 (diff) | |
download | ansible-debug_levels.tar.gz |
Adding debug levelsdebug_levels
Also removes the debug lock, as it does appear to be required and
is causing some problems with deadlocks in some situations.
-rw-r--r-- | lib/ansible/cli/__init__.py | 12 | ||||
-rw-r--r-- | lib/ansible/cli/adhoc.py | 3 | ||||
-rw-r--r-- | lib/ansible/cli/console.py | 3 | ||||
-rw-r--r-- | lib/ansible/cli/galaxy.py | 4 | ||||
-rw-r--r-- | lib/ansible/cli/playbook.py | 4 | ||||
-rw-r--r-- | lib/ansible/cli/pull.py | 3 | ||||
-rw-r--r-- | lib/ansible/cli/vault.py | 3 | ||||
-rw-r--r-- | lib/ansible/constants.py | 2 | ||||
-rw-r--r-- | lib/ansible/module_utils/basic.py | 11 | ||||
-rw-r--r-- | lib/ansible/playbook/play_context.py | 3 | ||||
-rw-r--r-- | lib/ansible/utils/display.py | 36 |
11 files changed, 52 insertions, 32 deletions
diff --git a/lib/ansible/cli/__init__.py b/lib/ansible/cli/__init__.py index b12fc0dbc6..26e8ea1483 100644 --- a/lib/ansible/cli/__init__.py +++ b/lib/ansible/cli/__init__.py @@ -103,7 +103,15 @@ class CLI(object): fn() def parse(self): - raise Exception("Need to implement!") + if self.options: + display.verbosity = self.options.verbosity + try: + debug_verbosity = int(self.options.debug_verbosity) + except ValueError: + debug_verbosity = 0 + display.debug_verbosity = debug_verbosity + + return True def run(self): @@ -238,6 +246,8 @@ class CLI(object): parser = SortedOptParser(usage, version=CLI.version("%prog")) parser.add_option('-v','--verbose', dest='verbosity', default=0, action="count", help="verbose mode (-vvv for more, -vvvv to enable connection debugging)") + parser.add_option('-d','--debug', dest='debug_verbosity', default=C.DEFAULT_DEBUG, action="count", + help="debugging mode (multiple uses increase debugging verbosity)") if inventory_opts: parser.add_option('-i', '--inventory-file', dest='inventory', diff --git a/lib/ansible/cli/adhoc.py b/lib/ansible/cli/adhoc.py index cfaeca955b..85ede0f333 100644 --- a/lib/ansible/cli/adhoc.py +++ b/lib/ansible/cli/adhoc.py @@ -79,10 +79,9 @@ class AdHocCLI(CLI): elif len(self.args) > 1: raise AnsibleOptionsError("Extranous options or arguments") - display.verbosity = self.options.verbosity self.validate_conflicts(runas_opts=True, vault_opts=True, fork_opts=True) - return True + return super(GalaxyCLI, self).parse() def _play_ds(self, pattern, async, poll): check_raw = self.options.module_name in ('command', 'shell', 'script', 'raw') diff --git a/lib/ansible/cli/console.py b/lib/ansible/cli/console.py index 5b0432036f..0757c8d79b 100644 --- a/lib/ansible/cli/console.py +++ b/lib/ansible/cli/console.py @@ -98,10 +98,9 @@ class ConsoleCLI(CLI, cmd.Cmd): self.parser.set_defaults(cwd='*') self.options, self.args = self.parser.parse_args(self.args[1:]) - display.verbosity = self.options.verbosity self.validate_conflicts(runas_opts=True, vault_opts=True, fork_opts=True) - return True + return super(GalaxyCLI, self).parse() def get_names(self): return dir(self) diff --git a/lib/ansible/cli/galaxy.py b/lib/ansible/cli/galaxy.py index 231b6b909a..d83d57ff3e 100644 --- a/lib/ansible/cli/galaxy.py +++ b/lib/ansible/cli/galaxy.py @@ -121,9 +121,9 @@ class GalaxyCLI(CLI): self.parser.add_option('-f', '--force', dest='force', action='store_true', default=False, help='Force overwriting an existing role') self.options, self.args =self.parser.parse_args() - display.verbosity = self.options.verbosity self.galaxy = Galaxy(self.options) - return True + + return super(GalaxyCLI, self).parse() def run(self): diff --git a/lib/ansible/cli/playbook.py b/lib/ansible/cli/playbook.py index ec3a91776e..a6e1b98996 100644 --- a/lib/ansible/cli/playbook.py +++ b/lib/ansible/cli/playbook.py @@ -77,15 +77,15 @@ class PlaybookCLI(CLI): self.options, self.args = parser.parse_args(self.args[1:]) - self.parser = parser if len(self.args) == 0: raise AnsibleOptionsError("You must specify a playbook file to run") - display.verbosity = self.options.verbosity self.validate_conflicts(runas_opts=True, vault_opts=True, fork_opts=True) + return super(PlaybookCLI, self).parse() + def run(self): super(PlaybookCLI, self).run() diff --git a/lib/ansible/cli/pull.py b/lib/ansible/cli/pull.py index ccc106f369..8ea0fdf83f 100644 --- a/lib/ansible/cli/pull.py +++ b/lib/ansible/cli/pull.py @@ -121,9 +121,10 @@ class PullCLI(CLI): if self.options.module_name not in self.SUPPORTED_REPO_MODULES: raise AnsibleOptionsError("Unsuported repo module %s, choices are %s" % (self.options.module_name, ','.join(self.SUPPORTED_REPO_MODULES))) - display.verbosity = self.options.verbosity self.validate_conflicts(vault_opts=True) + return super(GalaxyCLI, self).parse() + def run(self): ''' use Runner lib to do SSH things ''' diff --git a/lib/ansible/cli/vault.py b/lib/ansible/cli/vault.py index 85bdac6993..f95a9e6a05 100644 --- a/lib/ansible/cli/vault.py +++ b/lib/ansible/cli/vault.py @@ -71,7 +71,6 @@ class VaultCLI(CLI): self.parser.set_usage("usage: %prog rekey [options] file_name") self.options, self.args = self.parser.parse_args(self.args[1:]) - display.verbosity = self.options.verbosity can_output = ['encrypt', 'decrypt'] @@ -89,6 +88,8 @@ class VaultCLI(CLI): if self.options.output_file and len(self.args) > 1: raise AnsibleOptionsError("At most one input file may be used with the --output option") + return super(GalaxyCLI, self).parse() + def run(self): super(VaultCLI, self).run() diff --git a/lib/ansible/constants.py b/lib/ansible/constants.py index 1adb31c808..29292d2768 100644 --- a/lib/ansible/constants.py +++ b/lib/ansible/constants.py @@ -151,7 +151,7 @@ DEPRECATED_HOST_LIST = get_config(p, DEFAULTS, 'hostfile', 'ANSIBLE_HOSTS', '/e DEFAULT_PATTERN = get_config(p, DEFAULTS, 'pattern', None, None) #### GENERALLY CONFIGURABLE THINGS #### -DEFAULT_DEBUG = get_config(p, DEFAULTS, 'debug', 'ANSIBLE_DEBUG', False, boolean=True) +DEFAULT_DEBUG = get_config(p, DEFAULTS, 'debug', 'ANSIBLE_DEBUG', 0, integer=True) DEFAULT_HOST_LIST = get_config(p, DEFAULTS,'inventory', 'ANSIBLE_INVENTORY', DEPRECATED_HOST_LIST, ispath=True) DEFAULT_MODULE_PATH = get_config(p, DEFAULTS, 'library', 'ANSIBLE_LIBRARY', None, ispathlist=True) DEFAULT_ROLES_PATH = get_config(p, DEFAULTS, 'roles_path', 'ANSIBLE_ROLES_PATH', '/etc/ansible/roles', ispathlist=True, expand_relative_paths=True) diff --git a/lib/ansible/module_utils/basic.py b/lib/ansible/module_utils/basic.py index 12add4eb38..67062ed64e 100644 --- a/lib/ansible/module_utils/basic.py +++ b/lib/ansible/module_utils/basic.py @@ -639,7 +639,7 @@ class AnsibleModule(object): self.check_mode = False self.no_log = no_log self.cleanup_files = [] - self._debug = False + self._debug = 0 self._diff = False self._verbosity = 0 # May be used to set modifications to the environment for any @@ -1271,7 +1271,10 @@ class AnsibleModule(object): self.no_log = self.boolean(v) elif k == '_ansible_debug': - self._debug = self.boolean(v) + try: + self._debug = int(v) + except ValueError: + self._debug = 0 elif k == '_ansible_diff': self._diff = self.boolean(v) @@ -1615,8 +1618,8 @@ class AnsibleModule(object): syslog.openlog(str(module), 0, facility) syslog.syslog(syslog.LOG_INFO, msg) - def debug(self, msg): - if self._debug: + def debug(self, msg, caplevel=0): + if self._debug > caplevel: self.log(msg) def log(self, msg, log_args=None): diff --git a/lib/ansible/playbook/play_context.py b/lib/ansible/playbook/play_context.py index b03d47d371..598adb7659 100644 --- a/lib/ansible/playbook/play_context.py +++ b/lib/ansible/playbook/play_context.py @@ -192,6 +192,7 @@ class PlayContext(Base): # general flags _verbosity = FieldAttribute(isa='int', default=0) + _debug_verbosity = FieldAttribute(isa='int', default=0) _only_tags = FieldAttribute(isa='set', default=set()) _skip_tags = FieldAttribute(isa='set', default=set()) _check_mode = FieldAttribute(isa='bool', default=False) @@ -273,7 +274,7 @@ class PlayContext(Base): setattr(self, flag, getattr(options,flag, '')) # general flags (should we move out?) - for flag in ['connection','remote_user', 'private_key_file', 'verbosity', 'force_handlers', 'step', 'start_at_task', 'diff']: + for flag in ['connection','remote_user', 'private_key_file', 'verbosity', 'debug_verbosity', 'force_handlers', 'step', 'start_at_task', 'diff']: attribute = getattr(options, flag, False) if attribute: setattr(self, flag, attribute) diff --git a/lib/ansible/utils/display.py b/lib/ansible/utils/display.py index 93df39bb1d..9f4723859f 100644 --- a/lib/ansible/utils/display.py +++ b/lib/ansible/utils/display.py @@ -38,14 +38,6 @@ from ansible.utils.color import stringc from ansible.utils.unicode import to_bytes, to_unicode try: - from __main__ import debug_lock -except ImportError: - # for those not using a CLI, though ... - # this might not work well after fork - from multiprocessing import Lock - debug_lock = Lock() - -try: # Python 2 input = raw_input except NameError: @@ -69,10 +61,11 @@ if C.DEFAULT_LOG_PATH: class Display: - def __init__(self, verbosity=0): + def __init__(self, verbosity=0, debug_verbosity=0): self.columns = None self.verbosity = verbosity + self.debug_verbosity = debug_verbosity # list of all deprecation messages to prevent duplicate display self._deprecations = {} @@ -182,12 +175,6 @@ class Display: def vvvvvv(self, msg, host=None): return self.verbose(msg, host=host, caplevel=5) - def debug(self, msg): - if C.DEFAULT_DEBUG: - debug_lock.acquire() - self.display("%6d %0.5f: %s" % (os.getpid(), time.time(), msg), color=C.COLOR_DEBUG) - debug_lock.release() - def verbose(self, msg, host=None, caplevel=2): # FIXME: this needs to be implemented #msg = utils.sanitize_output(msg) @@ -197,6 +184,25 @@ class Display: else: self.display("<%s> %s" % (host, msg), color=C.COLOR_VERBOSE, screen_only=True) + def debug(self, msg, caplevel=0): + if self.debug_verbosity > caplevel: + self.display("%6d %0.5f: %s" % (os.getpid(), time.time(), msg), color=C.COLOR_DEBUG) + + def d(self, msg): + self.debug(msg, caplevel=1) + + def dd(self, msg): + self.debug(msg, caplevel=2) + + def ddd(self, msg): + self.debug(msg, caplevel=3) + + def dddd(self, msg): + self.debug(msg, caplevel=4) + + def ddddd(self, msg): + self.debug(msg, caplevel=5) + def deprecated(self, msg, version=None, removed=False): ''' used to print out a deprecation message.''' |