mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -07:00
Allow tags to be templated from a variable (#49833)
* Allow tags to be templated from a variable. Fixes #49825 * Restore _load_tags to ensure we do csv tag splitting * Add tests for csv tags and templated tags * evaluate_tags doesn't need to accept strings, because _load_tags handles this
This commit is contained in:
parent
a0d71e7735
commit
7eb1ab45a7
5 changed files with 29 additions and 17 deletions
|
@ -19,8 +19,6 @@
|
|||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import itertools
|
||||
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible.module_utils.six import string_types
|
||||
from ansible.playbook.attribute import FieldAttribute
|
||||
|
@ -32,9 +30,6 @@ class Taggable:
|
|||
untagged = frozenset(['untagged'])
|
||||
_tags = FieldAttribute(isa='list', default=list, listof=(string_types, int), extend=True)
|
||||
|
||||
def __init__(self):
|
||||
super(Taggable, self).__init__()
|
||||
|
||||
def _load_tags(self, attr, ds):
|
||||
if isinstance(ds, list):
|
||||
return ds
|
||||
|
@ -54,13 +49,14 @@ class Taggable:
|
|||
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(','))
|
||||
_temp_tags = set()
|
||||
for tag in tags:
|
||||
if isinstance(tag, list):
|
||||
_temp_tags.update(tag)
|
||||
else:
|
||||
tags = set([tags])
|
||||
else:
|
||||
tags = set([i for i, _ in itertools.groupby(tags)])
|
||||
_temp_tags.add(tag)
|
||||
tags = _temp_tags
|
||||
self.tags = list(tags)
|
||||
else:
|
||||
# this makes isdisjoint work for untagged
|
||||
tags = self.untagged
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue