Created
June 10, 2016 00:23
-
-
Save dspruell/d12506b7332789f726ba487636b36c74 to your computer and use it in GitHub Desktop.
Filter idea - quote_each - surround array members in quotes
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
def quote_each(data, type='double'): | |
''' | |
Take a list of strings and output the list with each item surrounded by | |
quotation marks. Defaults to using double quotes ("item"), may be specified | |
instead to use single quotes ('item'). | |
''' | |
QUOTE_TYPES = { | |
'double': '"', | |
'single': "'", | |
} | |
if not isinstance(data, list): | |
raise errors.AnsibleFilterError("|failed expects first param is a list") | |
if not all(isinstance(x, basestring) for x in data): | |
raise errors.AnsibleFilterError("|failed expects first param is a list" | |
" of strings") | |
retval = [(QUOTE_TYPES[type] + s + QUOTE_TYPES[type]) for s in data] | |
return retval |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment