[英]AWS linux : ansible 2.9.7 using ec2.py and python 3.7 getting : ImportError: No module named boto , boto do installed
我安裝了 python 3.7
python --version
Python 3.7.6
我也安裝了 python 2.7 但我不想使用它
所以我設置:
設置別名 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)]
在 /etc/ansible/hosts 我從這里設置 ec2.py :
https://raw.githubusercontent.com/ansible/ansible/stable-2.9/contrib/inventory/ec2.py
但是當我運行時:
ansible localhost -m ping
我越來越:
[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)
讓我們從你開始的地方開始(我的系統上的版本會有點不同,但結果會是一樣的)。
您已安裝 python 2.7
$ which python
/usr/bin/python
$ python --version
Python 2.7.17
您的清單腳本可以使用 shebang 執行: #!/usr/bin/env python
。 目前這給出了:
$ /usr/bin/env python --version
Python 2.7.17
現在,您還安裝了 python3
$ which python3
/usr/bin/python3
$ python3 --version
Python 3.6.9
由於您更喜歡使用python3
,因此您創建一個別名,以便python
命令行指向您的首選版本
$ alias python=python3
$ python --version
Python 3.6.9
您現在認為對python
的任何調用都將直接指向python3
...除非在使用env
時這絕對不是真的
$ /usr/bin/env python --version
Python 2.7.17
結論:您需要將庫存腳本 sheebang 行更改為以下之一:
#!/usr/bin/env python3
#!/usr/bin/python3
它看起來像一個安裝問題。
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 模塊是 /home/ec2-user/.local/lib/python3.7 這是 in.local
嘗試which python3
使用該路徑運行命令ansible localhost -m ping -e 'ansible_python_interpreter=<path goes here>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.