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

Exception in ec2_vol when ec2 instance doesn't supply 'platform' #305

Closed
jdoxey opened this issue Mar 14, 2021 · 4 comments · Fixed by #306
Closed

Exception in ec2_vol when ec2 instance doesn't supply 'platform' #305

jdoxey opened this issue Mar 14, 2021 · 4 comments · Fixed by #306
Labels

Comments

@jdoxey
Copy link

jdoxey commented Mar 14, 2021

SUMMARY

I'm seeing an exception when using amazon.aws.ec2_vol to attach an existing EBS volume to a running Debian 10 EC2 instance.

At line 753 of ec2_vol.py, the code is expecting the inst object to contain a key called platform, which it's not finding. I dumped the value of inst and confirmed that the platform key was absent.

I noticed a workaround was to set the device_name manually in the playbook, e.g.,

    - name: Attach existing EBS data volume
      amazon.aws.ec2_vol:
        instance: i-XXXXXXXXXXXX
        id: "{{ ec2_data_volume_id }}"
        delete_on_termination: no
        region: ap-southeast-2
        device_name: /dev/sdf    # ...or /dev/xvdf for Windows
ISSUE TYPE
  • Bug Report
COMPONENT NAME

amazon.aws.ec2_vol

ANSIBLE VERSION
ansible 2.9.18
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/jdoxey/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.9/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.9.2 (default, Feb 20 2021, 00:00:00) [GCC 10.2.1 20201125 (Red Hat 10.2.1-9)]
CONFIGURATION

(empty)

OS / ENVIRONMENT

Host is Fedora 33 x86_64 with kernel 5.10.22-200 running on a 2011 MacBook Pro

The version of this galaxy collection I'm using is 1.4.1. I also tried with the HEAD of develop branch today and saw the same result.

boto details,

[jdoxey@xfce-fedora-macbook ansible]$ pip show boto
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: /home/jdoxey/.local/lib/python3.9/site-packages
Requires: 
Required-by: 

boto3 details,

[jdoxey@xfce-fedora-macbook ansible]$ pip show boto3
Name: boto3
Version: 1.17.27
Summary: The AWS SDK for Python
Home-page: https://github.com/boto/boto3
Author: Amazon Web Services
Author-email: None
License: Apache License 2.0
Location: /home/jdoxey/.local/lib/python3.9/site-packages
Requires: jmespath, botocore, s3transfer
Required-by: 
STEPS TO REPRODUCE

Inventory file,

[local]
localhost

[local:vars]
ec2_data_volume_id=vol-XXXXXXXXXXX

Playbook,

- name: Start EC2 instance
  hosts: local
  connection: local
  gather_facts: false
  tasks:
    - name: Attach existing EBS data volume
      amazon.aws.ec2_vol:
        instance: i-XXXXXXXXXX # debian 10 instance (ami-0cfdf1001961b06f5)
        id: "{{ ec2_data_volume_id }}"
        delete_on_termination: no
        region: ap-southeast-2

AWS_ACCESS_KEY and AWS_SECRET_KEY are set as environment variables.

EXPECTED RESULTS

Should see,

TASK [Attach existing EBS data volume] **************************************************************************************************
changed: [localhost]
ACTUAL RESULTS
[jdoxey@xfce-fedora-macbook ansible]$ ansible-playbook -vvv -i inventory playbook.yaml 
ansible-playbook 2.9.18
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/jdoxey/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.9/site-packages/ansible
  executable location = /usr/bin/ansible-playbook
  python version = 3.9.2 (default, Feb 20 2021, 00:00:00) [GCC 10.2.1 20201125 (Red Hat 10.2.1-9)]
Using /etc/ansible/ansible.cfg as config file
host_list declined parsing /home/jdoxey/Development/ansible/inventory as it did not pass its verify_file() method
script declined parsing /home/jdoxey/Development/ansible/inventory as it did not pass its verify_file() method
auto declined parsing /home/jdoxey/Development/ansible/inventory as it did not pass its verify_file() method
Parsed /home/jdoxey/Development/ansible/inventory inventory source with ini plugin
Skipping callback 'actionable', as we already have a stdout callback.
Skipping callback 'counter_enabled', as we already have a stdout callback.
Skipping callback 'debug', as we already have a stdout callback.
Skipping callback 'dense', as we already have a stdout callback.
Skipping callback 'dense', as we already have a stdout callback.
Skipping callback 'full_skip', as we already have a stdout callback.
Skipping callback 'json', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'null', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
Skipping callback 'selective', as we already have a stdout callback.
Skipping callback 'skippy', as we already have a stdout callback.
Skipping callback 'stderr', as we already have a stdout callback.
Skipping callback 'unixy', as we already have a stdout callback.
Skipping callback 'yaml', as we already have a stdout callback.

PLAYBOOK: playbook.yaml *****************************************************************************************************************
1 plays in playbook.yaml

PLAY [Start EC2 instance] ***************************************************************************************************************
META: ran handlers

TASK [Attach existing EBS data volume] **************************************************************************************************
task path: /home/jdoxey/Development/ansible/playbook.yaml:6
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: jdoxey
<localhost> EXEC /bin/sh -c 'echo ~jdoxey && sleep 0'
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/jdoxey/.ansible/tmp `"&& mkdir "` echo /home/jdoxey/.ansible/tmp/ansible-tmp-1615724188.4038346-6228-62369506050208 `" && echo ansible-tmp-1615724188.4038346-6228-62369506050208="` echo /home/jdoxey/.ansible/tmp/ansible-tmp-1615724188.4038346-6228-62369506050208 `" ) && sleep 0'
<localhost> Attempting python interpreter discovery
<localhost> EXEC /bin/sh -c 'echo PLATFORM; uname; echo FOUND; command -v '"'"'/usr/bin/python'"'"'; command -v '"'"'python3.7'"'"'; command -v '"'"'python3.6'"'"'; command -v '"'"'python3.5'"'"'; command -v '"'"'python2.7'"'"'; command -v '"'"'python2.6'"'"'; command -v '"'"'/usr/libexec/platform-python'"'"'; command -v '"'"'/usr/bin/python3'"'"'; command -v '"'"'python'"'"'; echo ENDFOUND && sleep 0'
<localhost> EXEC /bin/sh -c '/usr/bin/python && sleep 0'
Using module file /home/jdoxey/.ansible/collections/ansible_collections/amazon/aws/plugins/modules/ec2_vol.py
<localhost> PUT /home/jdoxey/.ansible/tmp/ansible-local-6225_18okefz/tmpg3ryy5a1 TO /home/jdoxey/.ansible/tmp/ansible-tmp-1615724188.4038346-6228-62369506050208/AnsiballZ_ec2_vol.py
<localhost> EXEC /bin/sh -c 'chmod u+x /home/jdoxey/.ansible/tmp/ansible-tmp-1615724188.4038346-6228-62369506050208/ /home/jdoxey/.ansible/tmp/ansible-tmp-1615724188.4038346-6228-62369506050208/AnsiballZ_ec2_vol.py && sleep 0'
<localhost> EXEC /bin/sh -c '/usr/bin/python /home/jdoxey/.ansible/tmp/ansible-tmp-1615724188.4038346-6228-62369506050208/AnsiballZ_ec2_vol.py && sleep 0'
<localhost> EXEC /bin/sh -c 'rm -f -r /home/jdoxey/.ansible/tmp/ansible-tmp-1615724188.4038346-6228-62369506050208/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
  File "/home/jdoxey/.ansible/tmp/ansible-tmp-1615724188.4038346-6228-62369506050208/AnsiballZ_ec2_vol.py", line 102, in <module>
    _ansiballz_main()
  File "/home/jdoxey/.ansible/tmp/ansible-tmp-1615724188.4038346-6228-62369506050208/AnsiballZ_ec2_vol.py", line 94, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/home/jdoxey/.ansible/tmp/ansible-tmp-1615724188.4038346-6228-62369506050208/AnsiballZ_ec2_vol.py", line 40, in invoke_module
    runpy.run_module(mod_name='ansible_collections.amazon.aws.plugins.modules.ec2_vol', init_globals=None, run_name='__main__', alter_sys=True)
  File "/usr/lib64/python3.9/runpy.py", line 210, 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_vol_payload_fdn35jhc/ansible_amazon.aws.ec2_vol_payload.zip/ansible_collections/amazon/aws/plugins/modules/ec2_vol.py", line 809, in <module>
  File "/tmp/ansible_amazon.aws.ec2_vol_payload_fdn35jhc/ansible_amazon.aws.ec2_vol_payload.zip/ansible_collections/amazon/aws/plugins/modules/ec2_vol.py", line 753, in main
KeyError: 'platform'
[DEPRECATION WARNING]: Distribution fedora 33 on host localhost should use /usr/bin/python3, but is using /usr/bin/python for backward 
compatibility with prior Ansible releases. A future Ansible release will default to using the discovered platform python for this host. 
See https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information. This feature will be 
removed in version 2.12. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
fatal: [localhost]: FAILED! => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\n  File \"/home/jdoxey/.ansible/tmp/ansible-tmp-1615724188.4038346-6228-62369506050208/AnsiballZ_ec2_vol.py\", line 102, in <module>\n    _ansiballz_main()\n  File \"/home/jdoxey/.ansible/tmp/ansible-tmp-1615724188.4038346-6228-62369506050208/AnsiballZ_ec2_vol.py\", line 94, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/jdoxey/.ansible/tmp/ansible-tmp-1615724188.4038346-6228-62369506050208/AnsiballZ_ec2_vol.py\", line 40, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.amazon.aws.plugins.modules.ec2_vol', init_globals=None, run_name='__main__', alter_sys=True)\n  File \"/usr/lib64/python3.9/runpy.py\", line 210, 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_vol_payload_fdn35jhc/ansible_amazon.aws.ec2_vol_payload.zip/ansible_collections/amazon/aws/plugins/modules/ec2_vol.py\", line 809, in <module>\n  File \"/tmp/ansible_amazon.aws.ec2_vol_payload_fdn35jhc/ansible_amazon.aws.ec2_vol_payload.zip/ansible_collections/amazon/aws/plugins/modules/ec2_vol.py\", line 753, in main\nKeyError: 'platform'\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   
@ansibullbot
Copy link

Files identified in the description:
None

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 ansibullbot added bug This issue/PR relates to a bug needs_triage python3 traceback labels Mar 14, 2021
@tremble
Copy link
Contributor

tremble commented Mar 14, 2021

!component ec2_vol

@tremble
Copy link
Contributor

tremble commented Mar 14, 2021

Hi @jdoxey

Thanks for taking the time to report this issue.

I've been able to verify that the debian images don't return the platform information. Please could you try the fix in #306

@jdoxey
Copy link
Author

jdoxey commented Mar 15, 2021

I can confirm that #306 fixes the issue when I apply it locally. Thank you for your prompt response.

abikouo pushed a commit to abikouo/amazon.aws that referenced this issue Sep 18, 2023
…ctions#305)

* Added Tier as option
* * added better description
* added changelong

Co-authored-by: Markus Bergholz <[email protected]>
Co-authored-by: Mark Chappell <[email protected]>
abikouo pushed a commit to abikouo/amazon.aws that referenced this issue Sep 18, 2023
…ctions#305)

* Added Tier as option
* * added better description
* added changelong

Co-authored-by: Markus Bergholz <[email protected]>
Co-authored-by: Mark Chappell <[email protected]>
abikouo pushed a commit to abikouo/amazon.aws that referenced this issue Oct 24, 2023
…ctions#305)

* Added Tier as option
* * added better description
* added changelong

Co-authored-by: Markus Bergholz <[email protected]>
Co-authored-by: Mark Chappell <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants