# Buggy code
def filters(self):
    return {
        # base 64
        "b64decode": base64.b64decode,
        "b64encode": base64.b64encode,
        # json
        "to_json": json.dumps,
        "to_nice_json": to_nice_json,
        "from_json": json.loads,
        # yaml
        "to_yaml": yaml.safe_dump,
        "to_nice_yaml": to_nice_yaml,
        "from_yaml": yaml.safe_load,
        # path
        "basename": os.path.basename,
        "dirname": os.path.dirname,
        "realpath": os.path.realpath,
        # failure testing
        "failed": failed,
        "success": success,
        # changed testing
        "changed": changed,
        # skip testing
        "skipped": skipped,
        # variable existence
        "mandatory": mandatory,
        # value as boolean
        "bool": bool,
        # quote string for shell usage
        "quote": quote,
        # md5 hex digest of string
        "md5": md5s,
        # file glob
        "fileglob": fileglob,
        # regex
        "match": match,
        "search": search,
        "regex": regex,
        # list
        "unique": unique,
        "intersect": intersect,
        "difference": difference,
        "symmetric_difference": symmetric_difference,
        "union": union,
    }


# Traceback (UnboundLocalError)
PLAY [test] ****************************************************************

TASK: [set_fact ] *************************************************************
ok: [localhost]

TASK: [debug ] ****************************************************************
ok: [localhost] => {
"msg": {
"text": "some thing"
}
}
Traceback (most recent call last):
File "/tmp/jim/env/bin/ansible-playbook", line 269, in <module>
sys.exit(main(sys.argv[1:]))
File "/tmp/jim/env/bin/ansible-playbook", line 209, in main
pb.run()
File "/tmp/jim/env/local/lib/python2.7/site-packages/ansible/playbook/__init__.py", line 263, in run
if not self._run_play(play):
File "/tmp/jim/env/local/lib/python2.7/site-packages/ansible/playbook/__init__.py", line 592, in _run_play
if not self._run_task(play, task, False):
File "/tmp/jim/env/local/lib/python2.7/site-packages/ansible/playbook/__init__.py", line 357, in _run_task
self.callbacks.on_task_start(template(play.basedir, name, task.module_vars, lookup_fatal=False, filter_fatal=False), is_handler)
File "/tmp/jim/env/local/lib/python2.7/site-packages/ansible/utils/template.py", line 319, in template
varname = template_from_string(basedir, varname, vars, fail_on_undefined)
File "/tmp/jim/env/local/lib/python2.7/site-packages/ansible/utils/template.py", line 543, in template_from_string
return res
UnboundLocalError: local variable 'res' referenced before assignment

# Fixed code
def filters(self):
    return {
        # base 64
        "b64decode": base64.b64decode,
        "b64encode": base64.b64encode,
        # json
        "to_json": to_json,
        "to_nice_json": to_nice_json,
        "from_json": json.loads,
        # yaml
        "to_yaml": yaml.safe_dump,
        "to_nice_yaml": to_nice_yaml,
        "from_yaml": yaml.safe_load,
        # path
        "basename": os.path.basename,
        "dirname": os.path.dirname,
        "realpath": os.path.realpath,
        # failure testing
        "failed": failed,
        "success": success,
        # changed testing
        "changed": changed,
        # skip testing
        "skipped": skipped,
        # variable existence
        "mandatory": mandatory,
        # value as boolean
        "bool": bool,
        # quote string for shell usage
        "quote": quote,
        # md5 hex digest of string
        "md5": md5s,
        # file glob
        "fileglob": fileglob,
        # regex
        "match": match,
        "search": search,
        "regex": regex,
        # list
        "unique": unique,
        "intersect": intersect,
        "difference": difference,
        "symmetric_difference": symmetric_difference,
        "union": union,
    }