You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ansible/test/integration/roles/test_filters/templates/foo.j2

56 lines
1.6 KiB
Django/Jinja

This is a test of various filter plugins found in Ansible (ex: core.py), and
not so much a test of the core filters in Jinja2.
Dumping the same structure to YAML
{{ some_structure | to_nice_yaml }}
Dumping the same structure to JSON, but don't pretty print
{{ some_structure | to_json }}
Dumping the same structure to YAML, but don't pretty print
{{ some_structure | to_yaml }}
From a recorded task, the changed, failed, success, and skipped
filters are shortcuts to ask if those tasks produced changes, failed,
succeeded, or skipped (as one might guess).
Changed = {{ some_registered_var | changed }}
Failed = {{ some_registered_var | failed }}
Success = {{ some_registered_var | success }}
Skipped = {{ some_registered_var | skipped }}
The mandatory filter fails if a variable is not defined and returns the value.
To avoid breaking this test, this variable is already defined.
a = {{ a | mandatory }}
There are various casts available
int = {{ a | int }}
bool = {{ 1 | bool }}
String quoting
quoted = {{ 'quoted' | quote }}
The fileglob module returns the list of things matching a pattern.
fileglob = {{ (output_dir + '/*') | fileglob }}
There are also various string operations that work on paths. These do not require
files to exist and are passthrus to the python os.path functions
/etc/motd with basename = {{ '/etc/motd' | basename }}
/etc/motd with dirname = {{ '/etc/motd' | dirname }}
TODO: realpath follows symlinks. There isn't a test for this just now.
TODO: add tests for set theory operations like union
TODO: add tests for regex, match, and search