ansible-collections / community.aws

Ansible Collection for Community AWS
GNU General Public License v3.0
189 stars 398 forks source link

route53 state: get AttributeError: 'NoneType' object has no attribute 'items' #798

Closed kaovilai closed 2 years ago

kaovilai commented 3 years ago

Summary

route53 unable to return results from get

Issue Type

Bug Report

Component Name

community.aws.route53

Ansible Version

$ ansible --version
ansible [core 2.11.3] 
  config file = None
  configured module search path = ['/Users/tiger/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
  ansible collection location = /Users/tiger/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.9.7 (default, Sep  3 2021, 12:37:55) [Clang 12.0.5 (clang-1205.0.22.9)]
  jinja version = 3.0.1
  libyaml = True

Collection Versions

$ ansible-galaxy collection list
lections
Collection                    Version
----------------------------- -------
amazon.aws                    1.5.0  
ansible.netcommon             2.2.0  
ansible.posix                 1.2.0  
ansible.utils                 2.3.0  
ansible.windows               1.7.0  
arista.eos                    2.2.0  
awx.awx                       19.2.2 
azure.azcollection            1.7.0  
check_point.mgmt              2.0.0  
chocolatey.chocolatey         1.1.0  
cisco.aci                     2.0.0  
cisco.asa                     2.0.2  
cisco.intersight              1.0.15 
cisco.ios                     2.3.0  
cisco.iosxr                   2.3.0  
cisco.meraki                  2.4.2  
cisco.mso                     1.2.0  
cisco.nso                     1.0.3  
cisco.nxos                    2.4.0  
cisco.ucs                     1.6.0  
cloudscale_ch.cloud           2.2.0  
community.aws                 1.5.0  
community.azure               1.0.0  
community.crypto              1.7.1  
community.digitalocean        1.7.0  
community.docker              1.8.0  
community.fortios             1.0.0  
community.general             3.3.0  
community.google              1.0.0  
community.grafana             1.2.1  
community.hashi_vault         1.3.0  
community.hrobot              1.1.1  
community.kubernetes          1.2.1  
community.kubevirt            1.0.0  
community.libvirt             1.0.1  
community.mongodb             1.2.1  
community.mysql               2.1.0  
community.network             3.0.0  
community.okd                 1.1.2  
community.postgresql          1.3.0  
community.proxysql            1.0.0  
community.rabbitmq            1.0.3  
community.routeros            1.2.0  
community.skydive             1.0.0  
community.sops                1.1.0  
community.vmware              1.11.0 
community.windows             1.5.0  
community.zabbix              1.3.0  
containers.podman             1.6.1  
cyberark.conjur               1.1.0  
cyberark.pas                  1.0.7  
dellemc.enterprise_sonic      1.1.0  
dellemc.openmanage            3.5.0  
dellemc.os10                  1.1.1  
dellemc.os6                   1.0.7  
dellemc.os9                   1.0.4  
f5networks.f5_modules         1.10.1 
fortinet.fortimanager         2.1.2  
fortinet.fortios              2.1.1  
frr.frr                       1.0.3  
gluster.gluster               1.0.1  
google.cloud                  1.0.2  
hetzner.hcloud                1.4.3  
hpe.nimble                    1.1.3  
ibm.qradar                    1.0.3  
infinidat.infinibox           1.2.4  
inspur.sm                     1.2.0  
junipernetworks.junos         2.3.0  
kubernetes.core               1.2.1  
mellanox.onyx                 1.0.0  
netapp.aws                    21.2.0 
netapp.azure                  21.7.0 
netapp.cloudmanager           21.7.0 
netapp.elementsw              21.6.1 
netapp.ontap                  21.7.0 
netapp.um_info                21.6.0 
netapp_eseries.santricity     1.2.13 
netbox.netbox                 3.1.1  
ngine_io.cloudstack           2.1.0  
ngine_io.exoscale             1.0.0  
ngine_io.vultr                1.1.0  
openstack.cloud               1.5.0  
openvswitch.openvswitch       2.0.0  
ovirt.ovirt                   1.5.3  
purestorage.flasharray        1.8.0  
purestorage.flashblade        1.6.0  
sensu.sensu_go                1.11.1 
servicenow.servicenow         1.0.6  
splunk.es                     1.0.2  
t_systems_mms.icinga_director 1.18.0 
theforeman.foreman            2.1.1  
vyos.vyos                     2.3.1  
wti.remote                    1.0.1  

AWS SDK versions

$ pip show boto boto3 botocore
Name: boto
Version: 2.49.0
Summary: Amazon Web Services Library
Home-page: https://github.com/boto/boto/
Author: Mitch Garnaat
Author-email: mitch@garnaat.com
License: MIT
Location: /usr/local/lib/python3.9/site-packages
Requires: 
Required-by: 
---
Name: boto3
Version: 1.14.43
Summary: The AWS SDK for Python
Home-page: https://github.com/boto/boto3
Author: Amazon Web Services
Author-email: UNKNOWN
License: Apache License 2.0
Location: /usr/local/lib/python3.9/site-packages
Requires: botocore, jmespath, s3transfer
Required-by: 
---
Name: botocore
Version: 1.17.43
Summary: Low-level, data-driven core of boto 3.
Home-page: https://github.com/boto/botocore
Author: Amazon Web Services
Author-email: UNKNOWN
License: Apache License 2.0
Location: /usr/local/lib/python3.9/site-packages
Requires: docutils, jmespath, python-dateutil, urllib3
Required-by: boto3, s3transfer

Configuration

$ ansible-config dump --only-changed

OS / Environment

macos

Steps to Reproduce

  - community.aws.route53:
      state: get
      aws_access_key: "{{ aws_access_key_id }}"
      aws_secret_key: "{{ aws_secret_access_key }}"
      zone: "{{ aws_dns_zone_root }}"
      record: "{{ guid }}.{{ aws_dns_zone_root }}"
      type: A

Expected Results

a list of A records

Actual Results

The full traceback is:
Traceback (most recent call last):
  File "/Users/tiger/.ansible/tmp/ansible-tmp-1636685275.349921-33905-179073351027125/AnsiballZ_route53.py", line 100, in <module>
    _ansiballz_main()
  File "/Users/tiger/.ansible/tmp/ansible-tmp-1636685275.349921-33905-179073351027125/AnsiballZ_route53.py", line 92, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/Users/tiger/.ansible/tmp/ansible-tmp-1636685275.349921-33905-179073351027125/AnsiballZ_route53.py", line 40, in invoke_module
    runpy.run_module(mod_name='ansible_collections.community.aws.plugins.modules.route53', init_globals=dict(_module_fqn='ansible_collections.community.aws.plugins.modules.route53', _modlib_path=modlib_path),
  File "/usr/local/Cellar/python@3.9/3.9.7/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 210, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "/usr/local/Cellar/python@3.9/3.9.7/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 97, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/usr/local/Cellar/python@3.9/3.9.7/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/var/folders/62/wkysd_4n0w57ljl9ycfsd9cc0000gn/T/ansible_community.aws.route53_payload_h0zkygem/ansible_community.aws.route53_payload.zip/ansible_collections/community/aws/plugins/modules/route53.py", line 698, in <module>
  File "/var/folders/62/wkysd_4n0w57ljl9ycfsd9cc0000gn/T/ansible_community.aws.route53_payload_h0zkygem/ansible_community.aws.route53_payload.zip/ansible_collections/community/aws/plugins/modules/route53.py", line 636, in main
  File "/var/folders/62/wkysd_4n0w57ljl9ycfsd9cc0000gn/T/ansible_community.aws.route53_payload_h0zkygem/ansible_community.aws.route53_payload.zip/ansible/module_utils/common/dict_transformations.py", line 42, in camel_dict_to_snake_dict
AttributeError: 'NoneType' object has no attribute 'items'
fatal: [localhost]: FAILED! => {
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\n  File \"/Users/tiger/.ansible/tmp/ansible-tmp-1636685275.349921-33905-179073351027125/AnsiballZ_route53.py\", line 100, in <module>\n    _ansiballz_main()\n  File \"/Users/tiger/.ansible/tmp/ansible-tmp-1636685275.349921-33905-179073351027125/AnsiballZ_route53.py\", line 92, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/Users/tiger/.ansible/tmp/ansible-tmp-1636685275.349921-33905-179073351027125/AnsiballZ_route53.py\", line 40, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.community.aws.plugins.modules.route53', init_globals=dict(_module_fqn='ansible_collections.community.aws.plugins.modules.route53', _modlib_path=modlib_path),\n  File \"/usr/local/Cellar/python@3.9/3.9.7/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py\", line 210, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/local/Cellar/python@3.9/3.9.7/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py\", line 97, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/usr/local/Cellar/python@3.9/3.9.7/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py\", line 87, in _run_code\n    exec(code, run_globals)\n  File \"/var/folders/62/wkysd_4n0w57ljl9ycfsd9cc0000gn/T/ansible_community.aws.route53_payload_h0zkygem/ansible_community.aws.route53_payload.zip/ansible_collections/community/aws/plugins/modules/route53.py\", line 698, in <module>\n  File \"/var/folders/62/wkysd_4n0w57ljl9ycfsd9cc0000gn/T/ansible_community.aws.route53_payload_h0zkygem/ansible_community.aws.route53_payload.zip/ansible_collections/community/aws/plugins/modules/route53.py\", line 636, in main\n  File \"/var/folders/62/wkysd_4n0w57ljl9ycfsd9cc0000gn/T/ansible_community.aws.route53_payload_h0zkygem/ansible_community.aws.route53_payload.zip/ansible/module_utils/common/dict_transformations.py\", line 42, in camel_dict_to_snake_dict\nAttributeError: 'NoneType' object has no attribute 'items'\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}

Code of Conduct

markuman commented 2 years ago

I can confirm the error with both, current release and upcomming release.
But it happens only if the record does not exist.

ansible-galaxy collection list |grep community.aws
community.aws                 1.5.0  
community.aws         2.1.0-dev
---
- hosts: localhost
  connection: local

  tasks:
    - community.aws.route53:
        state: get
        zone: xn--mitlinuxwrdasnichtpassiert-ohc.de
        record: mussmanwissen.xn--mitlinuxwrdasnichtpassiert-ohc.de.
        type: A
      register: test

    - debug:
        var: test

output

PLAY [localhost] ********************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] **************************************************************************************************************************************************************************************************************
ok: [localhost]

TASK [community.aws.route53] ********************************************************************************************************************************************************************************************************
ok: [localhost]

TASK [debug] ************************************************************************************************************************************************************************************************************************
ok: [localhost] => {
    "test": {
        "changed": false,
        "failed": false,
        "nameservers": [
            "ns-108.awsdns-13.com.",
            "ns-1264.awsdns-30.org.",
            "ns-737.awsdns-28.net.",
            "ns-1554.awsdns-02.co.uk."
        ],
        "resource_record_sets": [
            {
                "name": "mussmanwissen.xn--mitlinuxwrdasnichtpassiert-ohc.de.",
                "resource_records": [
                    {
                        "value": "127.0.0.1"
                    }
                ],
                "ttl": 60,
                "type": "A"
            }
        ],
        "set": {
            "Name": "mussmanwissen.xn--mitlinuxwrdasnichtpassiert-ohc.de.",
            "ResourceRecords": [
                {
                    "Value": "127.0.0.1"
                }
            ],
            "TTL": 60,
            "Type": "A",
            "alias": false,
            "failover": null,
            "health_check": null,
            "hosted_zone_id": "Z09919173I6GJAOQAMTMA",
            "identifier": null,
            "record": "mussmanwissen.xn--mitlinuxwrdasnichtpassiert-ohc.de.",
            "region": null,
            "ttl": "60",
            "type": "A",
            "value": "127.0.0.1",
            "values": [
                "127.0.0.1"
            ],
            "weight": null,
            "zone": "xn--mitlinuxwrdasnichtpassiert-ohc.de."
        }
    }
}

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

When the record does not exists

---
- hosts: localhost
  connection: local

  tasks:
    - community.aws.route53:
        state: get
        zone: xn--mitlinuxwrdasnichtpassiert-ohc.de
        record: doesnotexist.xn--mitlinuxwrdasnichtpassiert-ohc.de.
        type: A
      register: test

    - debug:
        var: test

I'll receive the same error

TASK [community.aws.route53] ********************************************************************************************************************************************************************************************************
task path: /home/m/git/lekker/iac/798.yml:6
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: m
<127.0.0.1> EXEC /bin/sh -c 'echo ~m && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/m/.ansible/tmp `"&& mkdir "` echo /home/m/.ansible/tmp/ansible-tmp-1636703337.6553104-21549-57181038135765 `" && echo ansible-tmp-1636703337.6553104-21549-57181038135765="` echo /home/m/.ansible/tmp/ansible-tmp-1636703337.6553104-21549-57181038135765 `" ) && sleep 0'
Using module file /home/m/.local/lib/python3.9/site-packages/ansible_collections/community/aws/plugins/modules/route53.py
<127.0.0.1> PUT /home/m/.ansible/tmp/ansible-local-21466oog6jc4o/tmpeo_xv0k3 TO /home/m/.ansible/tmp/ansible-tmp-1636703337.6553104-21549-57181038135765/AnsiballZ_route53.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/m/.ansible/tmp/ansible-tmp-1636703337.6553104-21549-57181038135765/ /home/m/.ansible/tmp/ansible-tmp-1636703337.6553104-21549-57181038135765/AnsiballZ_route53.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python /home/m/.ansible/tmp/ansible-tmp-1636703337.6553104-21549-57181038135765/AnsiballZ_route53.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/m/.ansible/tmp/ansible-tmp-1636703337.6553104-21549-57181038135765/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
  File "/home/m/.ansible/tmp/ansible-tmp-1636703337.6553104-21549-57181038135765/AnsiballZ_route53.py", line 100, in <module>
    _ansiballz_main()
  File "/home/m/.ansible/tmp/ansible-tmp-1636703337.6553104-21549-57181038135765/AnsiballZ_route53.py", line 92, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/home/m/.ansible/tmp/ansible-tmp-1636703337.6553104-21549-57181038135765/AnsiballZ_route53.py", line 40, in invoke_module
    runpy.run_module(mod_name='ansible_collections.community.aws.plugins.modules.route53', init_globals=dict(_module_fqn='ansible_collections.community.aws.plugins.modules.route53', _modlib_path=modlib_path),
  File "/usr/lib/python3.9/runpy.py", line 210, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "/usr/lib/python3.9/runpy.py", line 97, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/usr/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/tmp/ansible_community.aws.route53_payload_aekaeeo1/ansible_community.aws.route53_payload.zip/ansible_collections/community/aws/plugins/modules/route53.py", line 698, in <module>
  File "/tmp/ansible_community.aws.route53_payload_aekaeeo1/ansible_community.aws.route53_payload.zip/ansible_collections/community/aws/plugins/modules/route53.py", line 636, in main
  File "/tmp/ansible_community.aws.route53_payload_aekaeeo1/ansible_community.aws.route53_payload.zip/ansible/module_utils/common/dict_transformations.py", line 42, in camel_dict_to_snake_dict
AttributeError: 'NoneType' object has no attribute 'items'
fatal: [localhost]: FAILED! => {
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\n  File \"/home/m/.ansible/tmp/ansible-tmp-1636703337.6553104-21549-57181038135765/AnsiballZ_route53.py\", line 100, in <module>\n    _ansiballz_main()\n  File \"/home/m/.ansible/tmp/ansible-tmp-1636703337.6553104-21549-57181038135765/AnsiballZ_route53.py\", line 92, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/m/.ansible/tmp/ansible-tmp-1636703337.6553104-21549-57181038135765/AnsiballZ_route53.py\", line 40, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.community.aws.plugins.modules.route53', init_globals=dict(_module_fqn='ansible_collections.community.aws.plugins.modules.route53', _modlib_path=modlib_path),\n  File \"/usr/lib/python3.9/runpy.py\", line 210, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib/python3.9/runpy.py\", line 97, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/usr/lib/python3.9/runpy.py\", line 87, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_community.aws.route53_payload_aekaeeo1/ansible_community.aws.route53_payload.zip/ansible_collections/community/aws/plugins/modules/route53.py\", line 698, in <module>\n  File \"/tmp/ansible_community.aws.route53_payload_aekaeeo1/ansible_community.aws.route53_payload.zip/ansible_collections/community/aws/plugins/modules/route53.py\", line 636, in main\n  File \"/tmp/ansible_community.aws.route53_payload_aekaeeo1/ansible_community.aws.route53_payload.zip/ansible/module_utils/common/dict_transformations.py\", line 42, in camel_dict_to_snake_dict\nAttributeError: 'NoneType' object has no attribute 'items'\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}

So in case the record does not exist, it should return an empty resource_record_sets: [] and also an emty set: []