如何在 Ubuntu 18.04 上完全删除 Ansible 2.8.3

onk*_*ows 2 ansible

在我的 Ubuntu 18.04 上,我安装了 Ansible 2.8.3。

[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]
Run Code Online (Sandbox Code Playgroud)

当然我可以使用 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:~] # 
Run Code Online (Sandbox Code Playgroud)

我可以安装不同的版本,例如 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:~] # 
Run Code Online (Sandbox Code Playgroud)

问题是安装2.9.6-1ppa~bionic只会带回 2.8.3 版本。

[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:~] #
Run Code Online (Sandbox Code Playgroud)

所以结论一定是apt remove ansible不会完全删除2.8.3。如果apt install ansible执行另一个版本,此版本仍会安装准备激活。

有没有办法完全删除 Ansible 2.8.3?没有完全重新安装 Ubuntu 18.04?

顺便说一句,我使用官方 Ansible 存储库安装了 2.8.3

[root:~] # cat /etc/apt/sources.list.d/ansible.list 
deb      "http://ppa.launchpad.net/ansible/ansible/ubuntu" bionic main
[root:~] #  
Run Code Online (Sandbox Code Playgroud)

使用 Chef BTW,我使用 Chef 管理我的所有系统。所以 Ansible 是使用 apt 和官方 Ansible 存储库安装的。

apt_repository 'ansible' do
  uri          'ppa:ansible/ansible'
  distribution node['lsb']['codename']
end
package ['ansible','python-pip']
Run Code Online (Sandbox Code Playgroud)

Lu5*_*u55 5

就我而言,事实证明我已经通过 pip 安装了 ansible:

$ 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
Run Code Online (Sandbox Code Playgroud)

所以尝试通过pip卸载ansible:

$ sudo pip uninstall --yes ansible
Run Code Online (Sandbox Code Playgroud)