Skip to content

Instantly share code, notes, and snippets.

@perzizzle
Last active August 29, 2015 14:15
Show Gist options
  • Save perzizzle/117a6b139e2a97194d5f to your computer and use it in GitHub Desktop.
Save perzizzle/117a6b139e2a97194d5f to your computer and use it in GitHub Desktop.
ToPowershellHash filter
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