
我正在建立 Ansible Playbook 來設定 Ubuntu 18.04.1 VPS,但遇到了無法可靠安裝 Python 的問題。
由於 Ubuntu 18.04.1 未安裝 Python,因此我被迫apt -y update && apt -y install python
對該raw
模組使用以下命令。
我還設法在手動 ssh 進入的 shell 中遇到此錯誤。
root@ansible:~# apt -y update && apt -y install python
Hit:1 http://archive.ubuntu.com/ubuntu bionic InRelease
Hit:2 http://archive.ubuntu.com/ubuntu bionic-security InRelease
Hit:3 http://archive.ubuntu.com/ubuntu bionic-updates InRelease
Reading package lists... Done
Building dependency tree
Reading state information... Done
17 packages can be upgraded. Run 'apt list --upgradable' to see them.
E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?
這是 Windows 主機上 VirtualBox 中的虛擬機器。
我也嘗試過在andsync
之間使用,甚至在and之間執行類似的操作,但通常會失敗。apt update
apt install
while fuser /var/lib/dpkg/lock >/dev/null 2>&1; do sync && sleep 1; done
update
install
這是一個透過以下步驟設定的系統:https://askubuntu.com/questions/946787/ubuntu-server-installation-with-root-only/1066033#1066033
答案1
Ubuntu 16.04+,iirc,預設附帶 Python3,並從預設安裝中完全刪除了 Python2;換句話說,有一個正在運行的 Python 解釋器,但它不在 Ansible 看起來的地方。
您可以透過使用變數並將其設定為(在 Ubuntu 16.04+ 的情況下)來覆寫預設行為(期望python
作為命令)。ansible_python_interpreter
/usr/bin/python3
所以像這樣:
ansible_python_interpreter: /usr/bin/python3
Ansible 現在在很大程度上將 Python3 視為一等公民,因此這是一個非常安全的變更。我已經在我管理的一些 Ubuntu 18.04 機器上使用它,沒有任何問題。