fix: reset docker was not removing docker properly (#8680)
Signed-off-by: Cyril Corbon <corboncyril@gmail.com>pull/8692/head
parent
3782573ede
commit
29109575f5
|
@ -1,20 +1,81 @@
|
||||||
---
|
---
|
||||||
|
|
||||||
|
- name: Docker | Get package facts
|
||||||
|
package_facts:
|
||||||
|
manager: auto
|
||||||
|
|
||||||
|
- name: Docker | Find docker packages
|
||||||
|
set_fact:
|
||||||
|
docker_packages_list: "{{ ansible_facts.packages.keys() | select('search', '^docker*') }}"
|
||||||
|
containerd_package: "{{ ansible_facts.packages.keys() | select('search', '^containerd*') }}"
|
||||||
|
|
||||||
|
- name: Docker | Stop all running container
|
||||||
|
shell: "set -o pipefail && {{ docker_bin_dir }}/docker ps -q | xargs -r {{ docker_bin_dir }}/docker kill"
|
||||||
|
args:
|
||||||
|
executable: /bin/bash
|
||||||
|
register: stop_all_containers
|
||||||
|
retries: 5
|
||||||
|
until: stop_all_containers.rc == 0
|
||||||
|
changed_when: true
|
||||||
|
delay: 5
|
||||||
|
ignore_errors: true # noqa ignore-errors
|
||||||
|
when: docker_packages_list|length>0
|
||||||
|
|
||||||
|
- name: reset | remove all containers
|
||||||
|
shell: "set -o pipefail && {{ docker_bin_dir }}/docker ps -aq | xargs -r docker rm -fv"
|
||||||
|
args:
|
||||||
|
executable: /bin/bash
|
||||||
|
register: remove_all_containers
|
||||||
|
retries: 4
|
||||||
|
until: remove_all_containers.rc == 0
|
||||||
|
delay: 5
|
||||||
|
when: docker_packages_list|length>0
|
||||||
|
|
||||||
|
- name: Docker | Stop docker service
|
||||||
|
service:
|
||||||
|
name: "{{ item }}"
|
||||||
|
enabled: false
|
||||||
|
state: stopped
|
||||||
|
loop:
|
||||||
|
- docker
|
||||||
|
- docker.socket
|
||||||
|
- containerd
|
||||||
|
|
||||||
|
- name: Docker | Remove dpkg hold
|
||||||
|
dpkg_selections:
|
||||||
|
name: "{{ item }}"
|
||||||
|
selection: install
|
||||||
|
when: ansible_pkg_mgr == 'apt'
|
||||||
|
changed_when: false
|
||||||
|
with_items:
|
||||||
|
- "{{ docker_packages_list }}"
|
||||||
|
- "{{ containerd_package }}"
|
||||||
|
|
||||||
|
- name: Docker | Remove docker package
|
||||||
|
package:
|
||||||
|
name: "{{ item }}"
|
||||||
|
state: absent
|
||||||
|
changed_when: false
|
||||||
|
with_items:
|
||||||
|
- "{{ docker_packages_list }}"
|
||||||
|
- "{{ containerd_package }}"
|
||||||
|
when:
|
||||||
|
- not ansible_os_family in ["Flatcar", "Flatcar Container Linux by Kinvolk"]
|
||||||
|
- not is_ostree
|
||||||
|
- docker_packages_list|length > 0
|
||||||
|
|
||||||
- name: Docker | ensure docker-ce repository is removed
|
- name: Docker | ensure docker-ce repository is removed
|
||||||
apt_repository:
|
apt_repository:
|
||||||
repo: "{{ item }}"
|
repo: "{{ item }}"
|
||||||
state: absent
|
state: absent
|
||||||
with_items: "{{ docker_repo_info.repos }}"
|
with_items: "{{ docker_repo_info.repos }}"
|
||||||
when: ansible_pkg_mgr == 'apt'
|
when: ansible_pkg_mgr == 'apt'
|
||||||
tags:
|
|
||||||
- reset_docker
|
|
||||||
|
|
||||||
- name: Docker | Remove docker repository on Fedora
|
- name: Docker | Remove docker repository on Fedora
|
||||||
file:
|
file:
|
||||||
name: "{{ yum_repo_dir }}/docker.repo"
|
name: "{{ yum_repo_dir }}/docker.repo"
|
||||||
state: absent
|
state: absent
|
||||||
when: ansible_distribution == "Fedora" and not is_ostree
|
when: ansible_distribution == "Fedora" and not is_ostree
|
||||||
tags:
|
|
||||||
- reset_docker
|
|
||||||
|
|
||||||
- name: Docker | Remove docker repository on RedHat/CentOS/Oracle/AlmaLinux Linux
|
- name: Docker | Remove docker repository on RedHat/CentOS/Oracle/AlmaLinux Linux
|
||||||
template:
|
template:
|
||||||
|
@ -24,18 +85,6 @@
|
||||||
- ansible_os_family == "RedHat"
|
- ansible_os_family == "RedHat"
|
||||||
- ansible_distribution != "Fedora"
|
- ansible_distribution != "Fedora"
|
||||||
- not is_ostree
|
- not is_ostree
|
||||||
tags:
|
|
||||||
- reset_docker
|
|
||||||
|
|
||||||
- name: Docker | Stop docker service
|
|
||||||
service:
|
|
||||||
name: docker
|
|
||||||
daemon_reload: true
|
|
||||||
enabled: false
|
|
||||||
masked: true
|
|
||||||
state: stopped
|
|
||||||
tags:
|
|
||||||
- reset_docker
|
|
||||||
|
|
||||||
- name: Docker | Remove docker configuration files
|
- name: Docker | Remove docker configuration files
|
||||||
file:
|
file:
|
||||||
|
@ -43,19 +92,13 @@
|
||||||
state: absent
|
state: absent
|
||||||
loop:
|
loop:
|
||||||
- /etc/systemd/system/docker.service.d/
|
- /etc/systemd/system/docker.service.d/
|
||||||
|
- /etc/systemd/system/docker.socket
|
||||||
|
- /etc/systemd/system/docker.service
|
||||||
|
- /etc/systemd/system/containerd.service
|
||||||
|
- /etc/systemd/system/containerd.service.d
|
||||||
- /var/lib/docker
|
- /var/lib/docker
|
||||||
- /etc/docker
|
- /etc/docker
|
||||||
tags:
|
|
||||||
- reset_docker
|
|
||||||
|
|
||||||
- name: Docker | Remove docker package
|
- name: Docker | systemctl daemon-reload # noqa 503
|
||||||
package:
|
systemd:
|
||||||
name: "{{ docker_package_info.pkgs }}"
|
daemon_reload: true
|
||||||
state: absent
|
|
||||||
changed_when: false
|
|
||||||
when:
|
|
||||||
- not ansible_os_family in ["Flatcar", "Flatcar Container Linux by Kinvolk"]
|
|
||||||
- not is_ostree
|
|
||||||
- docker_package_info.pkgs|length > 0
|
|
||||||
tags:
|
|
||||||
- reset_docker
|
|
||||||
|
|
|
@ -30,43 +30,18 @@
|
||||||
- containerd
|
- containerd
|
||||||
- crio
|
- crio
|
||||||
|
|
||||||
- name: reset | remove docker dropins
|
- name: reset | Remove Docker
|
||||||
file:
|
include_role:
|
||||||
path: "/etc/systemd/system/docker.service.d/{{ item }}"
|
name: container-engine/docker
|
||||||
state: absent
|
tasks_from: reset
|
||||||
with_items:
|
when: container_manager == 'docker'
|
||||||
- docker-dns.conf
|
|
||||||
- docker-options.conf
|
|
||||||
- http-proxy.conf
|
|
||||||
- docker-orphan-cleanup.conf
|
|
||||||
register: docker_dropins_removed
|
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
|
||||||
- name: reset | systemctl daemon-reload # noqa 503
|
- name: reset | systemctl daemon-reload # noqa 503
|
||||||
systemd:
|
systemd:
|
||||||
daemon_reload: true
|
daemon_reload: true
|
||||||
when: services_removed.changed or docker_dropins_removed.changed
|
when: services_removed.changed
|
||||||
|
|
||||||
- name: reset | remove all containers
|
|
||||||
shell: "set -o pipefail && {{ docker_bin_dir }}/docker ps -aq | xargs -r docker rm -fv"
|
|
||||||
args:
|
|
||||||
executable: /bin/bash
|
|
||||||
register: remove_all_containers
|
|
||||||
retries: 4
|
|
||||||
until: remove_all_containers.rc == 0
|
|
||||||
delay: 5
|
|
||||||
when: container_manager == "docker"
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
|
|
||||||
- name: reset | restart docker if needed # noqa 503
|
|
||||||
service:
|
|
||||||
name: docker
|
|
||||||
state: restarted
|
|
||||||
when: docker_dropins_removed.changed and container_manager == "docker"
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
|
|
||||||
- name: reset | check if crictl is present
|
- name: reset | check if crictl is present
|
||||||
stat:
|
stat:
|
||||||
|
|
Loading…
Reference in New Issue