Blog

03/06/2019

Ansible: Could not find aptitude. Please ensure it is installed Error and Solution



I am running the ‘ansible-playbook -i hostnames upgrade.yml‘ command but getting an error that read as follows

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

My yml file includes the following line:

- apt: update_cache=yes upgrade=yes

How do I fix this error on a Debian or Ubuntu Linux server?


You need to use apt module to manage packages for Debian/Ubuntu Linux using ansible. The apt module runs command depends upon upgrade parameter as follows:

apt module syntax

The syntax is:

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

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

Where VALUE can be any one of the following:

  • if upgrade parameter is no (upgrade=no) – Do NOT upgrade anything (default)
  • if upgrade parameter is yes (upgrade=yes) – Do upgrade using the aptitude command
  • if upgrade parameter is safe (upgrade=safe) – Do upgrade using the aptitude command
  • if upgrade parameter is full (upgrade=full) – Do upgrade using the aptitude command
  • if upgrade parameter is dist (upgrade=dist) – Do upgrade using the apt-get command

Understanding the error

The following error indicates that you do not have aptitude command installed on the remote Debian/Ubuntu box which is quite common on virtual private servers (VPS) or cloud servers or minimal installation or customized installation:

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."}

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."}

You can verify that by ssh into any one of the server:
$ ssh user@db1 type -a aptitude
bash: line 0: type: aptitude: not found
$ ssh vivek@server1.sxi.io aptitude
bash: aptitude: command not found

How do I fix this problem?

To fix this problem either install aptitude on the remote box using apt module itself and run upgrade:

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

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

Or pass the dist parameter to the upgrade so that it will use apt-get command:

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

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

Another solution is to use the following in your .yml file:

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

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

For more info see apt – Manages apt-packages documentations.

(adsbygoogle = window.adsbygoogle || []).push({});

Posted by: SXI ADMIN

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

20/08/2019

Start your Bitcoin Exchange with our Software

Start your Bitcoin Exchange with our Software Setup your white label bitcoin exchange right away. Or create your own cryptocurrency using...
14/08/2019

How to KVM, QEMU start or stop virtual machine from command line (CLI)

KVM or Kernel Based Virtual Machine is a popular virtualization technology. It allows you to run virtual guest machines over a host machine. To start...
14/08/2019

How to Docker backup Saving and restoring your volumes

Running a Docker volume backup First, we spin up a temporary container, and we mount the backup folder and the target Docker volume to this container....