大网数据广告活动
服务器运维问答

Ansible - pip3 install fails

· 52CE 我爱测

I am trying to install Ansible on CentOS 7, and have Ansible configured to use Python 3. I've both Python2 and Python3 installed. [root@ansible1 ~]# python --version Python 2.7.5 [root@ansible1 ~]# python3 --version Python 3.6.8 …

问题原文

原帖链接 · JeremyCanfield · CC BY-SA 4.0

I am trying to install Ansible on CentOS 7, and have Ansible configured to use Python 3. I've both Python2 and Python3 installed.

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

If I install Ansible using yum install ansible, the ansible --version command shows that Ansible is configured to use Python 2.7.5. I uninstall 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)]

According to https://docs.ansible.com/ansible/latest/reference_appendices/python_3_support.html:

The easiest way to run /usr/bin/ansible under Python 3 is to install it with the Python3 version of pip. This will make the default /usr/bin/ansible run with Python3

I have version 9.0.3 of pip installed.

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

Following Ansibles documentation, I issue pip3 install ansible to install Ansible using pip3.

[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

Here is the output of the pip3 show ansible command.

[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 omitted]
License: GPLv3+
Location: /usr/local/lib/python3.6/site-packages
Requires: jinja2, PyYAML, cryptography

However, the ansible --version command returns the following.

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

Likewise, /usr/bin/ansible --version:

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

The pip show ansible command shows that the location is /usr/local/lib/python3.6/site-packages/ansible. This directory exists, and contains many files and folders, but no Ansible specific configuration files (e.g. ansible.cfg) or binary files (e.g. ansible) that can be used (best I can tell).

已采纳解答

原帖链接 · Michael Hampton · CC BY-SA 4.0

Bash caches the paths to commands, and if a command is relocated (as it appears to be in your case) then bash will not pick it up unless that cache is cleared.

You can clear ansible from the cache with:

hash -d ansible

Or clear the entire cache with:

hash -r

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-08-17)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。