Skip fact gathering if the entire play was included via conditional and False (#21734)
Addresses #21528
This commit is contained in:
parent
a1b3664ec4
commit
40235d7b99
3 changed files with 11 additions and 0 deletions
|
@ -184,6 +184,9 @@ class PlayIterator:
|
|||
if fact_path:
|
||||
setup_task.args['fact_path'] = fact_path
|
||||
setup_task.set_loader(self._play._loader)
|
||||
# short circuit fact gathering if the entire playbook is conditional
|
||||
if self._play._included_conditional is not None:
|
||||
setup_task.when = self._play._included_conditional[:]
|
||||
setup_block.block = [setup_task]
|
||||
|
||||
setup_block = setup_block.filter_tagged_tasks(play_context, all_vars)
|
||||
|
|
|
@ -97,6 +97,7 @@ class Play(Base, Taggable, Become):
|
|||
def __init__(self):
|
||||
super(Play, self).__init__()
|
||||
|
||||
self._included_conditional = None
|
||||
self._included_path = None
|
||||
self._removed_hosts = []
|
||||
self.ROLE_CACHE = {}
|
||||
|
@ -330,5 +331,6 @@ class Play(Base, Taggable, Become):
|
|||
def copy(self):
|
||||
new_me = super(Play, self).copy()
|
||||
new_me.ROLE_CACHE = self.ROLE_CACHE.copy()
|
||||
new_me._included_conditional = self._included_conditional
|
||||
new_me._included_path = self._included_path
|
||||
return new_me
|
||||
|
|
|
@ -49,6 +49,7 @@ class PlaybookInclude(Base, Conditional, Taggable):
|
|||
|
||||
# import here to avoid a dependency loop
|
||||
from ansible.playbook import Playbook
|
||||
from ansible.playbook.play import Play
|
||||
|
||||
# first, we use the original parent method to correctly load the object
|
||||
# via the load_data/preprocess_data system we normally use for other
|
||||
|
@ -73,6 +74,11 @@ class PlaybookInclude(Base, Conditional, Taggable):
|
|||
# finally, update each loaded playbook entry with any variables specified
|
||||
# on the included playbook and/or any tags which may have been set
|
||||
for entry in pb._entries:
|
||||
|
||||
# conditional includes on a playbook need a marker to skip gathering
|
||||
if new_obj.when and isinstance(entry, Play):
|
||||
entry._included_conditional = new_obj.when[:]
|
||||
|
||||
temp_vars = entry.vars.copy()
|
||||
temp_vars.update(new_obj.vars)
|
||||
param_tags = temp_vars.pop('tags', None)
|
||||
|
|
Loading…
Reference in a new issue