Skip to content

Instantly share code, notes, and snippets.

@udondan
Created March 16, 2015 10:42
Show Gist options
  • Save udondan/4652052f5e2e57b4b566 to your computer and use it in GitHub Desktop.
Save udondan/4652052f5e2e57b4b566 to your computer and use it in GitHub Desktop.
Ansible filter plugin for testing if variables are iterable - available in Jinja2 but not in the version Ansible currently uses
from ansible import errors
from jinja2.filters import environmentfilter
class FilterModule(object):
def filters(self):
return {
'iterable': self.iterable
}
def iterable(*args):
try:
iterator = iter(args[1])
except TypeError:
return False
else:
return True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment