Clear flag indicating role had run before each play is run

Fixes #11514
This commit is contained in:
James Cammarata 2015-07-07 21:46:44 -04:00
parent 48827a31bc
commit 2e5dfd57cc
3 changed files with 11 additions and 2 deletions

View file

@ -25,6 +25,7 @@ from ansible import constants as C
from ansible.errors import *
from ansible.executor.task_queue_manager import TaskQueueManager
from ansible.playbook import Playbook
from ansible.playbook.role import role_reset_has_run
from ansible.plugins import module_loader
from ansible.template import Templar
@ -83,6 +84,10 @@ class PlaybookExecutor:
self._display.vv('%d plays in %s' % (len(plays), playbook_path))
for play in plays:
# clear out the flag on all roles indicating they had any tasks run
role_reset_has_run()
# clear any filters which may have been applied to the inventory
self._inventory.remove_restriction()
# Create a temporary copy of the play here, so we can run post_validate

View file

@ -41,7 +41,7 @@ from ansible.plugins import get_all_plugin_loaders, push_basedir
from ansible.utils.vars import combine_vars
__all__ = ['Role', 'ROLE_CACHE', 'hash_params']
__all__ = ['Role', 'ROLE_CACHE', 'hash_params', 'role_reset_has_run']
# FIXME: this should be a utility function, but can't be a member of
# the role due to the fact that it would require the use of self
@ -70,6 +70,10 @@ def hash_params(params):
# will be based on the repr() of the dictionary object)
ROLE_CACHE = dict()
def role_reset_has_run():
for (role_name, cached_roles) in ROLE_CACHE.iteritems():
for (hashed_params, role) in cached_roles.iteritems():
role._had_task_run = False
class Role(Base, Become, Conditional, Taggable):

View file

@ -195,7 +195,7 @@ class StrategyBase:
# with the correct object and mark it as executed
for (entry, role_obj) in ROLE_CACHE[task_result._task._role._role_name].iteritems():
hashed_entry = hash_params(task_result._task._role._role_params)
if entry == hashed_entry :
if entry == hashed_entry:
role_obj._had_task_run = True
ret_results.append(task_result)