# Buggy code
def evaluate_tags(self, only_tags, skip_tags, all_vars):
    """this checks if the current item should be executed depending on tag options"""

    should_run = True

    if self.tags:
        templar = Templar(loader=self._loader, variables=all_vars)
        tags = templar.template(self.tags)

        if not isinstance(tags, list):
            if tags.find(",") != -1:
                tags = set(tags.split(","))
            else:
                tags = set([tags])
        else:
            tags = [i for i, _ in itertools.groupby(tags)]
    else:
        # 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


# Traceback (AttributeError)
Traceback (most recent call last):
File "/Users/matt/python_venvs/ansibledev/ansible/bin/ansible-playbook", line 66, in <module>
sys.exit(cli.run())
File "/Users/matt/python_venvs/ansibledev/ansible/lib/ansible/cli/playbook.py", line 161, in run
results = pbex.run()
File "/Users/matt/python_venvs/ansibledev/ansible/lib/ansible/executor/playbook_executor.py", line 127, in run
result = self._tqm.run(play=play)
File "/Users/matt/python_venvs/ansibledev/ansible/lib/ansible/executor/task_queue_manager.py", line 248, in run
iterator = PlayIterator(inventory=self._inventory, play=new_play, connection_info=connection_info, all_vars=all_vars)
File "/Users/matt/python_venvs/ansibledev/ansible/lib/ansible/executor/play_iterator.py", line 95, in __init__
new_block = block.filter_tagged_tasks(connection_info, all_vars)
File "/Users/matt/python_venvs/ansibledev/ansible/lib/ansible/playbook/block.py", line 318, in filter_tagged_tasks
new_block.block  = evaluate_and_append_task(self.block)
File "/Users/matt/python_venvs/ansibledev/ansible/lib/ansible/playbook/block.py", line 313, in evaluate_and_append_task
if task.evaluate_tags(connection_info.only_tags, connection_info.skip_tags, all_vars=all_vars):
File "/Users/matt/python_venvs/ansibledev/ansible/lib/ansible/playbook/taggable.py", line 82, in evaluate_tags
elif tags.intersection(only_tags):
AttributeError: 'list' object has no attribute 'intersection'

# Fixed code
def evaluate_tags(self, only_tags, skip_tags, all_vars):
    """this checks if the current item should be executed depending on tag options"""

    should_run = True

    if self.tags:
        templar = Templar(loader=self._loader, variables=all_vars)
        tags = templar.template(self.tags)

        if not isinstance(tags, list):
            if tags.find(",") != -1:
                tags = set(tags.split(","))
            else:
                tags = set([tags])
        else:
            tags = set([i for i, _ in itertools.groupby(tags)])
    else:
        # 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