Bug 1697237
| Summary: | Jinja2 templating breaks with "<lambda>() takes exactly 0 arguments (1 given)" in Ansible | ||
|---|---|---|---|
| Product: | Red Hat Enterprise Linux 7 | Reporter: | Till Maas <till> |
| Component: | python-jinja2 | Assignee: | Python Maintainers <python-maint> |
| Status: | CLOSED ERRATA | QA Contact: | Lukáš Zachar <lzachar> |
| Severity: | unspecified | Docs Contact: | |
| Priority: | unspecified | ||
| Version: | 7.7 | CC: | cstratak, hhorak, jkejda, mhroncok, pviktori |
| Target Milestone: | rc | ||
| Target Release: | --- | ||
| Hardware: | Unspecified | ||
| OS: | Unspecified | ||
| Whiteboard: | |||
| Fixed In Version: | python-jinja2-2.7.2-3.el7 | Doc Type: | No Doc Update |
| Doc Text: | Story Points: | --- | |
| Clone Of: | Environment: | ||
| Last Closed: | 2019-08-06 13:17:46 UTC | Type: | Bug |
| Regression: | --- | Mount Type: | --- |
| Documentation: | --- | CRM: | |
| Verified Versions: | Category: | --- | |
| oVirt Team: | --- | RHEL 7.3 requirements from Atomic Host: | |
| Cloudforms Team: | --- | Target Upstream Version: | |
| Embargoed: | |||
Minimal example using Ansible:
cat > 'dict_test.yml' <<EOF
---
- hosts: localhost
vars:
dict_test: "{{ dict([(0, 1)]) }}"
tasks:
- name: Show dict
debug:
var: dict_test
EOF
Test run on RHEL 7.6:
ansible-playbook ~/dict_test.yml
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
PLAY [localhost] **********************************************************************************************************************
TASK [Gathering Facts] ****************************************************************************************************************
ok: [localhost]
TASK [Show dict] **********************************************************************************************************************
fatal: [localhost]: FAILED! => {"msg": "An unhandled exception occurred while templating '{{ dict([(0, 1)]) }}'. Error was a <class 'ansible.errors.AnsibleError'>, original message: Unexpected templating type error occurred on ({{ dict([(0, 1)]) }}): <lambda>() takes exactly 0 arguments (1 given)"}
to retry, use: --limit @/root/dict_test.retry
PLAY RECAP ****************************************************************************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=1
====================================================
It works on Fedora 28:
ansible-playbook dict_test.yml
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
PLAY [localhost] *****************************************************************************************************************************************************************************************
TASK [Gathering Facts] ***********************************************************************************************************************************************************************************
ok: [localhost]
TASK [Show dict] *****************************************************************************************************************************************************************************************
ok: [localhost] => {
"dict_test": {
"0": 1
}
}
PLAY RECAP ***********************************************************************************************************************************************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=0
FWIW this started working in Jinja2 2.8 upstream. Nothing interesting in the chnagelog: http://jinja.pocoo.org/docs/2.10/changelog/#version-2-8 (In reply to Miro Hrončok from comment #4) > Upstream fix: > https://github.com/pallets/jinja/commit/ > 6179c02c91800d220de03006117afa5e6d60f0f6 Awesome, this simple fix makes it work! I patched it on my test VM and now the playbooks work again. Would be great to get this shipped! I'll send a Pagure PR, but somebody else from the team needs to take it from there. Since the problem described in this bug report should be resolved in a recent advisory, it has been closed with a resolution of ERRATA. For information on the advisory, and where to find the updated files, follow the link below. If the solution does not work for you, open a new bug report. https://access.redhat.com/errata/RHBA-2019:2313 |
Description of problem: This ansible playbook breaks on RHEL 7.6: --- - hosts: localhost vars: pci_address: "virtio0" device_by_pci_address: "{{ dict(ansible_facts | json_query('@.*| [?pciid].[pciid, device ]')) }}" tasks: - name: Show devices by PCI address debug: var: device_by_pci_address - name: "Show device with PCI address {{ pci_address }}" debug: msg: "The device {{ device_by_pci_address[pci_address] }} is at the PCI address {{ pci_address }}" Version-Release number of selected component (if applicable): ansible-2.7.9-1.el7ae python-jinja2-2.7.2-2.el7 How reproducible: always Steps to Reproduce: python2 -c 'import jinja2; jinja2.Environment().from_string("{{ dict([(0, 1)]) }}").render()' or ansible-playbook on the playbook mentioned above Actual results: Traceback (most recent call last): File "<string>", line 1, in <module> File "/usr/lib/python2.7/site-packages/jinja2/environment.py", line 969, in render return self.environment.handle_exception(exc_info, True) File "/usr/lib/python2.7/site-packages/jinja2/environment.py", line 742, in handle_exception reraise(exc_type, exc_value, tb) File "<template>", line 1, in top-level template code TypeError: <lambda>() takes exactly 0 arguments (1 given) Expected results: should not raise the exceptions Additional info: I am not 100% sure that the minimum example hightlights the problem. At least it triggers the same error and it does not raise on Fedora.