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

ec2_metadata_facts returns "AttributeError: 'int' object has no attribute 'items'" #1134

Closed
1 task done
isuftin opened this issue Oct 6, 2022 · 7 comments · Fixed by #1138
Closed
1 task done

ec2_metadata_facts returns "AttributeError: 'int' object has no attribute 'items'" #1134

isuftin opened this issue Oct 6, 2022 · 7 comments · Fixed by #1138
Labels
bug This issue/PR relates to a bug has_pr module module plugins plugin (any type) python3 traceback

Comments

@isuftin
Copy link

isuftin commented Oct 6, 2022

Summary

When calling amazon.aws.ec2_metadata_facts against a remote RHEL 8 instance, I get the error AttributeError: 'int' object has no attribute 'items'

Issue Type

Bug Report

Component Name

ec2_metadata_facts

Ansible Version

ansible [core 2.13.4]
  config file = None
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.9.14 (main, Sep 22 2022, 14:32:21) [GCC 11.2.1 20220219]
  jinja version = 3.1.2
  libyaml = False

Collection Versions

$ ansible-galaxy collection list

Collection    Version
------------- -------
amazon.aws    5.0.1  
ansible.posix 1.4.0  

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: [email protected]
License: MIT
Location: /usr/local/lib/python3.9/site-packages
Requires:
Required-by:
---
Name: boto3
Version: 1.24.88
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.27.88
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
ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True

OS / Environment

Target OS: RHEL 8 EC2 instance

Steps to Reproduce

This is being run as part of an overall molecule playbook. I'm not sure the best way to get a decent reproduction case here.

- hosts: all
  tasks:
    - name: Test
      amazon.aws.ec2_metadata_facts:

Expected Results

No error

Actual Results

fatal: [aws-ctek-rhel8-ec2-rundeck-5]: FAILED! => changed=false 
  module_stderr: |-
    OpenSSH_9.0p1, OpenSSL 1.1.1q  5 Jul 2022
    debug1: Reading configuration data /etc/ssh/ssh_config
    debug2: resolve_canonicalize: hostname internal.aws.ip is address
    debug1: auto-mux: Trying existing master
    debug2: fd 3 setting O_NONBLOCK
    debug2: mux_client_hello_exchange: master version 4
    debug3: mux_client_forwards: request forwardings: 0 local, 0 remote
    debug3: mux_client_request_session: entering
    debug3: mux_client_request_alive: entering
    debug3: mux_client_request_alive: done pid = 319
    debug3: mux_client_request_session: session request sent
    debug1: mux_client_request_session: master session id: 2
    /tmp/ansible_amazon.aws.ec2_metadata_facts_payload_ydfpudq4/ansible_amazon.aws.ec2_metadata_facts_payload.zip/ansible/module_utils/urls.py:176: CryptographyDeprecationWarning: Python 3.6 is no longer supported by the Python core team. Therefore, support for it is deprecated in cryptography and will be removed in a future release.
    Traceback (most recent call last):
      File "<stdin>", line 107, in <module>
      File "<stdin>", line 99, in _ansiballz_main
      File "<stdin>", line 48, in invoke_module
      File "/usr/lib64/python3.6/runpy.py", line 205, in run_module
        return _run_module_code(code, init_globals, run_name, mod_spec)
      File "/usr/lib64/python3.6/runpy.py", line 96, in _run_module_code
        mod_name, mod_spec, pkg_name, script_name)
      File "/usr/lib64/python3.6/runpy.py", line 85, in _run_code
        exec(code, run_globals)
      File "/tmp/ansible_amazon.aws.ec2_metadata_facts_payload_ydfpudq4/ansible_amazon.aws.ec2_metadata_facts_payload.zip/ansible_collections/amazon/aws/plugins/modules/ec2_metadata_facts.py", line 598, in <module>
      File "/tmp/ansible_amazon.aws.ec2_metadata_facts_payload_ydfpudq4/ansible_amazon.aws.ec2_metadata_facts_payload.zip/ansible_collections/amazon/aws/plugins/modules/ec2_metadata_facts.py", line 591, in main
      File "/tmp/ansible_amazon.aws.ec2_metadata_facts_payload_ydfpudq4/ansible_amazon.aws.ec2_metadata_facts_payload.zip/ansible_collections/amazon/aws/plugins/modules/ec2_metadata_facts.py", line 568, in run
      File "/tmp/ansible_amazon.aws.ec2_metadata_facts_payload_ydfpudq4/ansible_amazon.aws.ec2_metadata_facts_payload.zip/ansible_collections/amazon/aws/plugins/modules/ec2_metadata_facts.py", line 529, in fetch
    AttributeError: 'int' object has no attribute 'items'
    debug3: mux_client_read_packet: read header failed: Broken pipe
    debug2: Received exit status from master 1
  module_stdout: ''
  msg: |-
    MODULE FAILURE
    See stdout/stderr for the exact error
  rc: 1

Code of Conduct

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

isuftin commented Oct 6, 2022

The last time this ran properly was using 4.1.0 and I will re-try that

@ansibullbot
Copy link

@ansibullbot ansibullbot added bug This issue/PR relates to a bug module module needs_triage plugins plugin (any type) python3 traceback labels Oct 6, 2022
@isuftin
Copy link
Author

isuftin commented Oct 7, 2022

Versions up to 4.3.0 work as expected. 5.0.0 breaks as above.

@bakerbean
Copy link

This took out some of our cloud automation, can also confirm that specifying version 4.x gets everything working again.

ansible-galaxy collection install 'amazon.aws:>4.0.0,<5.0.0'

@tremble
Copy link
Contributor

tremble commented Oct 7, 2022

Hi, if possible please could you try #1138 and see if that fixes the issue. Unfortunately our integration tests for ec2_metadata_facts are apparently not running at all, so we didn't catch the issue.

@isuftin
Copy link
Author

isuftin commented Oct 7, 2022

@tremble - Yes, making that change does fix the issue

softwarefactory-project-zuul bot pushed a commit that referenced this issue Oct 8, 2022
Fix AttributeError when running ec2_metadata_facts

SUMMARY
Prior to 5.0.0 we caught "Exception" within fetch, this was limited to json.JSONDecodeError, however it looks like we also needed to catch AttributeError for non-dict JSON
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
ec2_metadata_facts
ADDITIONAL INFORMATION
fixes: #1134
patchback bot pushed a commit that referenced this issue Oct 10, 2022
Fix AttributeError when running ec2_metadata_facts

SUMMARY
Prior to 5.0.0 we caught "Exception" within fetch, this was limited to json.JSONDecodeError, however it looks like we also needed to catch AttributeError for non-dict JSON
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
ec2_metadata_facts
ADDITIONAL INFORMATION
fixes: #1134

(cherry picked from commit c269898)
softwarefactory-project-zuul bot pushed a commit that referenced this issue Oct 10, 2022
[PR #1138/c269898a backport][stable-5] Fix AttributeError when running ec2_metadata_facts

This is a backport of PR #1138 as merged into main (c269898).
SUMMARY
Prior to 5.0.0 we caught "Exception" within fetch, this was limited to json.JSONDecodeError, however it looks like we also needed to catch AttributeError for non-dict JSON
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
ec2_metadata_facts
ADDITIONAL INFORMATION
fixes: #1134

Reviewed-by: Mark Chappell <None>
softwarefactory-project-zuul bot pushed a commit that referenced this issue Oct 10, 2022
Prepare 5.0.2 release

SUMMARY
#1134 is kinda nasty, prepare 5.0.2 so we can get the fix out there.
ISSUE TYPE

Docs Pull Request

COMPONENT NAME
galaxy.yml
ADDITIONAL INFORMATION

Reviewed-by: Alina Buzachis <None>
@tremble
Copy link
Contributor

tremble commented Oct 10, 2022

5.0.2 has been released and it believed to resolve this issue.

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 has_pr module module plugins plugin (any type) python3 traceback
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants