Last active
August 29, 2015 14:09
-
-
Save StalkingKillah/b32c893ca12aa8bd8e3d to your computer and use it in GitHub Desktop.
Filter required by Ansible role: https://github.com/StalkingKillah/ansible-flynn
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, runner | |
def tail(lines, num_lines=1, delimiter='\n'): | |
if type(lines) is unicode or type(lines) is str: | |
lines = str(lines).split(delimiter) | |
# remove empty lines | |
lines = remove_empty_elements(lines) | |
end = len(lines) | |
start = end-num_lines | |
return lines[start:end] | |
def remove_empty_elements(obj): | |
obj = filter(lambda e: e != '', obj) | |
return obj | |
class FilterModule(object): | |
def filters(self): | |
return { | |
"tail": tail, | |
"remove_empty_elements": remove_empty_elements | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment