Created
March 16, 2015 10:42
-
-
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
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
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