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

Cpanel/Whm License $3/mo Plesk License $10/mo Cloudlinux License $5/mo

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.

Posted by: SXI ADMIN

The author is the creator of SXI LLC 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.

Related posts

Zuckerberg to Study Crypto in Quest to Fix Facebook

SXI ADMIN

Zooko Wilcox Envisions ‘Ambitious’ Changes for Zcash Cryptocurrency

SXI ADMIN

ZombieChain Comes Alive: Can Ethereum Sidechains Save the Dapps?

SXI ADMIN

ZoKrates Seeks to Bring Best of Zcash to Ethereum with Devcon Debut

SXI ADMIN

Zk-Starks? New Take on Zcash Tech Could Power Truly Private Blockchains

SXI ADMIN

Zk-Snarks Everywhere: Ethereum Privacy Tech Hits Tipping Point

SXI ADMIN

ZipZap to Offer Cash-for-Bitcoin Service at 28,000 UK Locations

SXI ADMIN

ZipZap Resumes Cash-to-Bitcoin Services for UK Shoppers

SXI ADMIN

ZipZap Raises $1.1 Million to Grow Global Bitcoin Payments Network

SXI ADMIN

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More