Skip to content

Instantly share code, notes, and snippets.

@StalkingKillah
Last active August 29, 2015 14:09
Show Gist options
  • Save StalkingKillah/b32c893ca12aa8bd8e3d to your computer and use it in GitHub Desktop.
Save StalkingKillah/b32c893ca12aa8bd8e3d to your computer and use it in GitHub Desktop.
Filter required by Ansible role: https://github.com/StalkingKillah/ansible-flynn
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