Created
July 31, 2017 15:39
-
-
Save logan2211/32a98a8bad71ed393badd621668e6a58 to your computer and use it in GitHub Desktop.
Broken jinja2 include inside loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
specific1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ubuntu@2378491cf3ce:/template-bug$ ansible-playbook test.yml -e test_template=test-context.j2 | |
[WARNING]: Host file not found: /etc/ansible/hosts | |
[WARNING]: provided hosts list is empty, only localhost is available | |
PLAY [localhost] ****************************************************************************************************************************************************************** | |
TASK [Test template] ************************************************************************************************************************************************************** | |
fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "msg": "KeyError: 'undefined variable: 0'"} | |
to retry, use: --limit @/template-bug/test.retry | |
PLAY RECAP ************************************************************************************************************************************************************************ | |
localhost : ok=0 changed=0 unreachable=0 failed=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ubuntu@2378491cf3ce:/template-bug$ ansible-playbook test.yml -e test_template=test-nocontext.j2 | |
[WARNING]: Host file not found: /etc/ansible/hosts | |
[WARNING]: provided hosts list is empty, only localhost is available | |
PLAY [localhost] ****************************************************************************************************************************************************************** | |
TASK [Test template] ************************************************************************************************************************************************************** | |
fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "msg": "AttributeError: 'NoneType' object has no attribute 'add_locals'"} | |
to retry, use: --limit @/template-bug/test.retry | |
PLAY RECAP ************************************************************************************************************************************************************************ | |
localhost : ok=0 changed=0 unreachable=0 failed=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% set b = file_base %} | |
{% for p in file_part %} | |
{% include file_base ~ p ~ '.j2' %} | |
{% endfor %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% set b = file_base %} | |
{% for p in file_part %} | |
{% include file_base ~ p ~ '.j2' without context %} | |
{% endfor %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Test playbook | |
# . | |
# ├── templates | |
# │ ├── base_specific1.j2 | |
# │ ├── test-context.j2 | |
# │ └── test-nocontext.j2 | |
# └── test.yml | |
- hosts: localhost | |
gather_facts: no | |
vars: | |
test_template: test-context.j2 | |
file_base: 'base_' | |
file_part: | |
- specific1 | |
tasks: | |
- name: Test template | |
template: | |
src: "{{ test_template }}" | |
dest: "{{ playbook_dir }}/output-rendered.txt" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment