如何安裝 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 官方網站。

祝你好運。

相關內容