forked from ansible-collections/amazon.aws
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a2b775e
commit 72f998e
Showing
3 changed files
with
45 additions
and
4 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Copyright (c) 2020 Paul Arthur | ||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) | ||
|
||
from __future__ import (absolute_import, division, print_function) | ||
__metaclass__ = type | ||
|
||
from ansible.errors import AnsibleFilterError | ||
from ansible.module_utils.common._collections_compat import Mapping | ||
|
||
|
||
def expand_csv_tags(mydict, separator=','): | ||
''' Takes a dictionary and transforms it into a list of key_value strings, | ||
possibly after splitting the value using the supplied separator. ''' | ||
|
||
if not isinstance(mydict, Mapping): | ||
raise AnsibleFilterError("expand_csv_tags requires a dictionary, got %s instead." % type(mydict)) | ||
|
||
ret = [] | ||
|
||
for key in mydict: | ||
for val in mydict[key].split(separator): | ||
ret.append('{0}_{1}'.format(key, val)) | ||
|
||
return ret | ||
|
||
|
||
class FilterModule(object): | ||
def filters(self): | ||
return { 'expand_csv_tags': expand_csv_tags } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters