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.py fails with - NameError: name 'botocore' is not defined - on devel #17555

Closed
xenithorb opened this Issue Sep 13, 2016 · 8 comments

Comments

Projects
None yet
7 participants
@xenithorb

xenithorb commented Sep 13, 2016

ISSUE TYPE
  • Bug Report
COMPONENT NAME

ec2.py

ANSIBLE VERSION
ansible 2.2.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides

Hash: da4c3eb

CONFIGURATION
OS / ENVIRONMENT

Fedora 24
Python 2.7.12 clean virtualenv

SUMMARY

ec2.py : https://raw.github.com/ansible/ansible/devel/contrib/inventory/ec2.py

Used to only require boto, but fails now with:

Traceback (most recent call last):
  File "./ec2.py", line 134, in <module>
    from ansible.module_utils import ec2 as ec2_utils
  File "/home/xenith/virtualenvs/ansible/lib/python2.7/site-packages/ansible/module_utils/ec2.py", line 61, in <module>
    class AWSRetry(CloudRetry):
  File "/home/xenith/virtualenvs/ansible/lib/python2.7/site-packages/ansible/module_utils/ec2.py", line 62, in AWSRetry
    base_class = botocore.exceptions.ClientError
NameError: name 'botocore' is not defined

Which I believe is a bug because it doesn't really tell the user what's wrong. Especially because this only happens if the user is testing devel branch. It works without error (and with the previous version of boto) with ansible 2.1.1

Additionally, if the user removes boto and only installs boto3 - it still fails:

Traceback (most recent call last):
  File "./ec2.py", line 127, in <module>
    import boto
ImportError: No module named boto

If the user installs both boto AND boto3 it works fine.

What I find strange about this is that the script fails based on the version of ansible.

STEPS TO REPRODUCE
virtualenv ansible
. ./ansible/bin/activate
pip install ansible boto
wget https://raw.githubusercontent.com/ansible/ansible/devel/contrib/inventory/ec2.ini 
wget https://raw.github.com/ansible/ansible/devel/contrib/inventory/ec2.py
python ec2.py

OR

virtualenv ansible
. ./ansible/bin/activate
# pip install ansible boto boto3 works!
pip install ansible boto3
wget https://raw.githubusercontent.com/ansible/ansible/devel/contrib/inventory/ec2.ini 
wget https://raw.github.com/ansible/ansible/devel/contrib/inventory/ec2.py
python ec2.py
EXPECTED RESULTS

ec2.py should announce that either:

  1. It needs boto3 to function properly (which it currently does) OR
  2. Fail back to actually using boto (not boto3) when it's not available
@Lujeni

This comment has been minimized.

Show comment
Hide comment
@Lujeni

Lujeni Apr 18, 2017

Contributor

Hello @xenithorb (@s-hertel ),

Can you check with the devel version pls?

It's seems the bug is fixed now.
The file module_utils/ec2.py check the boto3 presence.

Contributor

Lujeni commented Apr 18, 2017

Hello @xenithorb (@s-hertel ),

Can you check with the devel version pls?

It's seems the bug is fixed now.
The file module_utils/ec2.py check the boto3 presence.

@xenithorb

This comment has been minimized.

Show comment
Hide comment
@xenithorb

xenithorb Apr 18, 2017

It would appear that two working states are available now:

  1. With boto and without boto3 (fixed)
  2. With boto and with boto3 (original working condition)
  3. Without boto and without boto3 fails by still looking for boto, but I suspect that is intentional.

If those are the desired states then I would consider this fixed!

xenithorb commented Apr 18, 2017

It would appear that two working states are available now:

  1. With boto and without boto3 (fixed)
  2. With boto and with boto3 (original working condition)
  3. Without boto and without boto3 fails by still looking for boto, but I suspect that is intentional.

If those are the desired states then I would consider this fixed!

@ryansb

This comment has been minimized.

Show comment
Hide comment
@ryansb

ryansb Apr 19, 2017

Member

Yup, this is correct in current devel as well as the released 2.3

Member

ryansb commented Apr 19, 2017

Yup, this is correct in current devel as well as the released 2.3

@ryansb ryansb closed this Apr 19, 2017

@jimsmith

This comment has been minimized.

Show comment
Hide comment
@jimsmith

jimsmith Feb 8, 2018

@xenithorb if I read you msg correctly ec2.py now works with boto and boto3 ? as it's not working for me and my setup is standard nothing but does it work with Python 3.6.3 ?

./ec2.py --list
Traceback (most recent call last):
  File "./ec2.py", line 155, in <module>
    import boto
ModuleNotFoundError: No module named 'boto'
python --version
Python 3.6.3 :: Anaconda, Inc.
 python3.6
Python 3.6.3 |Anaconda, Inc.| (default, Oct 13 2017, 12:02:49)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import boto
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'boto'
>>> quit()
/usr/bin/python2.7
Python 2.7.5 (default, Aug  4 2017, 00:39:18)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import boto
>>> quit;

Both boto are installed for both versions of python:
/usr/lib/python2.7/site-packages/boto/
/usr/lib/python3.6/site-packages/boto/

jimsmith commented Feb 8, 2018

@xenithorb if I read you msg correctly ec2.py now works with boto and boto3 ? as it's not working for me and my setup is standard nothing but does it work with Python 3.6.3 ?

./ec2.py --list
Traceback (most recent call last):
  File "./ec2.py", line 155, in <module>
    import boto
ModuleNotFoundError: No module named 'boto'
python --version
Python 3.6.3 :: Anaconda, Inc.
 python3.6
Python 3.6.3 |Anaconda, Inc.| (default, Oct 13 2017, 12:02:49)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import boto
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'boto'
>>> quit()
/usr/bin/python2.7
Python 2.7.5 (default, Aug  4 2017, 00:39:18)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import boto
>>> quit;

Both boto are installed for both versions of python:
/usr/lib/python2.7/site-packages/boto/
/usr/lib/python3.6/site-packages/boto/

@xenithorb

This comment has been minimized.

Show comment
Hide comment
@xenithorb

xenithorb Feb 8, 2018

boto and boto3 are separate packages, its not meant to imply "python 3 boto," but I suspect a lot of people mistake that.

xenithorb commented Feb 8, 2018

boto and boto3 are separate packages, its not meant to imply "python 3 boto," but I suspect a lot of people mistake that.

@ryansb

This comment has been minimized.

Show comment
Hide comment
@ryansb

ryansb Feb 8, 2018

Member

Yup - boto is the original package for the Python SDK, and boto3 is a rewrite (using botocore under the hood) of the same SDK. They have different APIs, so instead of publishing the breaking changes to the boto package, they published a coinstallable "boto3".

Member

ryansb commented Feb 8, 2018

Yup - boto is the original package for the Python SDK, and boto3 is a rewrite (using botocore under the hood) of the same SDK. They have different APIs, so instead of publishing the breaking changes to the boto package, they published a coinstallable "boto3".

@jimsmith

This comment has been minimized.

Show comment
Hide comment
@jimsmith

jimsmith Feb 9, 2018

I would expect as a user of ec2.py for dynamic EC2 inventory for this to work with python3, does it ?
because reading this issue it implies it does, but the code doesn't but does have boto3 in the code as well..

If there is something incorrect with the setup I have let me know, as I've always used ec2.py with python2.7 and boto but since boto3 works with python3.6 it makes sense for these to both co-exist on the ansible control machine in harmony.

As I'd rather not do virtualenv or miniconda environments and take it off our RHEL/CentOS yum standard package install/upgrade path.

jimsmith commented Feb 9, 2018

I would expect as a user of ec2.py for dynamic EC2 inventory for this to work with python3, does it ?
because reading this issue it implies it does, but the code doesn't but does have boto3 in the code as well..

If there is something incorrect with the setup I have let me know, as I've always used ec2.py with python2.7 and boto but since boto3 works with python3.6 it makes sense for these to both co-exist on the ansible control machine in harmony.

As I'd rather not do virtualenv or miniconda environments and take it off our RHEL/CentOS yum standard package install/upgrade path.

@ryansb

This comment has been minimized.

Show comment
Hide comment
@ryansb

ryansb Feb 9, 2018

Member

boto3 and python3 are unrelated - you should be able to safely use boto3 on python 2 or python 3. If that does not work, please open a separate issue and we can move discussion there.

Member

ryansb commented Feb 9, 2018

boto3 and python3 are unrelated - you should be able to safely use boto3 on python 2 or python 3. If that does not work, please open a separate issue and we can move discussion there.

@ansibot ansibot added bug and removed bug_report labels Mar 7, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment