Reputation: 30895
i installed python 3.7
python --version
Python 3.7.6
i have python 2.7 installed also but i dont want to use it
so i set :
set alias python=python3
ansible :
ansible --version
ansible 2.9.7
config file = /etc/ansible/ansible.cfg
configured module search path = ['/home/ec2-user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/ec2-user/.local/lib/python3.7/site-packages/ansible
executable location = /home/ec2-user/.local/bin/ansible
python version = 3.7.6 (default, Feb 26 2020, 20:54:15) [GCC 7.3.1 20180712 (Red Hat 7.3.1-6)]
in /etc/ansible/hosts i set the ec2.py from here :
https://raw.githubusercontent.com/ansible/ansible/stable-2.9/contrib/inventory/ec2.py
but when i run :
ansible localhost -m ping
I'm getting :
[WARNING]: * Failed to parse /etc/ansible/hosts with script plugin: Inventory script (/etc/ansible/hosts) had an execution error: Traceback (most recent call last): File "/etc/ansible/hosts", line 164, in <module> import boto
ImportError: No module named boto
[WARNING]: * Failed to parse /etc/ansible/hosts with yaml plugin: Syntax Error while loading YAML. expected '<document start>', but found '<scalar>' The error appears to be in '/etc/ansible/hosts': line 12, column 31, but may be
elsewhere in the file depending on the exact syntax problem. The offending line appears to be: variables needed for Boto have already been set: export AWS_ACCESS_KEY_ID='AK123' ^ here
[WARNING]: * Failed to parse /etc/ansible/hosts with ini plugin: /etc/ansible/hosts:3: Error parsing host definition ''''': No closing quotation
[WARNING]: Unable to parse /etc/ansible/hosts as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
PLAY [Ansible Ad-Hoc] ***********************************************************************************************************************************************************************************************************************
TASK [ping] *********************************************************************************************************************************************************************************************************************************
Saturday 02 May 2020 08:36:13 +0000 (0:00:00.089) 0:00:00.089 **********
ok: [localhost]
PLAY RECAP **********************************************************************************************************************************************************************************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Saturday 02 May 2020 08:36:14 +0000 (0:00:00.290) 0:00:00.380 **********
===============================================================================
boto and boto3 are installed in my server
pip3 install boto
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: boto in ./.local/lib/python3.7/site-packages (2.49.0)
pip3 install boto3
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: boto3 in ./.local/lib/python3.7/site-packages (1.13.0)
Requirement already satisfied: s3transfer<0.4.0,>=0.3.0 in ./.local/lib/python3.7/site-packages (from boto3) (0.3.3)
Requirement already satisfied: botocore<1.17.0,>=1.16.0 in ./.local/lib/python3.7/site-packages (from boto3) (1.16.0)
Requirement already satisfied: jmespath<1.0.0,>=0.7.1 in ./.local/lib/python3.7/site-packages (from boto3) (0.9.5)
Requirement already satisfied: docutils<0.16,>=0.10 in ./.local/lib/python3.7/site-packages (from botocore<1.17.0,>=1.16.0->boto3) (0.15.2)
Requirement already satisfied: urllib3<1.26,>=1.20; python_version != "3.4" in ./.local/lib/python3.7/site-packages (from botocore<1.17.0,>=1.16.0->boto3) (1.25.9)
Requirement already satisfied: python-dateutil<3.0.0,>=2.1 in ./.local/lib/python3.7/site-packages (from botocore<1.17.0,>=1.16.0->boto3) (2.8.1)
Requirement already satisfied: six>=1.5 in ./.local/lib/python3.7/site-packages (from python-dateutil<3.0.0,>=2.1->botocore<1.17.0,>=1.16.0->boto3) (1.14.0)
Upvotes: 0
Views: 2796
Reputation: 44615
Let's start from where you began (versions will be a bit different on my system but result will be the same).
You have python 2.7 installed
$ which python
/usr/bin/python
$ python --version
Python 2.7.17
Your inventory script is executable with the shebang: #!/usr/bin/env python
. This gives at the moment:
$ /usr/bin/env python --version
Python 2.7.17
Now, you also have python3 installed
$ which python3
/usr/bin/python3
$ python3 --version
Python 3.6.9
Since you prefer using python3
, you create an alias so that the python
command line points to your preferred version
$ alias python=python3
$ python --version
Python 3.6.9
You now think that any call to python
will direct to python3
... except this is absolutely not true when using env
$ /usr/bin/env python --version
Python 2.7.17
Conclusion: you need to change your inventory script sheebang line to one of the following:
#!/usr/bin/env python3
#!/usr/bin/python3
Upvotes: 2
Reputation: 114
It looks like an installation issue.
configured module search path = ['/home/ec2-user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/ec2-user/.local/lib/python3.7/site-packages/ansible
executable location = /home/ec2-user/.local/bin/ansible
Ansible python module is /home/ec2-user/.local/lib/python3.7 which is in .local
try which python3
use that path for running the command
ansible localhost -m ping -e 'ansible_python_interpreter=<path goes here>
Upvotes: 1