Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

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-jinja2Assignee: Python Maintainers <python-maint>
Status: CLOSED ERRATA QA Contact: Lukáš Zachar <lzachar>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 7.7CC: 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:

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