Skip to content

Commit

Permalink
Skip fact gathering if the entire play was included via conditional a…
Browse files Browse the repository at this point in the history
…nd False (ansible#21734)

Addresses ansible#21528
  • Loading branch information
jctanner authored Feb 21, 2017
1 parent a1b3664 commit 40235d7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/ansible/executor/play_iterator.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ def __init__(self, inventory, play, play_context, variable_manager, all_vars, st
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)
Expand Down
2 changes: 2 additions & 0 deletions lib/ansible/playbook/play.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -330,5 +331,6 @@ def deserialize(self, data):
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
6 changes: 6 additions & 0 deletions lib/ansible/playbook/playbook_include.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def load_data(self, ds, basedir, variable_manager=None, loader=None):

# 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
Expand All @@ -73,6 +74,11 @@ def load_data(self, ds, basedir, variable_manager=None, loader=None):
# 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)
Expand Down

0 comments on commit 40235d7

Please sign in to comment.