1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Finish up plugin porting to global display

Also remove display = display which does nothing
This commit is contained in:
Toshio Kuratomi 2015-11-11 10:19:58 -08:00
parent 2bd695ed42
commit 62979efa14
39 changed files with 68 additions and 92 deletions

View file

@ -36,7 +36,6 @@ from ansible.utils.unicode import to_bytes
try: try:
from __main__ import display from __main__ import display
display = display
except ImportError: except ImportError:
from ansible.utils.display import Display from ansible.utils.display import Display
display = Display() display = Display()

View file

@ -36,7 +36,6 @@ from ansible.vars import VariableManager
try: try:
from __main__ import display from __main__ import display
display = display
except ImportError: except ImportError:
from ansible.utils.display import Display from ansible.utils.display import Display
display = Display() display = Display()

View file

@ -33,7 +33,6 @@ from ansible.utils import module_docs
try: try:
from __main__ import display from __main__ import display
display = display
except ImportError: except ImportError:
from ansible.utils.display import Display from ansible.utils.display import Display
display = Display() display = Display()

View file

@ -40,7 +40,6 @@ from ansible.playbook.role.requirement import RoleRequirement
try: try:
from __main__ import display from __main__ import display
display = display
except ImportError: except ImportError:
from ansible.utils.display import Display from ansible.utils.display import Display
display = Display() display = Display()

View file

@ -35,7 +35,6 @@ from ansible.vars import VariableManager
try: try:
from __main__ import display from __main__ import display
display = display
except ImportError: except ImportError:
from ansible.utils.display import Display from ansible.utils.display import Display
display = Display() display = Display()

View file

@ -35,7 +35,6 @@ from ansible.utils.cmd_functions import run_cmd
try: try:
from __main__ import display from __main__ import display
display = display
except ImportError: except ImportError:
from ansible.utils.display import Display from ansible.utils.display import Display
display = Display() display = Display()

View file

@ -29,7 +29,6 @@ from ansible.cli import CLI
try: try:
from __main__ import display from __main__ import display
display = display
except ImportError: except ImportError:
from ansible.utils.display import Display from ansible.utils.display import Display
display = Display() display = Display()

View file

@ -37,7 +37,6 @@ from ansible.utils.unicode import to_unicode
try: try:
from __main__ import display from __main__ import display
display = display
except ImportError: except ImportError:
from ansible.utils.display import Display from ansible.utils.display import Display
display = Display() display = Display()

View file

@ -39,7 +39,6 @@ from ansible.vars.unsafe_proxy import UnsafeProxy
try: try:
from __main__ import display from __main__ import display
display = display
except ImportError: except ImportError:
from ansible.utils.display import Display from ansible.utils.display import Display
display = Display() display = Display()

View file

@ -35,7 +35,6 @@ from ansible.template import Templar
try: try:
from __main__ import display from __main__ import display
display = display
except ImportError: except ImportError:
from ansible.utils.display import Display from ansible.utils.display import Display
display = 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): elif callback_needs_whitelist and (C.DEFAULT_CALLBACK_WHITELIST is None or callback_name not in C.DEFAULT_CALLBACK_WHITELIST):
continue continue
# is it too late to change the API for v2 callback plugins? self._callback_plugins.append(callback_plugin())
# display is not necessary.
self._callback_plugins.append(callback_plugin(display))
else:
self._callback_plugins.append(callback_plugin())
self._callbacks_loaded = True self._callbacks_loaded = True

View file

@ -25,7 +25,6 @@ from ansible.playbook.attribute import Attribute, FieldAttribute
try: try:
from __main__ import display from __main__ import display
display = display
except ImportError: except ImportError:
from ansible.utils.display import Display from ansible.utils.display import Display
display = Display() display = Display()

View file

@ -34,7 +34,6 @@ from ansible.vars import preprocess_vars
try: try:
from __main__ import display from __main__ import display
display = display
except ImportError: except ImportError:
from ansible.utils.display import Display from ansible.utils.display import Display
display = Display() display = Display()

View file

@ -39,7 +39,6 @@ __all__ = ['PlayContext']
try: try:
from __main__ import display from __main__ import display
display = display
except ImportError: except ImportError:
from ansible.utils.display import Display from ansible.utils.display import Display
display = Display() display = Display()

View file

@ -42,7 +42,6 @@ VALID_SPEC_KEYS = [
try: try:
from __main__ import display from __main__ import display
display = display
except ImportError: except ImportError:
from ansible.utils.display import Display from ansible.utils.display import Display
display = Display() display = Display()

View file

@ -38,7 +38,6 @@ from ansible.playbook.taggable import Taggable
try: try:
from __main__ import display from __main__ import display
display = display
except ImportError: except ImportError:
from ansible.utils.display import Display from ansible.utils.display import Display
display = Display() display = Display()

View file

@ -26,7 +26,6 @@ from ansible.errors import AnsibleError
try: try:
from __main__ import display from __main__ import display
display = display
except ImportError: except ImportError:
from ansible.utils.display import Display from ansible.utils.display import Display
display = Display() display = Display()

View file

@ -21,7 +21,6 @@ from ansible.plugins.action import ActionBase
try: try:
from __main__ import display from __main__ import display
display = display
except ImportError: except ImportError:
from ansible.utils.display import Display from ansible.utils.display import Display
display = Display() display = Display()

View file

@ -29,7 +29,6 @@ from ansible.plugins.action import ActionBase
try: try:
from __main__ import display from __main__ import display
display = display
except ImportError: except ImportError:
from ansible.utils.display import Display from ansible.utils.display import Display
display = Display() display = Display()

View file

@ -31,6 +31,7 @@ except ImportError:
class BaseCacheModule(with_metaclass(ABCMeta, object)): class BaseCacheModule(with_metaclass(ABCMeta, object)):
# Backwards compat only. Just import the global display instead
_display = display _display = display
@abstractmethod @abstractmethod

View file

@ -37,7 +37,6 @@ from ansible.utils.unicode import to_bytes
try: try:
from __main__ import display from __main__ import display
display = display
except ImportError: except ImportError:
from ansible.utils.display import Display from ansible.utils.display import Display
display = Display() display = Display()

View file

@ -30,6 +30,12 @@ from ansible import constants as C
from ansible.vars import strip_internal_keys from ansible.vars import strip_internal_keys
from ansible.utils.unicode import to_unicode 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"] __all__ = ["CallbackBase"]
@ -41,8 +47,12 @@ class CallbackBase:
custom actions. custom actions.
''' '''
def __init__(self, display): def __init__(self, display=None):
self._display = display if display:
self._display = display
else:
self._display = global_display
if self._display.verbosity >= 4: if self._display.verbosity >= 4:
name = getattr(self, 'CALLBACK_NAME', 'unnamed') name = getattr(self, 'CALLBACK_NAME', 'unnamed')
ctype = getattr(self, 'CALLBACK_TYPE', 'old') ctype = getattr(self, 'CALLBACK_TYPE', 'old')

View file

@ -33,7 +33,6 @@ from ansible.utils.encrypt import key_for_hostname, keyczar_encrypt, keyczar_dec
try: try:
from __main__ import display from __main__ import display
display = display
except ImportError: except ImportError:
from ansible.utils.display import Display from ansible.utils.display import Display
display = Display() display = Display()

View file

@ -33,7 +33,6 @@ from ansible.module_utils.basic import is_executable
try: try:
from __main__ import display from __main__ import display
display = display
except ImportError: except ImportError:
from ansible.utils.display import Display from ansible.utils.display import Display
display = Display() display = Display()

View file

@ -39,7 +39,6 @@ from ansible.plugins.connection import ConnectionBase
try: try:
from __main__ import display from __main__ import display
display = display
except ImportError: except ImportError:
from ansible.utils.display import Display from ansible.utils.display import Display
display = Display() display = Display()

View file

@ -33,7 +33,6 @@ from ansible.plugins.connection import ConnectionBase
try: try:
from __main__ import display from __main__ import display
display = display
except ImportError: except ImportError:
from ansible.utils.display import Display from ansible.utils.display import Display
display = Display() display = Display()

View file

@ -33,7 +33,6 @@ from ansible.plugins.connection import ConnectionBase
try: try:
from __main__ import display from __main__ import display
display = display
except ImportError: except ImportError:
from ansible.utils.display import Display from ansible.utils.display import Display
display = Display() display = Display()

View file

@ -32,7 +32,6 @@ from ansible.plugins.connection import ConnectionBase
try: try:
from __main__ import display from __main__ import display
display = display
except ImportError: except ImportError:
from ansible.utils.display import Display from ansible.utils.display import Display
display = Display() display = Display()

View file

@ -45,7 +45,6 @@ from ansible.utils.path import makedirs_safe
try: try:
from __main__ import display from __main__ import display
display = display
except ImportError: except ImportError:
from ansible.utils.display import Display from ansible.utils.display import Display
display = Display() display = Display()

View file

@ -36,7 +36,6 @@ from ansible.utils.unicode import to_bytes, to_unicode
try: try:
from __main__ import display from __main__ import display
display = display
except ImportError: except ImportError:
from ansible.utils.display import Display from ansible.utils.display import Display
display = Display() display = Display()

View file

@ -49,7 +49,6 @@ from ansible.utils.unicode import to_bytes, to_unicode, to_str
try: try:
from __main__ import display from __main__ import display
display = display
except ImportError: except ImportError:
from ansible.utils.display import Display from ansible.utils.display import Display
display = Display() display = Display()

View file

@ -34,7 +34,6 @@ from ansible.plugins.connection import ConnectionBase
try: try:
from __main__ import display from __main__ import display
display = display
except ImportError: except ImportError:
from ansible.utils.display import Display from ansible.utils.display import Display
display = Display() display = Display()

View file

@ -22,7 +22,6 @@ from ansible.plugins.lookup import LookupBase
try: try:
from __main__ import display from __main__ import display
display = display
except ImportError: except ImportError:
from ansible.utils.display import Display from ansible.utils.display import Display
display = Display() display = Display()

View file

@ -25,7 +25,6 @@ from ansible.plugins.lookup import LookupBase
try: try:
from __main__ import display from __main__ import display
display = display
except ImportError: except ImportError:
from ansible.utils.display import Display from ansible.utils.display import Display
display = Display() display = Display()

View file

@ -26,7 +26,6 @@ from ansible.utils.unicode import to_unicode
try: try:
from __main__ import display from __main__ import display
display = display
except ImportError: except ImportError:
from ansible.utils.display import Display from ansible.utils.display import Display
display = Display() display = Display()

View file

@ -23,8 +23,6 @@ from ansible.compat.six.moves import queue as Queue
from ansible.compat.six import iteritems, text_type, string_types from ansible.compat.six import iteritems, text_type, string_types
import json import json
import pickle
import sys
import time import time
import zlib import zlib
@ -35,13 +33,11 @@ from ansible.errors import AnsibleError, AnsibleParserError, AnsibleUndefinedVar
from ansible.executor.task_result import TaskResult from ansible.executor.task_result import TaskResult
from ansible.inventory.host import Host from ansible.inventory.host import Host
from ansible.inventory.group import Group from ansible.inventory.group import Group
from ansible.playbook.handler import Handler
from ansible.playbook.helpers import load_list_of_blocks from ansible.playbook.helpers import load_list_of_blocks
from ansible.playbook.included_file import IncludedFile 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.plugins import action_loader, connection_loader, filter_loader, lookup_loader, module_loader, test_loader
from ansible.template import Templar from ansible.template import Templar
from ansible.vars.unsafe_proxy import wrap_var, AnsibleJSONUnsafeEncoder from ansible.vars.unsafe_proxy import wrap_var
try: try:
from __main__ import display from __main__ import display
@ -51,6 +47,7 @@ except ImportError:
__all__ = ['StrategyBase'] __all__ = ['StrategyBase']
# TODO: this should probably be in the plugins/__init__.py, with # TODO: this should probably be in the plugins/__init__.py, with
# a smarter mechanism to set all of the attributes based on # a smarter mechanism to set all of the attributes based on
# the loaders created there # the loaders created there
@ -67,6 +64,7 @@ class SharedPluginLoaderObj:
self.lookup_loader = lookup_loader self.lookup_loader = lookup_loader
self.module_loader = module_loader self.module_loader = module_loader
class StrategyBase: class StrategyBase:
''' '''
@ -84,6 +82,7 @@ class StrategyBase:
self._final_q = tqm._final_q self._final_q = tqm._final_q
self._step = getattr(tqm._options, 'step', False) self._step = getattr(tqm._options, 'step', False)
self._diff = getattr(tqm._options, 'diff', 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 self._display = display
# internal counters # internal counters
@ -100,7 +99,7 @@ class StrategyBase:
failed_hosts = self._tqm._failed_hosts.keys() failed_hosts = self._tqm._failed_hosts.keys()
unreachable_hosts = self._tqm._unreachable_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) result &= self.run_handlers(iterator, play_context)
# now update with the hosts (if any) that failed or were # now update with the hosts (if any) that failed or were
@ -121,7 +120,8 @@ class StrategyBase:
return 0 return 0
def get_hosts_remaining(self, play): 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): 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] 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): def _queue_task(self, host, task, task_vars, play_context):
''' handles queueing the task up to be sent to a worker ''' ''' 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 # 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: 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] (worker_prc, main_q, rslt_q) = self._workers[self._cur_worker]
self._cur_worker += 1 self._cur_worker += 1
@ -167,7 +167,7 @@ class StrategyBase:
# data contained in the dict is very large # data contained in the dict is very large
del task_vars del task_vars
else: 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 # 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) 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 self._pending_results += 1
except (EOFError, IOError, AssertionError) as e: except (EOFError, IOError, AssertionError) as e:
# most likely an abort # most likely an abort
self._display.debug("got an error while queuing: %s" % e) display.debug("got an error while queuing: %s" % e)
return 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): def _process_pending_results(self, iterator):
''' '''
@ -193,7 +193,7 @@ class StrategyBase:
while not self._final_q.empty() and not self._tqm._terminated: while not self._final_q.empty() and not self._tqm._terminated:
try: try:
result = self._final_q.get(block=False) 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) # 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'): 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 task = task_result._task
if result[0] == 'host_task_failed' or task_result.is_failed(): if result[0] == 'host_task_failed' or task_result.is_failed():
if not task.ignore_errors: 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 task.run_once:
# if we're using run_once, we have to fail every host here # 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] [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]: if task_result._host not in self._notified_handlers[handler_name]:
self._notified_handlers[handler_name].append(task_result._host) 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': elif result[0] == 'register_host_var':
# essentially the same as 'set_host_var' below, however we # essentially the same as 'set_host_var' below, however we
@ -323,12 +323,12 @@ class StrategyBase:
ret_results = [] 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: while self._pending_results > 0 and not self._tqm._terminated:
results = self._process_pending_results(iterator) results = self._process_pending_results(iterator)
ret_results.extend(results) ret_results.extend(results)
time.sleep(0.01) 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 return ret_results
@ -468,8 +468,9 @@ class StrategyBase:
tags = [ tags ] tags = [ tags ]
if len(tags) > 0: if len(tags) > 0:
if len(b._task_include.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) raise AnsibleParserError("Include tasks should not specify tags in more than one way (both via args and directly on the task)",
self._display.deprecated("You should not specify tags in the include parameters. All tags should be specified using the task-level option") 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.tags = tags
b._task_include.vars = temp_vars b._task_include.vars = temp_vars
@ -579,12 +580,12 @@ class StrategyBase:
for host in included_file._hosts: for host in included_file._hosts:
iterator.mark_host_failed(host) iterator.mark_host_failed(host)
self._tqm._failed_hosts[host.name] = True self._tqm._failed_hosts[host.name] = True
self._display.warning(str(e)) display.warning(str(e))
continue continue
# wipe the notification list # wipe the notification list
self._notified_handlers[handler_name] = [] 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 return result
def _take_step(self, task, host=None): 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) msg = u'Perform task: %s on %s (y/n/c): ' % (task, host)
else: else:
msg = u'Perform task: %s (y/n/c): ' % task msg = u'Perform task: %s (y/n/c): ' % task
resp = self._display.prompt(msg) resp = display.prompt(msg)
if resp.lower() in ['y','yes']: if resp.lower() in ['y','yes']:
self._display.debug("User ran task") display.debug("User ran task")
ret = True ret = True
elif resp.lower() in ['c', 'continue']: 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 self._step = False
ret = True ret = True
else: else:
self._display.debug("User skipped task") display.debug("User skipped task")
self._display.banner(msg) display.banner(msg)
return ret return ret

View file

@ -31,6 +31,7 @@ except ImportError:
from ansible.utils.display import Display from ansible.utils.display import Display
display = Display() display = Display()
class StrategyModule(StrategyBase): class StrategyModule(StrategyBase):
def run(self, iterator, play_context): def run(self, iterator, play_context):
@ -69,31 +70,31 @@ class StrategyModule(StrategyBase):
host_results = [] host_results = []
while True: while True:
host = hosts_left[last_host] 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() host_name = host.get_name()
# peek at the next task for the host, to see if there's # peek at the next task for the host, to see if there's
# anything to do do for this host # anything to do do for this host
(state, task) = iterator.get_next_task_for_host(host, peek=True) (state, task) = iterator.get_next_task_for_host(host, peek=True)
self._display.debug("free host state: %s" % state) display.debug("free host state: %s" % state)
self._display.debug("free host task: %s" % task) 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: 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 # set the flag so the outer loop knows we've still found
# some work which needs to be done # some work which needs to be done
work_to_do = True 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) # 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 # pop the task, mark the host blocked, and queue it
self._blocked_hosts[host_name] = True self._blocked_hosts[host_name] = True
(state, task) = iterator.get_next_task_for_host(host) (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) 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 # 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) # 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 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 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: 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 continue
if task.action == 'meta': if task.action == 'meta':
@ -138,7 +139,8 @@ class StrategyModule(StrategyBase):
host_results.extend(results) host_results.extend(results)
try: 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: except AnsibleError as e:
return False return False
@ -151,7 +153,7 @@ class StrategyModule(StrategyBase):
except AnsibleError as e: except AnsibleError as e:
for host in included_file._hosts: for host in included_file._hosts:
iterator.mark_host_failed(host) iterator.mark_host_failed(host)
self._display.warning(str(e)) display.warning(str(e))
continue continue
for host in hosts_left: for host in hosts_left:
@ -174,4 +176,3 @@ class StrategyModule(StrategyBase):
# run the base class run() method, which executes the cleanup function # run the base class run() method, which executes the cleanup function
# and runs any outstanding handlers which have been triggered # and runs any outstanding handlers which have been triggered
return super(StrategyModule, self).run(iterator, play_context, result) return super(StrategyModule, self).run(iterator, play_context, result)

View file

@ -154,9 +154,9 @@ class StrategyModule(StrategyBase):
while work_to_do and not self._tqm._terminated: while work_to_do and not self._tqm._terminated:
try: 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] 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 # queue up this task for each host in the inventory
callback_sent = False 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 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 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: 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 continue
if task.action == 'meta': if task.action == 'meta':
@ -212,11 +212,11 @@ class StrategyModule(StrategyBase):
skip_rest = True skip_rest = True
break 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) 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) self.add_tqm_variables(task_vars, play=iterator._play)
templar = Templar(loader=self._loader, variables=task_vars) templar = Templar(loader=self._loader, variables=task_vars)
self._display.debug("done getting variables") display.debug("done getting variables")
if not callback_sent: if not callback_sent:
display.debug("sending task start callback, copying the task so we can template it temporarily") 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: if skip_rest:
continue 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) results = self._wait_on_pending_results(iterator)
host_results.extend(results) host_results.extend(results)
if not work_to_do and len(iterator.get_failed_hosts()) > 0: 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') self._tqm.send_callback('v2_playbook_on_no_hosts_remaining')
result = False result = False
break break
try: 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: except AnsibleError as e:
return False return False
@ -285,7 +286,8 @@ class StrategyModule(StrategyBase):
noop_block.rescue = [noop_task for t in new_block.rescue] noop_block.rescue = [noop_task for t in new_block.rescue]
for host in hosts_left: for host in hosts_left:
if host in included_file._hosts: 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) final_block = new_block.filter_tagged_tasks(play_context, task_vars)
all_blocks[host].append(final_block) all_blocks[host].append(final_block)
else: else:
@ -295,7 +297,7 @@ class StrategyModule(StrategyBase):
for host in included_file._hosts: for host in included_file._hosts:
self._tqm._failed_hosts[host.name] = True self._tqm._failed_hosts[host.name] = True
iterator.mark_host_failed(host) iterator.mark_host_failed(host)
self._display.error(e, wrap_text=False) display.error(e, wrap_text=False)
continue continue
# finally go through all of the hosts and append the # finally go through all of the hosts and append the
@ -303,9 +305,9 @@ class StrategyModule(StrategyBase):
for host in hosts_left: for host in hosts_left:
iterator.add_tasks(host, all_blocks[host]) iterator.add_tasks(host, all_blocks[host])
self._display.debug("results queue empty") display.debug("results queue empty")
except (IOError, EOFError) as e: 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 # most likely an abort, return failed
return False return False
@ -313,4 +315,3 @@ class StrategyModule(StrategyBase):
# and runs any outstanding handlers which have been triggered # and runs any outstanding handlers which have been triggered
return super(StrategyModule, self).run(iterator, play_context, result) return super(StrategyModule, self).run(iterator, play_context, result)

View file

@ -32,7 +32,6 @@ except:
try: try:
from __main__ import display from __main__ import display
display = display
except ImportError: except ImportError:
from ansible.utils.display import Display from ansible.utils.display import Display
display = Display() display = Display()

View file

@ -48,7 +48,6 @@ from ansible.vars.unsafe_proxy import wrap_var
try: try:
from __main__ import display from __main__ import display
display = display
except ImportError: except ImportError:
from ansible.utils.display import Display from ansible.utils.display import Display
display = Display() display = Display()