Test cases for YAML and Jinja2
This directory contains numerous test cases used to illustrate how to create complex data structures in YAML and how to use them in Jinja2 templates. The includes subdirectory is used to test Jinja2 include functionality, ipaddr directory contains test cases for Ansible ipaddr Jinja2 filter, whitespace directory has test cases illustrating whitespace handling when using Jinja2 with Ansible.
The main directory also includes render.py that can be used to render YAML data structure with corresponding Jinja2 template.
The easiest way to invoke render.py is simply
./render.py somename. Specify just the file name, not the extension (for example, 1-basics and not 1-basics.yml). Using this syntax the script expects to find:
- Data structure in somename.yml
- Jinja2 template in somename.j2
If you want to use YAML and Jinja2 files with different names or different extensions specify the file names individually. Using this syntax you have to use full file names (including extensions)
./render.py -yaml yamlfile -jinja jinja2file
Note: you can use -y instead of -yaml and -j instead of -jinja2
You can use these command line options to change render.py behavior:
- -n or -notrim: do not trim whitespace (sets trim_blocks and lstrip_blocks)
- -w or -warning: report usage of undefined variables
- -s or -strict: fail on undefined variables