当我尝试使用 Ansible 卸载 RHEL 8 机器上的 docker 时,出现以下错误
fatal: [server1]: FAILED! => {"changed": false, "msg": "Failed to download packages: containers-common-1:1.2.2-10.module+el8.4.0+11311+9da8acfb.x86_64: Cannot download, all mirrors were already tried without success", "results": []}
如果我通过 SSH 连接到 ansible 用户所在的同一主机并运行手动操作
yum remove docker docker-client docker-client-latest....
,软件包将成功删除。
这是我的 Ansible 代码
---
- name: Remove PodMan
gather_facts: true
hosts: all
become: yes
tasks:
- name: uninstall podman
package:
name:
- docker
- docker-client
- docker-client-latest
- docker-common
- docker-latest
- docker-latest-logrotate
- docker-logrotate
- docker-engine
- podman
- runc
state: absent
我也尝试过“yum”模块而不是包,但我得到了同样的错误。
这是我的 Ansible 版本
ansible --version
ansible [core 2.14.2]
config file = /etc/ansible/ansible.cfg
configured module search path = ['/home/ansible/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.11/site-packages/ansible
ansible collection location = /home/ansible/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.11.2 (main, Jun 6 2023, 07:39:01) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] (/usr/bin/python3.11)
jinja version = 3.1.2
libyaml = True
---
- name: uninstall packages
hosts: all
gather_facts: true
vars:
packages:
- docker
- podman
tasks:
- name: uninstall
yum:
name: "{{item}}"
state: absent
loop: "{{packages}}"
Ansible playbook 用于卸载所有主机上的软件包。它会循环遍历所有软件包并一一卸载。它使用 yum 模块。