Sha256: 4fd9cf898bb6338bd81019dc09318ae0e08b46759a58280f777da1561b107762

Contents?: true

Size: 1.78 KB

Versions: 20

Compression:

Stored size: 1.78 KB

Contents

#!/usr/bin/env python2

# `{{ name }}` Ansible/Jinja2 Filters for `{{ role_role_name }}` Role.
# 


# Imports
# ============================================================================

# Make Python 2 more Python 3-like
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

from ansible.errors import AnsibleError

# Some imports you may often want:
# import sys
# improt os
# import subprocess
# import yaml
# improt json


# Functions
# ============================================================================
# 
# Suggested practice seems to be to define each filter as a top-level function
# then expose them via the `FilterModule#filters` method below.
# 

def my_{{ name }}_filter(subject, *args, **kwds):
    '''
    TODO doc me!
    
    >>> my_{{ name }}_filter('yao')
    "buyao"
    '''
    
    raise NotImplementedError("Implement me!")


# Module
# ============================================================================
# 
# How Ansible finds the filters. It looks like it gets instantiated with
# no arguments, at least most of the time, so it pretty much just serves as
# a well-known name to obtain the function references from.
# 
class FilterModule(object):
    '''
    `{{ name }}` Ansible/Jinja2 filters for `{{ role_role_name }}` role.
    '''

    def filters(self):
        return {
            'my_{{ name }}_filter': my_{{ name }}_filter,
        }
    # filters()
# FilterModule


# Testing
# ============================================================================
# 
# This is not standard Ansible-ness - they use `unittest.TestCase` in separate
# files - but `doctest` seemed like a really easy way to add and run tests 
# for these typically simple functions.
# 
if __name__ == '__main__':
    import doctest
    doctest.testmod()
    

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
qb-0.3.13 roles/qb/role/templates/filter_plugins/filters.py.j2
qb-0.3.12 roles/qb.role/templates/filter_plugins/filters.py.j2
qb-0.3.11 roles/qb.role/templates/filter_plugins/filters.py.j2
qb-0.3.10 roles/qb.role/templates/filter_plugins/filters.py.j2
qb-0.3.9 roles/qb.role/templates/filter_plugins/filters.py.j2
qb-0.3.8 roles/qb.role/templates/filter_plugins/filters.py.j2
qb-0.3.7 roles/qb.role/templates/filter_plugins/filters.py.j2
qb-0.3.6 roles/qb.role/templates/filter_plugins/filters.py.j2
qb-0.3.5 roles/qb.role/templates/filter_plugins/filters.py.j2
qb-0.3.4 roles/qb.role/templates/filter_plugins/filters.py.j2
qb-0.3.3 roles/qb.role/templates/filter_plugins/filters.py.j2
qb-0.3.2 roles/qb.role/templates/filter_plugins/filters.py.j2
qb-0.3.1 roles/qb.role/templates/filter_plugins/filters.py.j2
qb-0.1.88 roles/qb.role/templates/filter_plugins/filters.py.j2
qb-0.1.87 roles/qb.role/templates/filter_plugins/filters.py.j2
qb-0.1.86 roles/qb.role/templates/filter_plugins/filters.py.j2
qb-0.1.85 roles/qb.role/templates/filter_plugins/filter_plugin.py.j2
qb-0.1.84 roles/qb.role/templates/filter_plugins/filter_plugin.py.j2
qb-0.1.83 roles/qb.role/templates/filter_plugins/filter_plugin.py.j2
qb-0.1.82 roles/qb.role/templates/filter_plugins/filter_plugin.py.j2