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

'NoneType' object has no attribute 'items' error from ec2_vpc_route_table_info #1668

Closed
1 task done
branic opened this issue Jul 27, 2023 · 2 comments · Fixed by #1670
Closed
1 task done

'NoneType' object has no attribute 'items' error from ec2_vpc_route_table_info #1668

branic opened this issue Jul 27, 2023 · 2 comments · Fixed by #1670
Labels
bug This issue/PR relates to a bug module module needs_triage plugins plugin (any type) python3 traceback

Comments

@branic
Copy link
Contributor

branic commented Jul 27, 2023

Summary

When gathering the route tables using the ec2_vpc_route_table_info module without any filters being provided always errors out with 'NoneType' object has no attribute 'items'.

The error is due to the fact that line 263 sets the default for filters to None instead of an empty dict.

Other *info modules (e.g. ec2_vpc_endpoint_info or ec2_vpc_subnet_info) define the default for filters to be an empty dict.

A simple work-around is to add filters: {} to the module options, but the module should use a sane default.

Issue Type

Bug Report

Component Name

ec2_vpc_route_table_info

Ansible Version

$ ansible --version
ansible [core 2.14.6]
  config file = /home/bevans/ansible-stuff/csa-aws-cleanup/ansible.cfg
  configured module search path = ['/home/runner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.9/site-packages/ansible
  ansible collection location = /home/runner/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.9.16 (main, May 31 2023, 12:21:58) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] (/usr/bin/python3.9)
  jinja version = 3.1.2
  libyaml = True

Collection Versions

$ ansible-galaxy collection list

# /usr/share/ansible/collections/ansible_collections
Collection    Version
------------- -------
amazon.aws    6.2.0  
community.aws 6.1.0  

AWS SDK versions

$ pip show boto boto3 botocore
WARNING: Package(s) not found: boto
Name: boto3
Version: 1.28.7
Summary: The AWS SDK for Python
Home-page: https://github.com/boto/boto3
Author: Amazon Web Services
Author-email: 
License: Apache License 2.0
Location: /usr/local/lib/python3.9/site-packages
Requires: botocore, jmespath, s3transfer
Required-by: 
---
Name: botocore
Version: 1.31.7
Summary: Low-level, data-driven core of boto 3.
Home-page: https://github.com/boto/botocore
Author: Amazon Web Services
Author-email: 
License: Apache License 2.0
Location: /usr/local/lib/python3.9/site-packages
Requires: jmespath, python-dateutil, urllib3
Required-by: boto3, s3transfer

Configuration

$ ansible-config dump --only-changed
CACHE_PLUGIN(env: ANSIBLE_CACHE_PLUGIN) = jsonfile
CACHE_PLUGIN_CONNECTION(env: ANSIBLE_CACHE_PLUGIN_CONNECTION) = /runner/artifacts/991b8baf-7c45-4de2-ad91-0444ac62ab05/fact_cache
CONFIG_FILE() = /home/bevans/ansible-stuff/csa-aws-cleanup/ansible.cfg
DEFAULT_CALLBACK_PLUGIN_PATH(env: ANSIBLE_CALLBACK_PLUGINS) = ['/runner/artifacts/991b8baf-7c45-4de2-ad91-0444ac62ab05/callback']
DEFAULT_ROLES_PATH(/home/bevans/ansible-stuff/csa-aws-cleanup/ansible.cfg) = ['/home/bevans/ansible-stuff/csa-aws-cleanup/roles', '/home/runner/.ansible/roles', '/usr/share/ansible/roles', '/etc/ansible/roles']
DEFAULT_STDOUT_CALLBACK(env: ANSIBLE_STDOUT_CALLBACK) = awx_display
HOST_KEY_CHECKING(env: ANSIBLE_HOST_KEY_CHECKING) = False
RETRY_FILES_ENABLED(env: ANSIBLE_RETRY_FILES_ENABLED) = False

OS / Environment

RHEL 8 based execution environment targeting localhost to query the AWS APIs

Steps to Reproduce

--
- name: Testing playbook
  hosts: localhost
  gather_facts: false

  tasks:
    - name: Gather route tables info
      amazon.aws.ec2_vpc_endpoint_info:
        profile: <<REDACTED>>
        region: us-east-2
      register: route_tables

Expected Results

I expected the playbook to run without a module error.

Actual Results

ansible-navigator run -m stdout --pae false playbooks/test.yml -vvvv
ansible-playbook [core 2.14.6]
  config file = /home/bevans/ansible-stuff/csa-aws-cleanup/ansible.cfg
  configured module search path = ['/home/runner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.9/site-packages/ansible
  ansible collection location = /home/runner/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible-playbook
  python version = 3.9.16 (main, May 31 2023, 12:21:58) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] (/usr/bin/python3.9)
  jinja version = 3.1.2
  libyaml = True
Using /home/bevans/ansible-stuff/csa-aws-cleanup/ansible.cfg as config file
setting up inventory plugins
host_list declined parsing /home/bevans/ansible-stuff/csa-aws-cleanup/inventory.ini as it did not pass its verify_file() method
script declined parsing /home/bevans/ansible-stuff/csa-aws-cleanup/inventory.ini as it did not pass its verify_file() method
auto declined parsing /home/bevans/ansible-stuff/csa-aws-cleanup/inventory.ini as it did not pass its verify_file() method
yaml declined parsing /home/bevans/ansible-stuff/csa-aws-cleanup/inventory.ini as it did not pass its verify_file() method
Set default localhost to localhost
Parsed /home/bevans/ansible-stuff/csa-aws-cleanup/inventory.ini inventory source with ini plugin
Loading collection amazon.aws from /usr/share/ansible/collections/ansible_collections/amazon/aws
Loading callback plugin default of type stdout, v2.0 from /usr/lib/python3.9/site-packages/ansible/plugins/callback/default.py
Loading callback plugin awx_display of type stdout, v2.0 from /runner/artifacts/77212833-48b1-407b-80d0-26bf5a2a747b/callback/awx_display.py
Skipping callback 'awx_display', as we already have a stdout callback.
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.

PLAYBOOK: test.yml ******************************************************************************************************************************************
Positional arguments: /home/bevans/ansible-stuff/csa-aws-cleanup/playbooks/test.yml
verbosity: 4
connection: smart
timeout: 10
become_method: sudo
tags: ('all',)
inventory: ('/home/bevans/ansible-stuff/csa-aws-cleanup/inventory.ini',)
forks: 5
1 plays in /home/bevans/ansible-stuff/csa-aws-cleanup/playbooks/test.yml

PLAY [Testing playbook] *************************************************************************************************************************************

TASK [Gather route tables info] *****************************************************************************************************************************
task path: /home/bevans/ansible-stuff/csa-aws-cleanup/playbooks/test.yml:13
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: root
<localhost> EXEC /bin/sh -c 'echo ~root && sleep 0'
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/runner/.ansible/tmp `"&& mkdir "` echo /home/runner/.ansible/tmp/ansible-tmp-1690485480.8549228-25-268646880821548 `" && echo ansible-tmp-1690485480.8549228-25-268646880821548="` echo /home/runner/.ansible/tmp/ansible-tmp-1690485480.8549228-25-268646880821548 `" ) && sleep 0'
Using module file /usr/share/ansible/collections/ansible_collections/amazon/aws/plugins/modules/ec2_vpc_route_table_info.py
<localhost> PUT /home/runner/.ansible/tmp/ansible-local-21xvl1k7gt/tmpl8j_huqx TO /home/runner/.ansible/tmp/ansible-tmp-1690485480.8549228-25-268646880821548/AnsiballZ_ec2_vpc_route_table_info.py
<localhost> EXEC /bin/sh -c 'chmod u+x /home/runner/.ansible/tmp/ansible-tmp-1690485480.8549228-25-268646880821548/ /home/runner/.ansible/tmp/ansible-tmp-1690485480.8549228-25-268646880821548/AnsiballZ_ec2_vpc_route_table_info.py && sleep 0'
<localhost> EXEC /bin/sh -c '/usr/bin/python3.9 /home/runner/.ansible/tmp/ansible-tmp-1690485480.8549228-25-268646880821548/AnsiballZ_ec2_vpc_route_table_info.py && sleep 0'
<localhost> EXEC /bin/sh -c 'rm -f -r /home/runner/.ansible/tmp/ansible-tmp-1690485480.8549228-25-268646880821548/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
  File "/home/runner/.ansible/tmp/ansible-tmp-1690485480.8549228-25-268646880821548/AnsiballZ_ec2_vpc_route_table_info.py", line 107, in <module>
    _ansiballz_main()
  File "/home/runner/.ansible/tmp/ansible-tmp-1690485480.8549228-25-268646880821548/AnsiballZ_ec2_vpc_route_table_info.py", line 99, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/home/runner/.ansible/tmp/ansible-tmp-1690485480.8549228-25-268646880821548/AnsiballZ_ec2_vpc_route_table_info.py", line 47, in invoke_module
    runpy.run_module(mod_name='ansible_collections.amazon.aws.plugins.modules.ec2_vpc_route_table_info', init_globals=dict(_module_fqn='ansible_collections.amazon.aws.plugins.modules.ec2_vpc_route_table_info', _modlib_path=modlib_path),
  File "/usr/lib64/python3.9/runpy.py", line 225, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "/usr/lib64/python3.9/runpy.py", line 97, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/usr/lib64/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/tmp/ansible_amazon.aws.ec2_vpc_route_table_info_payload_vi8kwltv/ansible_amazon.aws.ec2_vpc_route_table_info_payload.zip/ansible_collections/amazon/aws/plugins/modules/ec2_vpc_route_table_info.py", line 274, in <module>
  File "/tmp/ansible_amazon.aws.ec2_vpc_route_table_info_payload_vi8kwltv/ansible_amazon.aws.ec2_vpc_route_table_info_payload.zip/ansible_collections/amazon/aws/plugins/modules/ec2_vpc_route_table_info.py", line 270, in main
  File "/tmp/ansible_amazon.aws.ec2_vpc_route_table_info_payload_vi8kwltv/ansible_amazon.aws.ec2_vpc_route_table_info_payload.zip/ansible_collections/amazon/aws/plugins/modules/ec2_vpc_route_table_info.py", line 250, in list_ec2_vpc_route_tables
  File "/tmp/ansible_amazon.aws.ec2_vpc_route_table_info_payload_vi8kwltv/ansible_amazon.aws.ec2_vpc_route_table_info_payload.zip/ansible_collections/amazon/aws/plugins/module_utils/transformation.py", line 58, in ansible_dict_to_boto3_filter_list
AttributeError: 'NoneType' object has no attribute 'items'
fatal: [localhost]: FAILED! => {
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\n  File \"/home/runner/.ansible/tmp/ansible-tmp-1690485480.8549228-25-268646880821548/AnsiballZ_ec2_vpc_route_table_info.py\", line 107, in <module>\n    _ansiballz_main()\n  File \"/home/runner/.ansible/tmp/ansible-tmp-1690485480.8549228-25-268646880821548/AnsiballZ_ec2_vpc_route_table_info.py\", line 99, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/runner/.ansible/tmp/ansible-tmp-1690485480.8549228-25-268646880821548/AnsiballZ_ec2_vpc_route_table_info.py\", line 47, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.amazon.aws.plugins.modules.ec2_vpc_route_table_info', init_globals=dict(_module_fqn='ansible_collections.amazon.aws.plugins.modules.ec2_vpc_route_table_info', _modlib_path=modlib_path),\n  File \"/usr/lib64/python3.9/runpy.py\", line 225, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib64/python3.9/runpy.py\", line 97, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/usr/lib64/python3.9/runpy.py\", line 87, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_amazon.aws.ec2_vpc_route_table_info_payload_vi8kwltv/ansible_amazon.aws.ec2_vpc_route_table_info_payload.zip/ansible_collections/amazon/aws/plugins/modules/ec2_vpc_route_table_info.py\", line 274, in <module>\n  File \"/tmp/ansible_amazon.aws.ec2_vpc_route_table_info_payload_vi8kwltv/ansible_amazon.aws.ec2_vpc_route_table_info_payload.zip/ansible_collections/amazon/aws/plugins/modules/ec2_vpc_route_table_info.py\", line 270, in main\n  File \"/tmp/ansible_amazon.aws.ec2_vpc_route_table_info_payload_vi8kwltv/ansible_amazon.aws.ec2_vpc_route_table_info_payload.zip/ansible_collections/amazon/aws/plugins/modules/ec2_vpc_route_table_info.py\", line 250, in list_ec2_vpc_route_tables\n  File \"/tmp/ansible_amazon.aws.ec2_vpc_route_table_info_payload_vi8kwltv/ansible_amazon.aws.ec2_vpc_route_table_info_payload.zip/ansible_collections/amazon/aws/plugins/module_utils/transformation.py\", line 58, in ansible_dict_to_boto3_filter_list\nAttributeError: 'NoneType' object has no attribute 'items'\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}

PLAY RECAP **************************************************************************************************************************************************
localhost                  : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   

Please review the log for errors.

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
@ansibullbot
Copy link

Files identified in the description:

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibullbot
Copy link

@ansibullbot ansibullbot added bug This issue/PR relates to a bug module module plugins plugin (any type) python3 traceback labels Jul 27, 2023
softwarefactory-project-zuul bot pushed a commit that referenced this issue Aug 1, 2023
Default filters to empty dictionary

SUMMARY

Changes the default for the filters option from None to an empty dictionary.

Fixes: #1668
ISSUE TYPE


Bugfix Pull Request

COMPONENT NAME

ec2_vpc_route_table_info
ADDITIONAL INFORMATION


This matches what other *info modules (e.g. ec2_vpc_endpoint_info or ec2_vpc_subnet_info) do for the filters option default.

Reviewed-by: Alina Buzachis
Reviewed-by: Brant Evans <bevans@redhat.com>
Reviewed-by: Mark Chappell
Reviewed-by: Mike Graves <mgraves@redhat.com>
patchback bot pushed a commit that referenced this issue Aug 1, 2023
Default filters to empty dictionary

SUMMARY

Changes the default for the filters option from None to an empty dictionary.

Fixes: #1668
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME

ec2_vpc_route_table_info
ADDITIONAL INFORMATION

This matches what other *info modules (e.g. ec2_vpc_endpoint_info or ec2_vpc_subnet_info) do for the filters option default.

Reviewed-by: Alina Buzachis
Reviewed-by: Brant Evans <bevans@redhat.com>
Reviewed-by: Mark Chappell
Reviewed-by: Mike Graves <mgraves@redhat.com>
(cherry picked from commit 31c7506)
softwarefactory-project-zuul bot pushed a commit that referenced this issue Aug 1, 2023
[PR #1670/31c75069 backport][stable-6] Default filters to empty dictionary

This is a backport of PR #1670 as merged into main (31c7506).
SUMMARY

Changes the default for the filters option from None to an empty dictionary.

Fixes: #1668
ISSUE TYPE


Bugfix Pull Request

COMPONENT NAME

ec2_vpc_route_table_info
ADDITIONAL INFORMATION


This matches what other *info modules (e.g. ec2_vpc_endpoint_info or ec2_vpc_subnet_info) do for the filters option default.

Reviewed-by: Alina Buzachis
krisek pushed a commit to krisek/amazon.aws that referenced this issue Aug 31, 2023
Default filters to empty dictionary

SUMMARY

Changes the default for the filters option from None to an empty dictionary.

Fixes: ansible-collections#1668
ISSUE TYPE


Bugfix Pull Request

COMPONENT NAME

ec2_vpc_route_table_info
ADDITIONAL INFORMATION


This matches what other *info modules (e.g. ec2_vpc_endpoint_info or ec2_vpc_subnet_info) do for the filters option default.

Reviewed-by: Alina Buzachis
Reviewed-by: Brant Evans <bevans@redhat.com>
Reviewed-by: Mark Chappell
Reviewed-by: Mike Graves <mgraves@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue/PR relates to a bug module module needs_triage plugins plugin (any type) python3 traceback
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants