Ansible-pip3 安装失败

Ansible-pip3 安装失败

我正在尝试在 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 ansibleansible --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 运行

我安装了 pip 9.0.3 版本。

[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: [email protected]
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)(据我所知)。

答案1

猛击缓存命令的路径,并且如果命令被重新定位(就像在您的例子中那样)那么 bash 将不会拾取它,除非清除该缓存。

您可以ansible使用以下方法清除缓存:

hash -d ansible

或者使用以下命令清除整个缓存:

hash -r

相关内容