Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
..
Failed to load latest commit information.
includes
ipaddr
whitespace
1-basicFail.j2
1-basicFail.yml
1-basics.j2
1-basics.yml
2-conditionals.j2
2-conditionals.yml
3-complex.j2
3-complex.yml
4-default.j2
4-default.yml
5-sequence.j2
5-sequence.yml
5-sequenceFail.j2
5-sequenceFail.yml
6-iterable.j2
6-iterable.yml
6-syslog.j2
6-syslog.yml
7-sequenceObjects.j2
7-sequenceObjects.yml
8-iterateDictionary.j2
8-iterateDictionary.yml
9-loopVariable.j2
9-loopVariable.yml
A-valueLookup.j2
A-valueLookup.yml
B-ACL-seq-loopvar.j2
B-ACL-seq-loopvar.yml
B-ACL-sequenced.j2
B-ACL-sequenced.yml
B-ACL-simple.j2
B-ACL-simple.yml
C-macros.j2
C-macros.yml
D-import-include.j2
D-import-include.yml
P1-strings.j2
P1-strings.yml
P2-slicing.j2
P2-slicing.yml
README.md
render.py
setup.sh

README.md

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.

Invoking render.py

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

Additional parameters

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