Last active
August 29, 2015 14:15
-
-
Save perzizzle/117a6b139e2a97194d5f to your computer and use it in GitHub Desktop.
ToPowershellHash filter
This file contains hidden or 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
import yaml | |
from ansible import errors | |
def toPowershellHash(x): | |
try: | |
powershell ="@{" | |
if isinstance(x, dict): | |
for key, value in x.items(): | |
powershell += "'{0}'='{1}';".format(key,value) | |
powershell +="}" | |
return powershell | |
else: | |
raise errors.AnsibleFilterError("failed expects a dictionary") | |
except TypeError: | |
return False | |
class FilterModule(object): | |
''' Ansible powershell jinja2 filters ''' | |
def filters(self): | |
return { | |
# convert yaml array to powershell hash | |
'toPowershellHash': toPowershellHash, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment