Ansible:找不到才能。请确保已安装错误和解决方案

时间:2020-01-09 10:37:07  来源:igfitidea点击:

我正在运行ansible-playbook -i hostnames upgrade.yml命令,但收到如下错误:

fatal: [db1]: FAILED! => {changed: false, failed: true, msg: Could not find aptitude. Please ensure it is installed.}

我的yml文件包含以下行:apt:update_cache = yes upgrade = yes

如何在Debian或Ubuntu Linux服务器上解决此错误?
您需要使用apt模块使用ansible管理Debian/Ubuntu Linux的软件包。

apt模块运行命令取决于升级参数,如下所示:

apt模块语法

语法为:

- name: Update all packages to the latest version
  apt:
    upgrade: VALUE

其中VALUE可以是以下任意一项:

  • 如果upgrade参数为no(upgrade = no)不升级任何东西(默认)
  • 如果upgrade参数是yes(upgrade = yes),请使用aptitude命令进行升级
  • 如果upgrade参数是safe(upgrade = safe),请使用aptitude命令进行升级
  • 如果upgrade参数是full(upgrade = full),请使用aptitude命令进行升级
  • 如果upgrade参数是dist(upgrade = dist),请使用apt-get命令进行升级

了解错误

以下错误表明您没有在远程Debian/Ubuntu框中安装aptitude命令,该命令在虚拟专用服务器(VPS)或云服务器上很常见,或者最小安装或自定义安装:

TASK [Updating host using apt] ***********************************************************************************************
fatal: [db1]: FAILED! => {"changed": false, "failed": true, "msg": "Could not find aptitude. Please ensure it is installed."}
fatal: [db2]: FAILED! => {"changed": false, "failed": true, "msg": "Could not find aptitude. Please ensure it is installed."}
fatal: [www1]: FAILED! => {"changed": false, "failed": true, "msg": "Could not find aptitude. Please ensure it is installed."}
fatal: [www2]: FAILED! => {"changed": false, "failed": true, "msg": "Could not find aptitude. Please ensure it is installed."}

您可以通过ssh验证到任何一台服务器中:

$ ssh user@db1 type -a aptitude
`bash: line 0: type: aptitude: not found`
$ ssh [email protected] aptitude
`bash: aptitude: command not found`

我该如何解决这个问题?

要解决此问题,请使用apt模块本身在远程盒上安装aptitude并运行upgrade:

- name: Update all packages to the latest version
  apt:
    name: aptitude 
    upgrade: yes

或将dist参数传递给升级,以便它将使用apt-get命令:

- name: Update all packages to the latest version
  apt:
    upgrade: dist

另一种解决方案是在.yml文件中使用以下内容:

- name: Upgrade all packages to the latest version
  apt:
    name: "*"
    state: latest

有关更多信息,请参见apt管理apt-packages文档。