Ansible 通过 pip3 安装,但未找到 Ansible 命令

Ansible 通过 pip3 安装,但未找到 Ansible 命令

我已经通过 安装了 Ansible pip3,但是我找不到 Ansible 命令(ansible --versionansible-playbook等)

以下清单显示 Ansible 是通过以下方式安装的pip3

:~# pip3 list  | grep ansible
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
ansible (3.1.0)
ansible-base (2.10.7)

但是我找不到任何文件或任何东西/usr/bin,也找不到命令:

:~/.ansible# ls -ltrha
total 12K
drwx------ 3 root root 4.0K Feb  3 11:42 .
drwx------ 3 root root 4.0K Mar 19 16:01 tmp
drwx------ 8 root root 4.0K Mar 22 15:34 ..

我需要配置什么吗?我的安装是否不正确?

我使用 Debian GNU/Linux 9 (stretch)

答案1

将其添加~/.local/binPATH环境变量中,您可以通过在 Unix 终端中执行以下命令来完成此操作

export PATH=$PATH:~/.local/bin

答案2

我在 ubuntu WSL 安装中也遇到了同样的问题。只需使用以下命令卸载它:

python3 -m pip uninstall ansible

移至主目录:

cd ~

您的提示将显示:~$

重新安装一下:

python3 -m pip install --user ansible

现在它正在工作:)

:~$ ansible --version
ansible [core 2.13.1]
config file = None
configured module search path = ['/home/evert/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/evert/.local/lib/python3.8/site-packages/ansible
ansible collection location = /home/evert/.ansible/collections:/usr/share/ansible/collections
executable location = /home/evert/.local/bin/ansible
python version = 3.8.10 (default, Nov 26 2021, 20:14:08) [GCC 9.3.0]
jinja version = 3.1.2
libyaml = True

答案3

这种情况往往会像@micke 所评论的那样发生 -pip3root用户身份使用时 - 已安装的 CLI 工具可能会最终位于$PATH环境变量中未包含的目录中 - 然后您需要进行调整$PATH

在 Debian10 上测试,所有性能均符合预期:

root@d10:~# pip3 install ansible
Collecting ansible
  Downloading https://files.pythonhosted.org/packages/fd/f8/071905c6a67592d0852a9f340f6ab9226861eeeb97fdf4068642b22edcf3/ansible-4.10.0.tar.gz (36.8MB)
    100% |████████████████████████████████| 36.8MB 35kB/s 
#pip3 install log truncated...
 root@d10:~# ansible --version
[DEPRECATION WARNING]: Ansible will require Python 3.8 or newer on the controller starting with Ansible 2.12. Current version: 3.7.3 (default, Jan 22 2021, 
20:04:44) [GCC 8.3.0]. This feature will be removed from ansible-core in version 2.12. Deprecation warnings can be disabled by setting 
deprecation_warnings=False in ansible.cfg.
ansible [core 2.11.7] 
  config file = None
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.7/dist-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.7.3 (default, Jan 22 2021, 20:04:44) [GCC 8.3.0]
  jinja version = 3.0.3
  libyaml = True
root@d10:~# which ansible
/usr/local/bin/ansible

答案4

你可以将路径添加到 .bashrc 中,以便每次终端会话时都能加载它

~/.bashrc

if [ -d "$HOME/.local/bin" ] ; then
    PATH="$HOME/.local/bin:$PATH"
fi

重新加载你的 bashrc,运行这个或关闭所有 shell 并重新打开

source ~/.bashrc

如果一切正常,运行时你应该会看到二进制文件的路径which ansible

相关内容