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

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

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.cyberciti.biz 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

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

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

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

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


🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 0 comments... add one


CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
0 comments… add one

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum