Bug 1697237 - Jinja2 templating breaks with "<lambda>() takes exactly 0 arguments (1 given)" in Ansible
Summary: Jinja2 templating breaks with "<lambda>() takes exactly 0 arguments (1 given)...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: python-jinja2
Version: 7.7
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: rc
: ---
Assignee: Python Maintainers
QA Contact: Lukas Zachar
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2019-04-08 07:28 UTC by Till Maas
Modified: 2019-08-06 13:17 UTC (History)
5 users (show)

Fixed In Version: python-jinja2-2.7.2-3.el7
Doc Type: No Doc Update
Doc Text:
Clone Of:
Environment:
Last Closed: 2019-08-06 13:17:46 UTC


Attachments (Terms of Use)


Links
System ID Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2019:2313 None None None 2019-08-06 13:17:51 UTC

Description Till Maas 2019-04-08 07:28:12 UTC
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.

Comment 2 Till Maas 2019-04-09 06:38:18 UTC
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

Comment 3 Miro Hrončok 2019-04-09 09:13:38 UTC
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

Comment 5 Till Maas 2019-04-10 08:23:50 UTC
(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!

Comment 6 Miro Hrončok 2019-04-10 11:07:15 UTC
I'll send a Pagure PR, but somebody else from the team needs to take it from there.

Comment 12 errata-xmlrpc 2019-08-06 13:17:46 UTC
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


Note You need to log in before you can comment on or make changes to this bug.