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

AWS dynamic inventory Python script fails to run #17147

Closed
jonatanblue opened this issue Aug 19, 2016 · 2 comments
Closed

AWS dynamic inventory Python script fails to run #17147

jonatanblue opened this issue Aug 19, 2016 · 2 comments
Labels
aws bug This issue/PR relates to a bug. cloud

Comments

@jonatanblue
Copy link

ISSUE TYPE
  • Bug Report
COMPONENT NAME

Dynamic Inventory: ec2.py

ANSIBLE VERSION
ansible 2.1.0.0
Python 2.7.10
OS / ENVIRONMENT

Mac OS X 10.11.6

SUMMARY

Running ec2.py standalone causes import error.

STEPS TO REPRODUCE
  1. Download the ec2.py dynamic inventory script and ec2.ini file as instructed in the docs.
  2. Run the script with Python 2.7
python ec2.py --list
Traceback (most recent call last):
  File "ec2.py", line 134, in <module>
    from ansible.module_utils import ec2 as ec2_utils
ImportError: No module named ansible.module_utils
EXPECTED RESULTS

A list of instances

ACTUAL RESULTS

Error above.

Workaround

If I comment out the line from ansible.module_utils import ec2 as ec2_utils the script runs fine.

The line was introduced in #16606.

@jctanner
Copy link
Contributor

@jonatanblue that import was added by 59e499f which appears to be an attempt to normalize the boto client setup code.

The implication is that in order to use the inventory script, you need to have ansible installed on the machine such that "ansible" is available in the python path for your default python interpreter. We plan to make more use of the ansible libraries in the dynamic inventory scripts over time, so I am not going to revert this change.

@jonatanblue
Copy link
Author

Great to hear it's not a bug. Is this described somewhere in the documentation?

I figured out what caused it at my end: installing Ansible with brew made ansible unavailable to my Python interpreter.

To fix this I uninstalled Ansible and installed it again using pip:

brew uninstall ansible
pip install ansible

Now ansible is available:

python -c "import ansible;print(ansible.__version__)"
2.1.1.0

and the script works as expected.

It may be worth mentioning this somewhere in the documentation, or have the script throw an informative error if ansible is not available in the python path.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
aws bug This issue/PR relates to a bug. cloud
Projects
None yet
Development

No branches or pull requests

3 participants