Dynamic Inventory: ec2.py
ansible 2.1.0.0
Python 2.7.10
Mac OS X 10.11.6
Running ec2.py standalone causes import error.
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
A list of instances
Error above.
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.
@jonatanblue that import was added by https://github.com/ansible/ansible/commit/59e499f8f00e4068b68c147b8f3002535ad706e0 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.
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.
Most helpful comment
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:
Now ansible is available:
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.