From 62979efa140ce9659beac6442b51bd8efe35d4ba Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Wed, 11 Nov 2015 10:19:58 -0800 Subject: [PATCH] Finish up plugin porting to global display Also remove display = display which does nothing --- lib/ansible/cli/__init__.py | 1 - lib/ansible/cli/adhoc.py | 1 - lib/ansible/cli/doc.py | 1 - lib/ansible/cli/galaxy.py | 1 - lib/ansible/cli/playbook.py | 1 - lib/ansible/cli/pull.py | 1 - lib/ansible/cli/vault.py | 1 - lib/ansible/executor/playbook_executor.py | 1 - lib/ansible/executor/task_executor.py | 1 - lib/ansible/executor/task_queue_manager.py | 7 +-- lib/ansible/playbook/become.py | 1 - lib/ansible/playbook/play.py | 1 - lib/ansible/playbook/play_context.py | 1 - lib/ansible/playbook/role/requirement.py | 1 - lib/ansible/playbook/task.py | 1 - lib/ansible/plugins/action/add_host.py | 1 - lib/ansible/plugins/action/package.py | 1 - lib/ansible/plugins/action/pause.py | 1 - lib/ansible/plugins/cache/base.py | 1 + lib/ansible/plugins/cache/jsonfile.py | 1 - lib/ansible/plugins/callback/__init__.py | 14 ++++- lib/ansible/plugins/connection/accelerate.py | 1 - lib/ansible/plugins/connection/chroot.py | 1 - lib/ansible/plugins/connection/docker.py | 1 - lib/ansible/plugins/connection/jail.py | 1 - lib/ansible/plugins/connection/libvirt_lxc.py | 1 - lib/ansible/plugins/connection/local.py | 1 - .../plugins/connection/paramiko_ssh.py | 1 - lib/ansible/plugins/connection/ssh.py | 1 - lib/ansible/plugins/connection/winrm.py | 1 - lib/ansible/plugins/connection/zone.py | 1 - lib/ansible/plugins/lookup/file.py | 1 - lib/ansible/plugins/lookup/template.py | 1 - lib/ansible/plugins/lookup/url.py | 1 - lib/ansible/plugins/strategy/__init__.py | 55 ++++++++++--------- lib/ansible/plugins/strategy/free.py | 23 ++++---- lib/ansible/plugins/strategy/linear.py | 27 ++++----- lib/ansible/utils/encrypt.py | 1 - lib/ansible/vars/__init__.py | 1 - 39 files changed, 68 insertions(+), 92 deletions(-) diff --git a/lib/ansible/cli/__init__.py b/lib/ansible/cli/__init__.py index f1839fdc0b..012872be7c 100644 --- a/lib/ansible/cli/__init__.py +++ b/lib/ansible/cli/__init__.py @@ -36,7 +36,6 @@ from ansible.utils.unicode import to_bytes try: from __main__ import display - display = display except ImportError: from ansible.utils.display import Display display = Display() diff --git a/lib/ansible/cli/adhoc.py b/lib/ansible/cli/adhoc.py index 0ebae3a27a..25f29fc297 100644 --- a/lib/ansible/cli/adhoc.py +++ b/lib/ansible/cli/adhoc.py @@ -36,7 +36,6 @@ from ansible.vars import VariableManager try: from __main__ import display - display = display except ImportError: from ansible.utils.display import Display display = Display() diff --git a/lib/ansible/cli/doc.py b/lib/ansible/cli/doc.py index d4a713142b..4eef1dd5dd 100644 --- a/lib/ansible/cli/doc.py +++ b/lib/ansible/cli/doc.py @@ -33,7 +33,6 @@ from ansible.utils import module_docs try: from __main__ import display - display = display except ImportError: from ansible.utils.display import Display display = Display() diff --git a/lib/ansible/cli/galaxy.py b/lib/ansible/cli/galaxy.py index c6dc1ad658..31c21146fc 100644 --- a/lib/ansible/cli/galaxy.py +++ b/lib/ansible/cli/galaxy.py @@ -40,7 +40,6 @@ from ansible.playbook.role.requirement import RoleRequirement try: from __main__ import display - display = display except ImportError: from ansible.utils.display import Display display = Display() diff --git a/lib/ansible/cli/playbook.py b/lib/ansible/cli/playbook.py index 2407e35048..fc81f96456 100644 --- a/lib/ansible/cli/playbook.py +++ b/lib/ansible/cli/playbook.py @@ -35,7 +35,6 @@ from ansible.vars import VariableManager try: from __main__ import display - display = display except ImportError: from ansible.utils.display import Display display = Display() diff --git a/lib/ansible/cli/pull.py b/lib/ansible/cli/pull.py index 841bf2b3c3..04586c1d0c 100644 --- a/lib/ansible/cli/pull.py +++ b/lib/ansible/cli/pull.py @@ -35,7 +35,6 @@ from ansible.utils.cmd_functions import run_cmd try: from __main__ import display - display = display except ImportError: from ansible.utils.display import Display display = Display() diff --git a/lib/ansible/cli/vault.py b/lib/ansible/cli/vault.py index 82516085b8..ac148d4770 100644 --- a/lib/ansible/cli/vault.py +++ b/lib/ansible/cli/vault.py @@ -29,7 +29,6 @@ from ansible.cli import CLI try: from __main__ import display - display = display except ImportError: from ansible.utils.display import Display display = Display() diff --git a/lib/ansible/executor/playbook_executor.py b/lib/ansible/executor/playbook_executor.py index 19e812804c..b6cbf2b1ba 100644 --- a/lib/ansible/executor/playbook_executor.py +++ b/lib/ansible/executor/playbook_executor.py @@ -37,7 +37,6 @@ from ansible.utils.unicode import to_unicode try: from __main__ import display - display = display except ImportError: from ansible.utils.display import Display display = Display() diff --git a/lib/ansible/executor/task_executor.py b/lib/ansible/executor/task_executor.py index 06a7008275..592f652a8b 100644 --- a/lib/ansible/executor/task_executor.py +++ b/lib/ansible/executor/task_executor.py @@ -39,7 +39,6 @@ from ansible.vars.unsafe_proxy import UnsafeProxy try: from __main__ import display - display = display except ImportError: from ansible.utils.display import Display display = Display() diff --git a/lib/ansible/executor/task_queue_manager.py b/lib/ansible/executor/task_queue_manager.py index fd910c3067..001d71e9e0 100644 --- a/lib/ansible/executor/task_queue_manager.py +++ b/lib/ansible/executor/task_queue_manager.py @@ -35,7 +35,6 @@ from ansible.template import Templar try: from __main__ import display - display = display except ImportError: from ansible.utils.display import Display display = Display() @@ -161,11 +160,7 @@ class TaskQueueManager: elif callback_needs_whitelist and (C.DEFAULT_CALLBACK_WHITELIST is None or callback_name not in C.DEFAULT_CALLBACK_WHITELIST): continue - # is it too late to change the API for v2 callback plugins? - # display is not necessary. - self._callback_plugins.append(callback_plugin(display)) - else: - self._callback_plugins.append(callback_plugin()) + self._callback_plugins.append(callback_plugin()) self._callbacks_loaded = True diff --git a/lib/ansible/playbook/become.py b/lib/ansible/playbook/become.py index 47d1eedfa6..643f2b555d 100644 --- a/lib/ansible/playbook/become.py +++ b/lib/ansible/playbook/become.py @@ -25,7 +25,6 @@ from ansible.playbook.attribute import Attribute, FieldAttribute try: from __main__ import display - display = display except ImportError: from ansible.utils.display import Display display = Display() diff --git a/lib/ansible/playbook/play.py b/lib/ansible/playbook/play.py index db96c29372..ed61416e95 100644 --- a/lib/ansible/playbook/play.py +++ b/lib/ansible/playbook/play.py @@ -34,7 +34,6 @@ from ansible.vars import preprocess_vars try: from __main__ import display - display = display except ImportError: from ansible.utils.display import Display display = Display() diff --git a/lib/ansible/playbook/play_context.py b/lib/ansible/playbook/play_context.py index 00d6d2e1ef..d8c1d4cfb9 100644 --- a/lib/ansible/playbook/play_context.py +++ b/lib/ansible/playbook/play_context.py @@ -39,7 +39,6 @@ __all__ = ['PlayContext'] try: from __main__ import display - display = display except ImportError: from ansible.utils.display import Display display = Display() diff --git a/lib/ansible/playbook/role/requirement.py b/lib/ansible/playbook/role/requirement.py index 21cb573b93..1a640247e2 100644 --- a/lib/ansible/playbook/role/requirement.py +++ b/lib/ansible/playbook/role/requirement.py @@ -42,7 +42,6 @@ VALID_SPEC_KEYS = [ try: from __main__ import display - display = display except ImportError: from ansible.utils.display import Display display = Display() diff --git a/lib/ansible/playbook/task.py b/lib/ansible/playbook/task.py index 82226554c6..38cca4b3a2 100644 --- a/lib/ansible/playbook/task.py +++ b/lib/ansible/playbook/task.py @@ -38,7 +38,6 @@ from ansible.playbook.taggable import Taggable try: from __main__ import display - display = display except ImportError: from ansible.utils.display import Display display = Display() diff --git a/lib/ansible/plugins/action/add_host.py b/lib/ansible/plugins/action/add_host.py index 08fac722e9..4bf43f1400 100644 --- a/lib/ansible/plugins/action/add_host.py +++ b/lib/ansible/plugins/action/add_host.py @@ -26,7 +26,6 @@ from ansible.errors import AnsibleError try: from __main__ import display - display = display except ImportError: from ansible.utils.display import Display display = Display() diff --git a/lib/ansible/plugins/action/package.py b/lib/ansible/plugins/action/package.py index 8e68c21f51..87759289cc 100644 --- a/lib/ansible/plugins/action/package.py +++ b/lib/ansible/plugins/action/package.py @@ -21,7 +21,6 @@ from ansible.plugins.action import ActionBase try: from __main__ import display - display = display except ImportError: from ansible.utils.display import Display display = Display() diff --git a/lib/ansible/plugins/action/pause.py b/lib/ansible/plugins/action/pause.py index 2d7eb1b0ae..f3a70ed7e3 100644 --- a/lib/ansible/plugins/action/pause.py +++ b/lib/ansible/plugins/action/pause.py @@ -29,7 +29,6 @@ from ansible.plugins.action import ActionBase try: from __main__ import display - display = display except ImportError: from ansible.utils.display import Display display = Display() diff --git a/lib/ansible/plugins/cache/base.py b/lib/ansible/plugins/cache/base.py index 16d0ef7c71..0367d01534 100644 --- a/lib/ansible/plugins/cache/base.py +++ b/lib/ansible/plugins/cache/base.py @@ -31,6 +31,7 @@ except ImportError: class BaseCacheModule(with_metaclass(ABCMeta, object)): + # Backwards compat only. Just import the global display instead _display = display @abstractmethod diff --git a/lib/ansible/plugins/cache/jsonfile.py b/lib/ansible/plugins/cache/jsonfile.py index e09042c1a8..6a1012aa18 100644 --- a/lib/ansible/plugins/cache/jsonfile.py +++ b/lib/ansible/plugins/cache/jsonfile.py @@ -37,7 +37,6 @@ from ansible.utils.unicode import to_bytes try: from __main__ import display - display = display except ImportError: from ansible.utils.display import Display display = Display() diff --git a/lib/ansible/plugins/callback/__init__.py b/lib/ansible/plugins/callback/__init__.py index 6df5e154d8..2b6875ae20 100644 --- a/lib/ansible/plugins/callback/__init__.py +++ b/lib/ansible/plugins/callback/__init__.py @@ -30,6 +30,12 @@ from ansible import constants as C from ansible.vars import strip_internal_keys from ansible.utils.unicode import to_unicode +try: + from __main__ import display as global_display +except ImportError: + from ansible.utils.display import Display + global_display = Display() + __all__ = ["CallbackBase"] @@ -41,8 +47,12 @@ class CallbackBase: custom actions. ''' - def __init__(self, display): - self._display = display + def __init__(self, display=None): + if display: + self._display = display + else: + self._display = global_display + if self._display.verbosity >= 4: name = getattr(self, 'CALLBACK_NAME', 'unnamed') ctype = getattr(self, 'CALLBACK_TYPE', 'old') diff --git a/lib/ansible/plugins/connection/accelerate.py b/lib/ansible/plugins/connection/accelerate.py index 8d60014404..c62cc95b9b 100644 --- a/lib/ansible/plugins/connection/accelerate.py +++ b/lib/ansible/plugins/connection/accelerate.py @@ -33,7 +33,6 @@ from ansible.utils.encrypt import key_for_hostname, keyczar_encrypt, keyczar_dec try: from __main__ import display - display = display except ImportError: from ansible.utils.display import Display display = Display() diff --git a/lib/ansible/plugins/connection/chroot.py b/lib/ansible/plugins/connection/chroot.py index 6d4c2ec5fb..c86ea1fc35 100644 --- a/lib/ansible/plugins/connection/chroot.py +++ b/lib/ansible/plugins/connection/chroot.py @@ -33,7 +33,6 @@ from ansible.module_utils.basic import is_executable try: from __main__ import display - display = display except ImportError: from ansible.utils.display import Display display = Display() diff --git a/lib/ansible/plugins/connection/docker.py b/lib/ansible/plugins/connection/docker.py index 990b743d74..308dea0edc 100644 --- a/lib/ansible/plugins/connection/docker.py +++ b/lib/ansible/plugins/connection/docker.py @@ -39,7 +39,6 @@ from ansible.plugins.connection import ConnectionBase try: from __main__ import display - display = display except ImportError: from ansible.utils.display import Display display = Display() diff --git a/lib/ansible/plugins/connection/jail.py b/lib/ansible/plugins/connection/jail.py index 1780821603..e665692543 100644 --- a/lib/ansible/plugins/connection/jail.py +++ b/lib/ansible/plugins/connection/jail.py @@ -33,7 +33,6 @@ from ansible.plugins.connection import ConnectionBase try: from __main__ import display - display = display except ImportError: from ansible.utils.display import Display display = Display() diff --git a/lib/ansible/plugins/connection/libvirt_lxc.py b/lib/ansible/plugins/connection/libvirt_lxc.py index 23b8475c36..dc82d98404 100644 --- a/lib/ansible/plugins/connection/libvirt_lxc.py +++ b/lib/ansible/plugins/connection/libvirt_lxc.py @@ -33,7 +33,6 @@ from ansible.plugins.connection import ConnectionBase try: from __main__ import display - display = display except ImportError: from ansible.utils.display import Display display = Display() diff --git a/lib/ansible/plugins/connection/local.py b/lib/ansible/plugins/connection/local.py index 90d313969f..0244f90d59 100644 --- a/lib/ansible/plugins/connection/local.py +++ b/lib/ansible/plugins/connection/local.py @@ -32,7 +32,6 @@ from ansible.plugins.connection import ConnectionBase try: from __main__ import display - display = display except ImportError: from ansible.utils.display import Display display = Display() diff --git a/lib/ansible/plugins/connection/paramiko_ssh.py b/lib/ansible/plugins/connection/paramiko_ssh.py index 6c4dd43cae..ab9ce90db9 100644 --- a/lib/ansible/plugins/connection/paramiko_ssh.py +++ b/lib/ansible/plugins/connection/paramiko_ssh.py @@ -45,7 +45,6 @@ from ansible.utils.path import makedirs_safe try: from __main__ import display - display = display except ImportError: from ansible.utils.display import Display display = Display() diff --git a/lib/ansible/plugins/connection/ssh.py b/lib/ansible/plugins/connection/ssh.py index e7183619c9..fc8b9a1105 100644 --- a/lib/ansible/plugins/connection/ssh.py +++ b/lib/ansible/plugins/connection/ssh.py @@ -36,7 +36,6 @@ from ansible.utils.unicode import to_bytes, to_unicode try: from __main__ import display - display = display except ImportError: from ansible.utils.display import Display display = Display() diff --git a/lib/ansible/plugins/connection/winrm.py b/lib/ansible/plugins/connection/winrm.py index 0a65fa031c..f75c7a7092 100644 --- a/lib/ansible/plugins/connection/winrm.py +++ b/lib/ansible/plugins/connection/winrm.py @@ -49,7 +49,6 @@ from ansible.utils.unicode import to_bytes, to_unicode, to_str try: from __main__ import display - display = display except ImportError: from ansible.utils.display import Display display = Display() diff --git a/lib/ansible/plugins/connection/zone.py b/lib/ansible/plugins/connection/zone.py index 3af95b9f15..f0001d3c9e 100644 --- a/lib/ansible/plugins/connection/zone.py +++ b/lib/ansible/plugins/connection/zone.py @@ -34,7 +34,6 @@ from ansible.plugins.connection import ConnectionBase try: from __main__ import display - display = display except ImportError: from ansible.utils.display import Display display = Display() diff --git a/lib/ansible/plugins/lookup/file.py b/lib/ansible/plugins/lookup/file.py index abc77c601d..5dd31d9c88 100644 --- a/lib/ansible/plugins/lookup/file.py +++ b/lib/ansible/plugins/lookup/file.py @@ -22,7 +22,6 @@ from ansible.plugins.lookup import LookupBase try: from __main__ import display - display = display except ImportError: from ansible.utils.display import Display display = Display() diff --git a/lib/ansible/plugins/lookup/template.py b/lib/ansible/plugins/lookup/template.py index 439b805979..569ede6276 100644 --- a/lib/ansible/plugins/lookup/template.py +++ b/lib/ansible/plugins/lookup/template.py @@ -25,7 +25,6 @@ from ansible.plugins.lookup import LookupBase try: from __main__ import display - display = display except ImportError: from ansible.utils.display import Display display = Display() diff --git a/lib/ansible/plugins/lookup/url.py b/lib/ansible/plugins/lookup/url.py index d40bb54c39..9f643bc420 100644 --- a/lib/ansible/plugins/lookup/url.py +++ b/lib/ansible/plugins/lookup/url.py @@ -26,7 +26,6 @@ from ansible.utils.unicode import to_unicode try: from __main__ import display - display = display except ImportError: from ansible.utils.display import Display display = Display() diff --git a/lib/ansible/plugins/strategy/__init__.py b/lib/ansible/plugins/strategy/__init__.py index 4e20741268..db816b137e 100644 --- a/lib/ansible/plugins/strategy/__init__.py +++ b/lib/ansible/plugins/strategy/__init__.py @@ -23,8 +23,6 @@ from ansible.compat.six.moves import queue as Queue from ansible.compat.six import iteritems, text_type, string_types import json -import pickle -import sys import time import zlib @@ -35,13 +33,11 @@ from ansible.errors import AnsibleError, AnsibleParserError, AnsibleUndefinedVar from ansible.executor.task_result import TaskResult from ansible.inventory.host import Host from ansible.inventory.group import Group -from ansible.playbook.handler import Handler from ansible.playbook.helpers import load_list_of_blocks from ansible.playbook.included_file import IncludedFile -from ansible.playbook.role import hash_params from ansible.plugins import action_loader, connection_loader, filter_loader, lookup_loader, module_loader, test_loader from ansible.template import Templar -from ansible.vars.unsafe_proxy import wrap_var, AnsibleJSONUnsafeEncoder +from ansible.vars.unsafe_proxy import wrap_var try: from __main__ import display @@ -51,6 +47,7 @@ except ImportError: __all__ = ['StrategyBase'] + # TODO: this should probably be in the plugins/__init__.py, with # a smarter mechanism to set all of the attributes based on # the loaders created there @@ -67,6 +64,7 @@ class SharedPluginLoaderObj: self.lookup_loader = lookup_loader self.module_loader = module_loader + class StrategyBase: ''' @@ -84,6 +82,7 @@ class StrategyBase: self._final_q = tqm._final_q self._step = getattr(tqm._options, 'step', False) self._diff = getattr(tqm._options, 'diff', False) + # Backwards compat: self._display isn't really needed, just import the global display and use that. self._display = display # internal counters @@ -100,7 +99,7 @@ class StrategyBase: failed_hosts = self._tqm._failed_hosts.keys() unreachable_hosts = self._tqm._unreachable_hosts.keys() - self._display.debug("running handlers") + display.debug("running handlers") result &= self.run_handlers(iterator, play_context) # now update with the hosts (if any) that failed or were @@ -121,7 +120,8 @@ class StrategyBase: return 0 def get_hosts_remaining(self, play): - return [host for host in self._inventory.get_hosts(play.hosts) if host.name not in self._tqm._failed_hosts and host.name not in self._tqm._unreachable_hosts] + return [host for host in self._inventory.get_hosts(play.hosts) + if host.name not in self._tqm._failed_hosts and host.name not in self._tqm._unreachable_hosts] def get_failed_hosts(self, play): return [host for host in self._inventory.get_hosts(play.hosts) if host.name in self._tqm._failed_hosts] @@ -137,12 +137,12 @@ class StrategyBase: def _queue_task(self, host, task, task_vars, play_context): ''' handles queueing the task up to be sent to a worker ''' - self._display.debug("entering _queue_task() for %s/%s" % (host, task)) + display.debug("entering _queue_task() for %s/%s" % (host, task)) # and then queue the new task - self._display.debug("%s - putting task (%s) in queue" % (host, task)) + display.debug("%s - putting task (%s) in queue" % (host, task)) try: - self._display.debug("worker is %d (out of %d available)" % (self._cur_worker+1, len(self._workers))) + display.debug("worker is %d (out of %d available)" % (self._cur_worker+1, len(self._workers))) (worker_prc, main_q, rslt_q) = self._workers[self._cur_worker] self._cur_worker += 1 @@ -167,7 +167,7 @@ class StrategyBase: # data contained in the dict is very large del task_vars else: - zip_vars = task_vars + zip_vars = task_vars # noqa (pyflakes false positive because task_vars is deleted in the conditional above) # and queue the task main_q.put((host, task, self._loader.get_basedir(), zip_vars, hostvars, compressed_vars, play_context, shared_loader_obj), block=False) @@ -178,9 +178,9 @@ class StrategyBase: self._pending_results += 1 except (EOFError, IOError, AssertionError) as e: # most likely an abort - self._display.debug("got an error while queuing: %s" % e) + display.debug("got an error while queuing: %s" % e) return - self._display.debug("exiting _queue_task() for %s/%s" % (host, task)) + display.debug("exiting _queue_task() for %s/%s" % (host, task)) def _process_pending_results(self, iterator): ''' @@ -193,7 +193,7 @@ class StrategyBase: while not self._final_q.empty() and not self._tqm._terminated: try: result = self._final_q.get(block=False) - self._display.debug("got result from result worker: %s" % ([text_type(x) for x in result],)) + display.debug("got result from result worker: %s" % ([text_type(x) for x in result],)) # all host status messages contain 2 entries: (msg, task_result) if result[0] in ('host_task_ok', 'host_task_failed', 'host_task_skipped', 'host_unreachable'): @@ -202,7 +202,7 @@ class StrategyBase: task = task_result._task if result[0] == 'host_task_failed' or task_result.is_failed(): if not task.ignore_errors: - self._display.debug("marking %s as failed" % host.name) + display.debug("marking %s as failed" % host.name) if task.run_once: # if we're using run_once, we have to fail every host here [iterator.mark_host_failed(h) for h in self._inventory.get_hosts(iterator._play.hosts) if h.name not in self._tqm._unreachable_hosts] @@ -266,7 +266,7 @@ class StrategyBase: if task_result._host not in self._notified_handlers[handler_name]: self._notified_handlers[handler_name].append(task_result._host) - self._display.vv("NOTIFIED HANDLER %s" % (handler_name,)) + display.vv("NOTIFIED HANDLER %s" % (handler_name,)) elif result[0] == 'register_host_var': # essentially the same as 'set_host_var' below, however we @@ -323,12 +323,12 @@ class StrategyBase: ret_results = [] - self._display.debug("waiting for pending results...") + display.debug("waiting for pending results...") while self._pending_results > 0 and not self._tqm._terminated: results = self._process_pending_results(iterator) ret_results.extend(results) time.sleep(0.01) - self._display.debug("no more pending results, returning what we have") + display.debug("no more pending results, returning what we have") return ret_results @@ -468,8 +468,9 @@ class StrategyBase: tags = [ tags ] if len(tags) > 0: if len(b._task_include.tags) > 0: - raise AnsibleParserError("Include tasks should not specify tags in more than one way (both via args and directly on the task)", obj=included_file._task._ds) - self._display.deprecated("You should not specify tags in the include parameters. All tags should be specified using the task-level option") + raise AnsibleParserError("Include tasks should not specify tags in more than one way (both via args and directly on the task)", + obj=included_file._task._ds) + display.deprecated("You should not specify tags in the include parameters. All tags should be specified using the task-level option") b._task_include.tags = tags b._task_include.vars = temp_vars @@ -579,12 +580,12 @@ class StrategyBase: for host in included_file._hosts: iterator.mark_host_failed(host) self._tqm._failed_hosts[host.name] = True - self._display.warning(str(e)) + display.warning(str(e)) continue # wipe the notification list self._notified_handlers[handler_name] = [] - self._display.debug("done running handlers, result is: %s" % result) + display.debug("done running handlers, result is: %s" % result) return result def _take_step(self, task, host=None): @@ -594,19 +595,19 @@ class StrategyBase: msg = u'Perform task: %s on %s (y/n/c): ' % (task, host) else: msg = u'Perform task: %s (y/n/c): ' % task - resp = self._display.prompt(msg) + resp = display.prompt(msg) if resp.lower() in ['y','yes']: - self._display.debug("User ran task") + display.debug("User ran task") ret = True elif resp.lower() in ['c', 'continue']: - self._display.debug("User ran task and cancled step mode") + display.debug("User ran task and cancled step mode") self._step = False ret = True else: - self._display.debug("User skipped task") + display.debug("User skipped task") - self._display.banner(msg) + display.banner(msg) return ret diff --git a/lib/ansible/plugins/strategy/free.py b/lib/ansible/plugins/strategy/free.py index 17ca99694b..2d3c184a8c 100644 --- a/lib/ansible/plugins/strategy/free.py +++ b/lib/ansible/plugins/strategy/free.py @@ -31,6 +31,7 @@ except ImportError: from ansible.utils.display import Display display = Display() + class StrategyModule(StrategyBase): def run(self, iterator, play_context): @@ -69,31 +70,31 @@ class StrategyModule(StrategyBase): host_results = [] while True: host = hosts_left[last_host] - self._display.debug("next free host: %s" % host) + display.debug("next free host: %s" % host) host_name = host.get_name() # peek at the next task for the host, to see if there's # anything to do do for this host (state, task) = iterator.get_next_task_for_host(host, peek=True) - self._display.debug("free host state: %s" % state) - self._display.debug("free host task: %s" % task) + display.debug("free host state: %s" % state) + display.debug("free host task: %s" % task) if host_name not in self._tqm._failed_hosts and host_name not in self._tqm._unreachable_hosts and task: # set the flag so the outer loop knows we've still found # some work which needs to be done work_to_do = True - self._display.debug("this host has work to do") + display.debug("this host has work to do") # check to see if this host is blocked (still executing a previous task) - if not host_name in self._blocked_hosts or not self._blocked_hosts[host_name]: + if host_name not in self._blocked_hosts or not self._blocked_hosts[host_name]: # pop the task, mark the host blocked, and queue it self._blocked_hosts[host_name] = True (state, task) = iterator.get_next_task_for_host(host) - self._display.debug("getting variables") + display.debug("getting variables") task_vars = self._variable_manager.get_vars(loader=self._loader, play=iterator._play, host=host, task=task) - self._display.debug("done getting variables") + display.debug("done getting variables") # check to see if this task should be skipped, due to it being a member of a # role which has already run (and whether that role allows duplicate execution) @@ -101,7 +102,7 @@ class StrategyModule(StrategyBase): # If there is no metadata, the default behavior is to not allow duplicates, # if there is metadata, check to see if the allow_duplicates flag was set to true if task._role._metadata is None or task._role._metadata and not task._role._metadata.allow_duplicates: - self._display.debug("'%s' skipped because role has already run" % task) + display.debug("'%s' skipped because role has already run" % task) continue if task.action == 'meta': @@ -138,7 +139,8 @@ class StrategyModule(StrategyBase): host_results.extend(results) try: - included_files = IncludedFile.process_include_results(host_results, self._tqm, iterator=iterator, loader=self._loader, variable_manager=self._variable_manager) + included_files = IncludedFile.process_include_results(host_results, self._tqm, iterator=iterator, + loader=self._loader, variable_manager=self._variable_manager) except AnsibleError as e: return False @@ -151,7 +153,7 @@ class StrategyModule(StrategyBase): except AnsibleError as e: for host in included_file._hosts: iterator.mark_host_failed(host) - self._display.warning(str(e)) + display.warning(str(e)) continue for host in hosts_left: @@ -174,4 +176,3 @@ class StrategyModule(StrategyBase): # run the base class run() method, which executes the cleanup function # and runs any outstanding handlers which have been triggered return super(StrategyModule, self).run(iterator, play_context, result) - diff --git a/lib/ansible/plugins/strategy/linear.py b/lib/ansible/plugins/strategy/linear.py index 0b5e0627bd..56824689c6 100644 --- a/lib/ansible/plugins/strategy/linear.py +++ b/lib/ansible/plugins/strategy/linear.py @@ -154,9 +154,9 @@ class StrategyModule(StrategyBase): while work_to_do and not self._tqm._terminated: try: - self._display.debug("getting the remaining hosts for this loop") + display.debug("getting the remaining hosts for this loop") hosts_left = [host for host in self._inventory.get_hosts(iterator._play.hosts) if host.name not in self._tqm._unreachable_hosts] - self._display.debug("done getting the remaining hosts for this loop") + display.debug("done getting the remaining hosts for this loop") # queue up this task for each host in the inventory callback_sent = False @@ -198,7 +198,7 @@ class StrategyModule(StrategyBase): # If there is no metadata, the default behavior is to not allow duplicates, # if there is metadata, check to see if the allow_duplicates flag was set to true if task._role._metadata is None or task._role._metadata and not task._role._metadata.allow_duplicates: - self._display.debug("'%s' skipped because role has already run" % task) + display.debug("'%s' skipped because role has already run" % task) continue if task.action == 'meta': @@ -212,11 +212,11 @@ class StrategyModule(StrategyBase): skip_rest = True break - self._display.debug("getting variables") + display.debug("getting variables") task_vars = self._variable_manager.get_vars(loader=self._loader, play=iterator._play, host=host, task=task) self.add_tqm_variables(task_vars, play=iterator._play) templar = Templar(loader=self._loader, variables=task_vars) - self._display.debug("done getting variables") + display.debug("done getting variables") if not callback_sent: display.debug("sending task start callback, copying the task so we can template it temporarily") @@ -250,18 +250,19 @@ class StrategyModule(StrategyBase): if skip_rest: continue - self._display.debug("done queuing things up, now waiting for results queue to drain") + display.debug("done queuing things up, now waiting for results queue to drain") results = self._wait_on_pending_results(iterator) host_results.extend(results) if not work_to_do and len(iterator.get_failed_hosts()) > 0: - self._display.debug("out of hosts to run on") + display.debug("out of hosts to run on") self._tqm.send_callback('v2_playbook_on_no_hosts_remaining') result = False break try: - included_files = IncludedFile.process_include_results(host_results, self._tqm, iterator=iterator, loader=self._loader, variable_manager=self._variable_manager) + included_files = IncludedFile.process_include_results(host_results, self._tqm, + iterator=iterator, loader=self._loader, variable_manager=self._variable_manager) except AnsibleError as e: return False @@ -285,7 +286,8 @@ class StrategyModule(StrategyBase): noop_block.rescue = [noop_task for t in new_block.rescue] for host in hosts_left: if host in included_file._hosts: - task_vars = self._variable_manager.get_vars(loader=self._loader, play=iterator._play, host=host, task=included_file._task) + task_vars = self._variable_manager.get_vars(loader=self._loader, + play=iterator._play, host=host, task=included_file._task) final_block = new_block.filter_tagged_tasks(play_context, task_vars) all_blocks[host].append(final_block) else: @@ -295,7 +297,7 @@ class StrategyModule(StrategyBase): for host in included_file._hosts: self._tqm._failed_hosts[host.name] = True iterator.mark_host_failed(host) - self._display.error(e, wrap_text=False) + display.error(e, wrap_text=False) continue # finally go through all of the hosts and append the @@ -303,9 +305,9 @@ class StrategyModule(StrategyBase): for host in hosts_left: iterator.add_tasks(host, all_blocks[host]) - self._display.debug("results queue empty") + display.debug("results queue empty") except (IOError, EOFError) as e: - self._display.debug("got IOError/EOFError in task loop: %s" % e) + display.debug("got IOError/EOFError in task loop: %s" % e) # most likely an abort, return failed return False @@ -313,4 +315,3 @@ class StrategyModule(StrategyBase): # and runs any outstanding handlers which have been triggered return super(StrategyModule, self).run(iterator, play_context, result) - diff --git a/lib/ansible/utils/encrypt.py b/lib/ansible/utils/encrypt.py index 976bf5028f..d00a89bb1c 100644 --- a/lib/ansible/utils/encrypt.py +++ b/lib/ansible/utils/encrypt.py @@ -32,7 +32,6 @@ except: try: from __main__ import display - display = display except ImportError: from ansible.utils.display import Display display = Display() diff --git a/lib/ansible/vars/__init__.py b/lib/ansible/vars/__init__.py index ad2b2d1dc4..26f52adfb0 100644 --- a/lib/ansible/vars/__init__.py +++ b/lib/ansible/vars/__init__.py @@ -48,7 +48,6 @@ from ansible.vars.unsafe_proxy import wrap_var try: from __main__ import display - display = display except ImportError: from ansible.utils.display import Display display = Display()