mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-08 09:24:01 -07:00
Merge branch 'playbook-skip-tags' of git://github.com/dekked/ansible into skip_tags
This commit is contained in:
commit
f592340f7f
2 changed files with 51 additions and 23 deletions
|
@ -63,6 +63,7 @@ class PlayBook(object):
|
|||
sudo_user = C.DEFAULT_SUDO_USER,
|
||||
extra_vars = None,
|
||||
only_tags = None,
|
||||
skip_tags = None,
|
||||
subset = C.DEFAULT_SUBSET,
|
||||
inventory = None,
|
||||
check = False,
|
||||
|
@ -97,6 +98,8 @@ class PlayBook(object):
|
|||
extra_vars = {}
|
||||
if only_tags is None:
|
||||
only_tags = [ 'all' ]
|
||||
if skip_tags is None:
|
||||
skip_tags = []
|
||||
|
||||
self.check = check
|
||||
self.diff = diff
|
||||
|
@ -117,6 +120,7 @@ class PlayBook(object):
|
|||
self.global_vars = {}
|
||||
self.private_key_file = private_key_file
|
||||
self.only_tags = only_tags
|
||||
self.skip_tags = skip_tags
|
||||
self.any_errors_fatal = any_errors_fatal
|
||||
|
||||
self.callbacks.playbook = self
|
||||
|
@ -216,11 +220,14 @@ class PlayBook(object):
|
|||
for (play_ds, play_basedir) in zip(self.playbook, self.play_basedirs):
|
||||
play = Play(self, play_ds, play_basedir)
|
||||
assert play is not None
|
||||
|
||||
|
||||
matched_tags, unmatched_tags = play.compare_tags(self.only_tags)
|
||||
matched_tags_all = matched_tags_all | matched_tags
|
||||
unmatched_tags_all = unmatched_tags_all | unmatched_tags
|
||||
|
||||
# Remove tasks we wish to skip
|
||||
matched_tags = matched_tags - set(self.skip_tags)
|
||||
|
||||
# if we have matched_tags, the play must be run.
|
||||
# if the play contains no tasks, assume we just want to gather facts
|
||||
# in this case there are actually 3 meta tasks (handler flushes) not 0
|
||||
|
@ -228,9 +235,11 @@ class PlayBook(object):
|
|||
if (len(matched_tags) > 0 or len(play.tasks()) == 3):
|
||||
plays.append(play)
|
||||
|
||||
# if the playbook is invoked with --tags that don't exist at all in the playbooks
|
||||
# then we need to raise an error so that the user can correct the arguments.
|
||||
unknown_tags = set(self.only_tags) - (matched_tags_all | unmatched_tags_all)
|
||||
# if the playbook is invoked with --tags or --skip-tags that don't
|
||||
# exist at all in the playbooks then we need to raise an error so that
|
||||
# the user can correct the arguments.
|
||||
unknown_tags = ((set(self.only_tags) | set(self.skip_tags)) -
|
||||
(matched_tags_all | unmatched_tags_all))
|
||||
unknown_tags.discard('all')
|
||||
|
||||
if len(unknown_tags) > 0:
|
||||
|
@ -331,7 +340,7 @@ class PlayBook(object):
|
|||
ansible.callbacks.set_task(self.callbacks, None)
|
||||
ansible.callbacks.set_task(self.runner_callbacks, None)
|
||||
return True
|
||||
|
||||
|
||||
# load up an appropriate ansible runner to run the task in parallel
|
||||
results = self._run_task_internal(task)
|
||||
|
||||
|
@ -340,7 +349,7 @@ class PlayBook(object):
|
|||
if results is None:
|
||||
hosts_remaining = False
|
||||
results = {}
|
||||
|
||||
|
||||
contacted = results.get('contacted', {})
|
||||
self.stats.compute(results, ignore_errors=task.ignore_errors)
|
||||
|
||||
|
@ -408,7 +417,7 @@ class PlayBook(object):
|
|||
|
||||
self.callbacks.on_setup()
|
||||
self.inventory.restrict_to(host_list)
|
||||
|
||||
|
||||
ansible.callbacks.set_task(self.callbacks, None)
|
||||
ansible.callbacks.set_task(self.runner_callbacks, None)
|
||||
|
||||
|
@ -438,10 +447,10 @@ class PlayBook(object):
|
|||
|
||||
def generate_retry_inventory(self, replay_hosts):
|
||||
'''
|
||||
called by /usr/bin/ansible when a playbook run fails. It generates a inventory
|
||||
called by /usr/bin/ansible when a playbook run fails. It generates a inventory
|
||||
that allows re-running on ONLY the failed hosts. This may duplicate some
|
||||
variable information in group_vars/host_vars but that is ok, and expected.
|
||||
'''
|
||||
'''
|
||||
|
||||
buf = StringIO.StringIO()
|
||||
for x in replay_hosts:
|
||||
|
@ -507,7 +516,7 @@ class PlayBook(object):
|
|||
|
||||
# meta tasks are an internalism and are not valid for end-user playbook usage
|
||||
# here a meta task is a placeholder that signals handlers should be run
|
||||
|
||||
|
||||
if task.meta == 'flush_handlers':
|
||||
for handler in play.handlers():
|
||||
if len(handler.notified_by) > 0:
|
||||
|
@ -530,11 +539,17 @@ class PlayBook(object):
|
|||
for x in self.only_tags:
|
||||
|
||||
for y in task.tags:
|
||||
if (x==y):
|
||||
if x == y:
|
||||
should_run = True
|
||||
break
|
||||
|
||||
# Check for tags that we need to skip
|
||||
if should_run:
|
||||
if any(x in task.tags for x in self.skip_tags):
|
||||
should_run = False
|
||||
|
||||
if should_run:
|
||||
|
||||
if not self._run_task(play, task, False):
|
||||
# whether no hosts matched is fatal or not depends if it was on the initial step.
|
||||
# if we got exactly no hosts on the first step (setup!) then the host group
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue