Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dict2items in loops throw typeerror, fails task even when task should be skipped. #70413

Closed
gamuniz opened this issue Jul 1, 2020 · 1 comment · Fixed by #70417
Closed

dict2items in loops throw typeerror, fails task even when task should be skipped. #70413

gamuniz opened this issue Jul 1, 2020 · 1 comment · Fixed by #70417
Labels
affects_2.9 This issue/PR affects Ansible v2.9 bug This issue/PR relates to a bug. support:community This issue/PR relates to code supported by the Ansible community.

Comments

@gamuniz
Copy link
Contributor

gamuniz commented Jul 1, 2020

SUMMARY

Using loops with dict2items fails even when task should be skipped by conditional.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

dict2items filter

ANSIBLE VERSION
ansible --version
ansible 2.9.9
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /var/lib/awx/venv/ansible-2.6.4/lib/python2.7/site-packages/ansible
  executable location = /var/lib/awx/venv/ansible-2.6.4/bin/ansible
  python version = 2.7.5 (default, Apr  2 2020, 13:16:51) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
CONFIGURATION
ansible-config dump --only-changed
GALAXY_SERVER_LIST(/etc/ansible/ansible.cfg) = [u'official_galaxy']
OS / ENVIRONMENT

CentOS 7.8

STEPS TO REPRODUCE

Run this playbook

- hosts: localhost
  gather_facts: false
  tasks:
    - debug: msg={{item}}
      with_dict: '{{myundef}}'
      when:
       - myundef is defined
    - debug: msg={{item}}
      loop: '{{myundef|dict2items}}'
      when: 
       - myundef is defined
      

EXPECTED RESULTS

Expected that both tasks are skipped as conditional is not met.

ACTUAL RESULTS
ansible-playbook 2.9.9
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /var/lib/awx/venv/ansible-2.6.4/lib/python2.7/site-packages/ansible
  executable location = /var/lib/awx/venv/ansible-2.6.4/bin/ansible-playbook
  python version = 2.7.5 (default, Apr  2 2020, 13:16:51) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
Using /etc/ansible/ansible.cfg as config file
setting up inventory plugins
host_list declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
script declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
auto declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Parsed /etc/ansible/hosts inventory source with ini plugin
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not
match 'all'
Loading callback plugin default of type stdout, v2.0 from /var/lib/awx/venv/ansible-2.6.4/lib/python2.7/site-packages/ansible/plugins/callback/default.pyc

PLAYBOOK: test_dict2items.yml ***************************************************************************************
Positional arguments: test_dict2items.yml
become_method: sudo
inventory: (u'/etc/ansible/hosts',)
forks: 5
tags: (u'all',)
verbosity: 4
connection: smart
timeout: 10
1 plays in test_dict2items.yml

PLAY [localhost] ****************************************************************************************************
META: ran handlers

TASK [debug] ********************************************************************************************************
task path: /var/lib/awx/projects/Manual/test_dict2items.yml:4
skipping: [localhost] => {}

TASK [debug] ********************************************************************************************************
task path: /var/lib/awx/projects/Manual/test_dict2items.yml:8
fatal: [localhost]: FAILED! => {
    "msg": "dict2items requires a dictionary, got <class 'ansible.template.AnsibleUndefined'> instead."
}

PLAY RECAP **********************************************************************************************************
localhost                  : ok=0    changed=0    unreachable=0    failed=1    skipped=1    rescued=0    ignored=0  
@bcoca
Copy link
Member

bcoca commented Jul 1, 2020

actually, it returns an AnsibleFilterError after capturing/bypassing the TypeError

The fix would be to actually emit the TypeError from filters as we do handle it for the Undefined case in there already.

@ansibot ansibot added affects_2.9 This issue/PR affects Ansible v2.9 bug This issue/PR relates to a bug. needs_triage Needs a first human triage before being processed. support:community This issue/PR relates to code supported by the Ansible community. labels Jul 1, 2020
@sivel sivel removed the needs_triage Needs a first human triage before being processed. label Jul 14, 2020
@ansible ansible locked and limited conversation to collaborators Aug 7, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.9 This issue/PR affects Ansible v2.9 bug This issue/PR relates to a bug. support:community This issue/PR relates to code supported by the Ansible community.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants