如何安装 Ansible?

如何安装 Ansible?

我正在尝试使用 安装 Ansible sudo apt-get install ansible,但收到以下输出:

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 ansible-core : Depends: python3-jinja2 but it is not installable
                Depends: python3-packaging but it is not installable
                Depends: python3-resolvelib but it is not installable
                Recommends: sshpass but it is not installable
E: Unable to correct problems, you have held broken packages.

如何安装 Ansible?

答案1

Ansible 已经准备好安装指南,它将指导你解决任何缺少的依赖项:https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html

GitHub 上还有开发版本:https://github.com/ansible/ansible

以下是摘自上述指南的基本准则:

  1. 使用以下命令找到 Python 的安装位置:

    which python3
    
  2. 通过运行以下命令确保pip已安装(Python 的一部分):

    python3 -m pip -V
    

    如果一切顺利的话,你应该会看到类似下面的内容:

    pip 21.0.1 from /usr/lib/python3.9/site-packages/pip (python 3.9)
    

    如果是的话,pip则表示可用,您可以继续下一步。

    如果您看到类似这样的错误No module named pip,则需要pip在您选择的 Python 解释器下进行安装才能继续。这可能意味着安装额外的操作系统包(例如),或者通过运行以下命令直接从 Python Packaging Authoritypython3-pip安装最新版本:pip

    curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
    python3 get-pip.py --user
    
  3. pip在您选择的 Python 环境中为当前用户安装 Ansible :

    python3 -m pip install --user ansible
    

您还没有提到您的 Ubuntu 版本安装,所以我假设您可以拥有高于 18.04 的版本,对于该版本来说,上述操作应该可以正常工作。

欲了解其他更多信息,请参阅本答案开头提到的指南和 Ansible 官方网站。

祝你好运。

相关内容