diff options
author | Zac Medico <zmedico@gmail.com> | 2017-08-10 00:50:53 +0200 |
---|---|---|
committer | Brian Coca <bcoca@users.noreply.github.com> | 2017-08-10 00:50:53 +0200 |
commit | 501fc7a248c4ad09c2593a200b3fbbdff0e48c70 (patch) | |
tree | ee1c8a420d8ffb9af7dc5664b82025902041009b /test/integration/targets/template/templates | |
parent | Various small changes and adding myself (diff) | |
download | ansible-501fc7a248c4ad09c2593a200b3fbbdff0e48c70.tar.xz ansible-501fc7a248c4ad09c2593a200b3fbbdff0e48c70.zip |
template: fix KeyError: 'undefined variable: 0 (#27972)
* template: fix KeyError: 'undefined variable: 0
For compatibility with the Context.get_all() implementation
in jinja 2.9, make AnsibleJ2Vars implement collections.Mapping.
Also, make AnsibleJ2Template.newcontext() handle dict type
for the 'vars' parameter.
See: https://github.com/pallets/jinja/commit/d67f0fd4cc2a4af08f51f4466150d49da7798729
Fixes: https://github.com/ansible/ansible/issues/20494
* add units/template/test_vars
* intg tests for jinja-2.9 issues like 20494
test cases here are based on
https://github.com/ansible/ansible/issues/20494#issue-202108318
Diffstat (limited to 'test/integration/targets/template/templates')
6 files changed, 16 insertions, 0 deletions
diff --git a/test/integration/targets/template/templates/bar b/test/integration/targets/template/templates/bar new file mode 100644 index 0000000000..2b60207f03 --- /dev/null +++ b/test/integration/targets/template/templates/bar @@ -0,0 +1 @@ +Goodbye diff --git a/test/integration/targets/template/templates/import_as.j2 b/test/integration/targets/template/templates/import_as.j2 new file mode 100644 index 0000000000..b06f1be849 --- /dev/null +++ b/test/integration/targets/template/templates/import_as.j2 @@ -0,0 +1,4 @@ +{% import 'qux' as qux %} +hello world import as +{{ qux.wibble }} +{% include 'bar' %} diff --git a/test/integration/targets/template/templates/import_as_with_context.j2 b/test/integration/targets/template/templates/import_as_with_context.j2 new file mode 100644 index 0000000000..3dd806a35b --- /dev/null +++ b/test/integration/targets/template/templates/import_as_with_context.j2 @@ -0,0 +1,3 @@ +{% import 'qux' as qux with context %} +hello world as qux with context +{{ qux.wibble }} diff --git a/test/integration/targets/template/templates/import_as_with_context.js b/test/integration/targets/template/templates/import_as_with_context.js new file mode 100644 index 0000000000..3dd806a35b --- /dev/null +++ b/test/integration/targets/template/templates/import_as_with_context.js @@ -0,0 +1,3 @@ +{% import 'qux' as qux with context %} +hello world as qux with context +{{ qux.wibble }} diff --git a/test/integration/targets/template/templates/import_with_context.j2 b/test/integration/targets/template/templates/import_with_context.j2 new file mode 100644 index 0000000000..104e68b347 --- /dev/null +++ b/test/integration/targets/template/templates/import_with_context.j2 @@ -0,0 +1,4 @@ +{% import 'qux' as qux with context %} +hello world with context +{{ qux.wibble }} +{% include 'bar' %} diff --git a/test/integration/targets/template/templates/qux b/test/integration/targets/template/templates/qux new file mode 100644 index 0000000000..d8cd22e41a --- /dev/null +++ b/test/integration/targets/template/templates/qux @@ -0,0 +1 @@ +{% set wibble = "WIBBLE" %} |