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

changes to not clear the setup cache between runs, and also decide to run plays with no tasks

in them if it looks like they are not tagged, because if that is the case, then we may just
be gathering facts about them.
This commit is contained in:
Michael DeHaan 2012-07-25 20:45:51 -04:00
parent f371092845
commit da4562f495
2 changed files with 12 additions and 11 deletions

View file

@ -24,6 +24,8 @@ import os
import collections
from play import Play
SETUP_CACHE = collections.defaultdict(dict)
class PlayBook(object):
'''
runs an ansible playbook, given as a datastructure or YAML filename.
@ -75,7 +77,7 @@ class PlayBook(object):
sudo: if not specified per play, requests all plays use sudo mode
"""
self.SETUP_CACHE = collections.defaultdict(dict)
self.SETUP_CACHE = SETUP_CACHE
if playbook is None or callbacks is None or runner_callbacks is None or stats is None:
raise Exception('missing required arguments')
@ -148,7 +150,6 @@ class PlayBook(object):
# loop through all patterns and run them
self.callbacks.on_start()
for play_ds in self.playbook:
self.SETUP_CACHE = collections.defaultdict(dict)
self._run_play(Play(self,play_ds))
# summarize the results
@ -219,11 +220,6 @@ class PlayBook(object):
if results is None:
results = {}
# add facts to the global setup cache
for host, result in results['contacted'].iteritems():
facts = result.get('ansible_facts', {})
self.SETUP_CACHE[host].update(facts)
self.stats.compute(results)
# flag which notify handlers need to be run

View file

@ -178,14 +178,19 @@ class Play(object):
def should_run(self, tags):
''' does the play match any of the tags? '''
if len(self._tasks) == 0:
return False
tags_counted = 0
for task in self._tasks:
for task_tag in task.tags:
tags_counted = tags_counted + 1
if task_tag in tags:
return True
return False
if tags_counted > 0:
return False
# didn't tag the play, and the play contains no steps
# so assume we just want to gather facts
return True
# *************************************************