Commit c5d5ed17 by Brian Coca

added tag resolution mirroring updated v1

parent 49ba9d4b
...@@ -24,6 +24,8 @@ from ansible.playbook.attribute import FieldAttribute ...@@ -24,6 +24,8 @@ from ansible.playbook.attribute import FieldAttribute
from ansible.template import Templar from ansible.template import Templar
class Taggable: class Taggable:
untagged = set(['untagged'])
_tags = FieldAttribute(isa='list', default=[]) _tags = FieldAttribute(isa='list', default=[])
def __init__(self): def __init__(self):
...@@ -38,22 +40,45 @@ class Taggable: ...@@ -38,22 +40,45 @@ class Taggable:
raise AnsibleError('tags must be specified as a list', obj=ds) raise AnsibleError('tags must be specified as a list', obj=ds)
def evaluate_tags(self, only_tags, skip_tags, all_vars): def evaluate_tags(self, only_tags, skip_tags, all_vars):
templar = Templar(loader=self._loader, variables=all_vars) ''' this checks if the current item should be executed depending on tag options '''
tags = templar.template(self.tags)
if not isinstance(tags, list): should_run = True
tags = set([tags])
else: if self.tags:
tags = set(tags) templar = Templar(loader=self._loader, variables=all_vars)
tags = templar.template(self.tags)
#print("%s tags are: %s, only_tags=%s, skip_tags=%s" % (self, my_tags, only_tags, skip_tags))
if skip_tags: if not isinstance(tags, list):
skipped_tags = tags.intersection(skip_tags) if tags.find(',') != -1:
if len(skipped_tags) > 0: tags = set(tags.split(','))
return False else:
matched_tags = tags.intersection(only_tags) tags = set([tags])
#print("matched tags are: %s" % matched_tags) else:
if len(matched_tags) > 0 or 'all' in only_tags: tags = set(tags)
return True
else: else:
return False # this makes intersection work for untagged
tags = self.__class__.untagged
if only_tags:
should_run = False
if 'always' in tags or 'all' in only_tags:
should_run = True
elif tags.intersection(only_tags):
should_run = True
elif 'tagged' in only_tags and tags != self.__class__.untagged:
should_run = True
if should_run and skip_tags:
# Check for tags that we need to skip
if 'all' in skip_tags:
if 'always' not in tags or 'always' in skip_tags:
should_run = False
elif tags.intersection(skip_tags):
should_run = False
elif 'tagged' in skip_tags and tags != self.__class__.untagged:
should_run = False
return should_run
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment