Python

Ansible - pip3 安裝失敗

  • August 17, 2020

我正在嘗試在 CentOS 7 上安裝 Ansible,並將 Ansible 配置為使用 Python 3。我已經安裝了 Python2 和 Python3。

[root@ansible1 ~]# python --version
Python 2.7.5
[root@ansible1 ~]# python3 --version
Python 3.6.8

如果我使用 安裝 Ansible yum install ansible,該ansible --version命令顯示 Ansible 已配置為使用 Python 2.7.5。我解除安裝 ansible ( yum remove ansible);

[root@ansible1 ~]# ansible --version
ansible 2.9.10
 config file = /etc/ansible/ansible.cfg
 configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
 ansible python module location = /usr/lib/python2.7/site-packages/ansible
 executable location = /bin/ansible
 python version = 2.7.5 (default, Aug  7 2019, 00:51:29) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]

根據https://docs.ansible.com/ansible/latest/reference_appendices/python_3_support.html

在 Python 3 下執行 /usr/bin/ansible 最簡單的方法是使用 Python3 版本的 pip 安裝它。這將使預設的 /usr/bin/ansible 與 Python3 一起執行

我安裝了 9.0.3 版本的 pip。

[root@ansible1 ~]# pip3 --version
pip 9.0.3 from /usr/lib/python3.6/site-packages (python 3.6)

按照 Ansibles 文件,我pip3 install ansible使用 pip3 安裝 Ansible。

[root@ansible1 ~]# pip3 install ansible
WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead.
Collecting ansible
 Using cached https://files.pythonhosted.org/packages/4b/69/c8aef60ce070fe6872e27db65f588bd0ffe8892a980cd3f4d844d8b72152/ansible-2.9.12.tar.gz
Requirement already satisfied: jinja2 in /usr/local/lib64/python3.6/site-packages (from ansible)
Requirement already satisfied: PyYAML in /usr/local/lib64/python3.6/site-packages (from ansible)
Requirement already satisfied: cryptography in /usr/local/lib64/python3.6/site-packages (from ansible)
Requirement already satisfied: MarkupSafe>=0.23 in /usr/local/lib64/python3.6/site-packages (from jinja2->ansible)
Requirement already satisfied: six>=1.4.1 in /usr/local/lib/python3.6/site-packages (from cryptography->ansible)
Requirement already satisfied: cffi!=1.11.3,>=1.8 in /usr/local/lib64/python3.6/site-packages (from cryptography->ansible)
Requirement already satisfied: pycparser in /usr/local/lib/python3.6/site-packages (from cffi!=1.11.3,>=1.8->cryptography->ansible)
Installing collected packages: ansible
 Running setup.py install for ansible ... done
Successfully installed ansible-2.9.12

這是pip3 show ansible命令的輸出。

[root@ansible1 ~]# pip3 show ansible
Name: ansible
Version: 2.9.12
Summary: Radically simple IT automation
Home-page: https://ansible.com/
Author: Ansible, Inc.
Author-email: info@ansible.com
License: GPLv3+
Location: /usr/local/lib/python3.6/site-packages
Requires: jinja2, PyYAML, cryptography

但是,該ansible --version命令返回以下內容。

-bash: /bin/ansible: No such file or directory

同樣,/usr/bin/ansible --version

-bash: /usr/bin/ansible: No such file or directory

pip show ansible命令顯示位置是/usr/local/lib/python3.6/site-packages/ansible。該目錄存在,並且包含許多文件和文件夾,但沒有可以使用的 Ansible 特定配置文件(例如 ansible.cfg)或二進製文件(例如 ansible)(我能說的最好)。

Bash記憶體 commands 的路徑,如果命令被重新定位(就像您的情況一樣),除非清除記憶體,否則 bash 將不會拾取它。

ansible您可以使用以下命令從記憶體中清除:

hash -d ansible

或清除整個記憶體:

hash -r

引用自:https://serverfault.com/questions/1030419