Sha256: b5677d5fab1d9fea8c6e609dc7ea51fcd5059c6278b5eb68d3e3e06796215f3a

Contents?: true

Size: 1.93 KB

Versions: 18

Compression:

Stored size: 1.93 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

18 entries across 18 versions & 1 rubygems

Version Path
qb-0.4.5 roles/qb/role/templates/filter_plugins/filters.py.j2
qb-0.4.4 roles/qb/role/templates/filter_plugins/filters.py.j2
qb-0.4.3 roles/qb/role/templates/filter_plugins/filters.py.j2
qb-0.4.2 roles/qb/role/templates/filter_plugins/filters.py.j2
qb-0.4.1 roles/qb/role/templates/filter_plugins/filters.py.j2
qb-0.4.0 roles/qb/role/templates/filter_plugins/filters.py.j2
qb-0.3.25 roles/qb/role/templates/filter_plugins/filters.py.j2
qb-0.3.24 roles/qb/role/templates/filter_plugins/filters.py.j2
qb-0.3.23 roles/qb/role/templates/filter_plugins/filters.py.j2
qb-0.3.22 roles/qb/role/templates/filter_plugins/filters.py.j2
qb-0.3.21 roles/qb/role/templates/filter_plugins/filters.py.j2
qb-0.3.20 roles/qb/role/templates/filter_plugins/filters.py.j2
qb-0.3.19 roles/qb/role/templates/filter_plugins/filters.py.j2
qb-0.3.18 roles/qb/role/templates/filter_plugins/filters.py.j2
qb-0.3.17 roles/qb/role/templates/filter_plugins/filters.py.j2
qb-0.3.16 roles/qb/role/templates/filter_plugins/filters.py.j2
qb-0.3.15 roles/qb/role/templates/filter_plugins/filters.py.j2
qb-0.3.14 roles/qb/role/templates/filter_plugins/filters.py.j2