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

Unexpected Exception, this is probably a bug: 'NoneType' object is not iterable #31249

Closed
joelwking opened this issue Oct 3, 2017 · 1 comment · Fixed by #31313
Closed

Unexpected Exception, this is probably a bug: 'NoneType' object is not iterable #31249

joelwking opened this issue Oct 3, 2017 · 1 comment · Fixed by #31313
Labels
affects_2.5 This issue/PR affects Ansible v2.5 bug This issue/PR relates to a bug. support:core This issue/PR relates to code supported by the Ansible Engineering Team.

Comments

@joelwking
Copy link

ISSUE TYPE
  • Bug Report
COMPONENT NAME

ansible-playbook

ANSIBLE VERSION
ansible 2.5.0 (devel 101377768b) last updated 2017/10/03 14:54:07 (GMT +000)
  config file = /sbux_ansible/ansible.cfg
  configured module search path = [u'/sbux_ansible/library', u'/usr/share/ansible']
  ansible python module location = /home/ubuntu/ansible/lib/ansible
  executable location = /home/ubuntu/ansible/bin/ansible
  python version = 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]

also in 2.4, and observed in 2.3

ansible 2.3.1.0
  config file = /home/administrator/ansible/playbooks/ansible.cfg
  configured module search path = [u'/usr/share/ansible/']
  python version = 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]
CONFIGURATION
DEFAULT_HOST_LIST(/sbux_ansible/ansible.cfg) = [u'/sbux_ansible/inventory.txt']
DEFAULT_MODULE_PATH(/sbux_ansible/ansible.cfg) = [u'/sbux_ansible/library', u'/usr/share/ansible']
RETRY_FILES_ENABLED(/sbux_ansible/ansible.cfg) = False
OS / ENVIRONMENT

ubuntu/xenial64

SUMMARY

Method play.get_vars_files() returns None rather than an empty list. In very large playbooks, it is not obvious what is causing the exception.

STEPS TO REPRODUCE

If vars_files has no entries (note the comment), the play fails with TypeError: 'NoneType' object is not iterable

#!/usr/bin/ansible-playbook
---
#
#
#      Copyright (c) 2017 World Wide Technology, Inc.
#      All rights reserved.
#
#      author: Joel W. King,  World Wide Technology
#
#
- hosts: localhost
  connection: local
  user: administrator

  vars_files:
   #  - "{{playbook_dir}}/passwords.yml"

  tasks:
  - name: debug the output
    debug: msg="{{f5.username}}"
EXPECTED RESULTS

Ignore the empty list or issue a warning to the user.

ACTUAL RESULTS
ubuntu@ubuntu-xenial:~/ansible/playbooks$ ansible-playbook ./debug_vars_files.yml -vvv
ansible-playbook 2.5.0 (devel 101377768b) last updated 2017/10/03 14:54:07 (GMT +000)
  config file = /sbux_ansible/ansible.cfg
  configured module search path = [u'/sbux_ansible/library', u'/usr/share/ansible']
  ansible python module location = /home/ubuntu/ansible/lib/ansible
  executable location = /home/ubuntu/ansible/bin/ansible-playbook
  python version = 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]
Using /sbux_ansible/ansible.cfg as config file
Parsed /sbux_ansible/inventory.txt inventory source with ini plugin

PLAYBOOK: debug_vars_files.yml *****************************************************************************************************
1 plays in ./debug_vars_files.yml
ERROR! Unexpected Exception, this is probably a bug: 'NoneType' object is not iterable
the full traceback was:

Traceback (most recent call last):
  File "/home/ubuntu/ansible/bin/ansible-playbook", line 109, in <module>
    exit_code = cli.run()
  File "/home/ubuntu/ansible/lib/ansible/cli/playbook.py", line 130, in run
    results = pbex.run()
  File "/home/ubuntu/ansible/lib/ansible/executor/playbook_executor.py", line 126, in run
    all_vars = self._variable_manager.get_vars(play=play)
  File "/home/ubuntu/ansible/lib/ansible/vars/manager.py", line 348, in get_vars
    for vars_file_item in play.get_vars_files():
TypeError: 'NoneType' object is not iterable
@ansibot ansibot added affects_2.5 This issue/PR affects Ansible v2.5 bug_report needs_triage Needs a first human triage before being processed. support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Oct 3, 2017
@ryansb
Copy link
Contributor

ryansb commented Oct 3, 2017

The workaround here is, of course, to supply an empty list instead of a None. I notice that the vars file attributes are defaulted to [], but won't override if the use supplies None which we could definitely handle more gracefully.

@ryansb ryansb removed the needs_triage Needs a first human triage before being processed. label Oct 3, 2017
@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 7, 2018
@ansible ansible locked and limited conversation to collaborators Apr 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.5 This issue/PR affects Ansible v2.5 bug This issue/PR relates to a bug. support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants