My current machine crashed and I have to setup ansible again on the new one using the same methodologies but It seems I am missing somethings. I need to use version 2.X for consistency reasons as we have not upgraded yet.
I heavily used ec2.py and ec2.ini so when I run
~ python /Users/joseph/infrastructure_as_code/ansible_projects/inventory/ec2.py
Traceback (most recent call last):
File "/Users/joseph/infrastructure_as_code/ansible_projects/inventory/ec2.py", line 172, in <module>
from ansible.module_utils import ec2 as ec2_utils
ImportError: cannot import name 'ec2' from 'ansible.module_utils' (/Users/joseph/.pyenv/versions/pypy3.8-7.3.7/lib/pypy3.8/site- packages/ansible/module_utils/__init__.py)
Here is my setup .Fresh MacBook Pro M1.
#Mac, no prior ansible installation either brew or pip
#Check Python version
➜ ~ python --version
Python 3.8.12 (9ef55f6fc369, Oct 25 2021, 05:10:01)
[PyPy 7.3.7 with GCC Apple LLVM 13.0.0 (clang-1300.0.29.3)]
#Check version used by shebang
➜ ~ /usr/bin/env python --version
Python 3.8.12 (9ef55f6fc369, Oct 25 2021, 05:10:01)
[PyPy 7.3.7 with GCC Apple LLVM 13.0.0 (clang-1300.0.29.3)]
## Check ansible version. Had to use version 2 for now. Installed with pip over python installed by peen
➜ ~ ansible --version
ansible 2.10.17
config file = /Users/joseph/.ansible.cfg
configured module search path = ['/Users/joseph/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /Users/joseph/.pyenv/versions/pypy3.8-7.3.7/lib/pypy3.8/site-packages/ansible
executable location = /Users/joseph/.pyenv/versions/pypy3.8-7.3.7/bin/ansible
python version = 3.8.12 (9ef55f6fc369, Oct 25 2021, 05:10:01)[PyPy 7.3.7 with GCC Apple LLVM 13.0.0 (clang-1300.0.29.3)]
#Run ec2.py inventory script
➜ ~ python /Users/joseph/infrastructure_as_code/ansible_projects/inventory/ec2.py
Traceback (most recent call last):
File "/Users/joseph/infrastructure_as_code/ansible_projects/inventory/ec2.py ", line 172, in <module>
from ansible.module_utils import ec2 as ec2_utils
ImportError: cannot import name 'ec2' from 'ansible.module_utils' (/Users/joseph/.pyenv/versions/pypy3.8-7.3.7/lib/pypy3.8/site- packages/ansible/module_utils/__init__.py)
#$PATH
/Users/joseph/.sdkman/candidates/java/current/bin:/Users/joseph/.pyenv/plugins/pyenv- virtualenv/shims:/Users/joseph/.pyenv/shims:/Users/joseph/.pyenv/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
## Content of ~/.ansible.cfg
[defaults]
interpreter_python=/Users/joseph/.pyenv/shims/python
## Which python
/Users/joseph/.pyenv/shims/python
## other python
➜ ~ pyenv versions
system
3.10.2
3.8.12
ansible-2x
* pypy3.8-7.3.7 (set by /Users/joseph/.pyenv/version)
pypy3.8-7.3.7/envs/ansible-2x
I have read couple of solution around about the PATH and had high hopes about the interpreter_python setting in the config file but none of that worked. So I am not sure what is wrong were, I have also switched to different version of python but it did nothing. Not sure what's missing , I would appreciate some hand in fixing this. Thanks in advance