How to completely remove Ansible 2.8.3 on Ubuntu 18.04

Viewed 19070

On my Ubuntu 18.04 I have Ansible 2.8.3 installed.

[root:~] # ansible --version
ansible 2.8.3
  config file = None
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.15+ (default, Oct  7 2019, 17:39:04) [GCC 7.4.0]

Of course I can remove this package using apt

[root:~] # apt remove ansible
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  python-httplib2 python-jinja2 python-markupsafe python-paramiko python-pyasn1 python-yaml sshpass
Use 'apt autoremove' to remove them.
The following packages will be REMOVED:
  ansible
0 upgraded, 0 newly installed, 1 to remove and 343 not upgraded.
After this operation, 58.0 MB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 317908 files and directories currently installed.)
Removing ansible (2.9.6-1ppa~bionic) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
[root:~] # 

And I can install a different version for example 2.9.6

[root:~] # apt install ansible=2.9.6-1ppa~bionic
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  ansible
0 upgraded, 1 newly installed, 0 to remove and 343 not upgraded.
Need to get 0 B/5,786 kB of archives.
After this operation, 58.0 MB of additional disk space will be used.
Selecting previously unselected package ansible.
(Reading database ... 311783 files and directories currently installed.)
Preparing to unpack .../ansible_2.9.6-1ppa~bionic_all.deb ...
Unpacking ansible (2.9.6-1ppa~bionic) ...
Setting up ansible (2.9.6-1ppa~bionic) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
[root:~] # 

The problem is that installing 2.9.6-1ppa~bionic will only bring the 2.8.3 version back.

[root:~] # ansible --version
ansible 2.8.3
  config file = None
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.15+ (default, Oct  7 2019, 17:39:04) [GCC 7.4.0]
[root:~] #

So the conclusion must be that apt remove ansible will not completely remove 2.8.3. This version is still installed ready to be activated if another apt install ansible is executed.

Is there a way to completely remove Ansible 2.8.3? Short of completely reinstalling Ubuntu 18.04?

BTW, I installed 2.8.3 using official Ansible repository

[root:~] # cat /etc/apt/sources.list.d/ansible.list 
deb      "http://ppa.launchpad.net/ansible/ansible/ubuntu" bionic main
[root:~] #  

Using Chef BTW, I manage all my systems using Chef. So Ansible was installed using apt and official Ansible repository.

apt_repository 'ansible' do
  uri          'ppa:ansible/ansible'
  distribution node['lsb']['codename']
end
package ['ansible','python-pip']
2 Answers

In my case it's turned out that I've ansible installed by pip:

$ sudo apt remove ansible
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package 'ansible' is not installed, so not removed

$ ansible --version
ansible 2.3.2.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.17 (default, Apr 15 2020, 17:20:14) [GCC 7.5.0]

$ sudo pip uninstall --yes ansible
Uninstalling ansible-2.3.2.0:
  Successfully uninstalled ansible-2.3.2.0

$ ansible --version
-bash: /usr/local/bin/ansible: No such file or directory

So try to uninstall ansible by pip:

$ sudo pip uninstall --yes ansible

I fixed this by deinstalling Ansible, Python and then searching the file system from root for anything with name 'ansible'. Inclusing repositories.

Related