我正在尝试在 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: [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)(我能说的最好)。
Bash缓存 commands 的路径,如果命令被重新定位(就像您的情况一样),除非清除缓存,否则 bash 将不会拾取它。
ansible
您可以使用以下命令从缓存中清除:或清除整个缓存: