Skip to content

Commit

Permalink
feat: check & uninstall container engine
Browse files Browse the repository at this point in the history
Signed-off-by: Cyril Corbon <[email protected]>
  • Loading branch information
cyril-corbon committed Jan 31, 2022
1 parent 2bbe573 commit 6b56ffb
Show file tree
Hide file tree
Showing 6 changed files with 256 additions and 3 deletions.
41 changes: 41 additions & 0 deletions roles/container-engine/containerd/tasks/reset.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
- name: containerd | Remove containerd repository for RedHat os family
file:
path: "{{ yum_repo_dir }}/containerd.repo"
state: absent
when:
- ansible_os_family in ['RedHat']
tags:
- reset_containerd

- name: containerd | Remove containerd repository for Debian os family
apt_repository:
repo: "{{ item }}"
state: absent
with_items: "{{ containerd_repo_info.repos }}"
when: ansible_pkg_mgr == 'apt'
tags:
- reset_containerd

- name: containerd | Stop containerd service
service:
name: containerd
daemon_reload: true
enabled: false
masked: true
state: stopped
tags:
- reset_containerd

- name: containerd | Remove configuration files
file:
path: "{{ item }}"
state: absent
loop:
- /etc/systemd/system/containerd.service
- "{{ containerd_systemd_dir }}"
- "{{ containerd_cfg_dir }}"
- "{{ containerd_storage_dir }}"
- "{{ containerd_state_dir }}"
tags:
- reset_containerd
5 changes: 2 additions & 3 deletions roles/container-engine/cri-o/tasks/crio_repo.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---

- block:
- name: Add Debian Backports apt repo
apt_repository:
Expand Down Expand Up @@ -99,7 +98,7 @@
baseurl: http://{{ crio_download_base }}/CentOS_{{ ansible_distribution_major_version }}/
gpgcheck: yes
gpgkey: http://{{ crio_download_base }}/CentOS_{{ ansible_distribution_major_version }}/repodata/repomd.xml.key
keepcache: '0'
keepcache: "0"
when:
- ansible_os_family == "RedHat"
- ansible_distribution not in ["Amazon", "Fedora"]
Expand All @@ -122,7 +121,7 @@
baseurl: http://{{ crio_download_base }}/CentOS_7/
gpgcheck: yes
gpgkey: http://{{ crio_download_base }}/CentOS_7/repodata/repomd.xml.key
keepcache: '0'
keepcache: "0"
when: ansible_distribution in ["Amazon"]

- name: Add CRI-O kubic yum repo
Expand Down
91 changes: 91 additions & 0 deletions roles/container-engine/cri-o/tasks/reset.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
---
- name: CRI-O | Kubic repo name for debian os family
set_fact:
crio_kubic_debian_repo_name: "{{ ((ansible_distribution == 'Ubuntu') | ternary('x','')) ~ ansible_distribution ~ '_' ~ ansible_distribution_version }}"
when: ansible_os_family == "Debian"
tags:
- reset_crio

- name: CRI-O | Remove kubic apt repo
apt_repository:
repo: "deb http://{{ crio_download_base }}/{{ crio_kubic_debian_repo_name }}/ /"
state: absent
when: crio_kubic_debian_repo_name is defined
tags:
- reset_crio

- name: CRI-O | Remove cri-o apt repo
apt_repository:
repo: "deb {{ crio_download_crio }}{{ crio_version }}/{{ crio_kubic_debian_repo_name }}/ /"
state: present
filename: devel-kubic-libcontainers-stable-cri-o
when: crio_kubic_debian_repo_name is defined
tags:
- reset_crio

- name: CRI-O | Remove CRI-O kubic yum repo
yum_repository:
name: devel_kubic_libcontainers_stable
state: absent
when: ansible_distribution in ["Amazon"]
tags:
- reset_crio

- name: CRI-O | Remove CRI-O kubic yum repo
yum_repository:
name: "devel_kubic_libcontainers_stable_cri-o_{{ crio_version }}"
state: absent
when:
- ansible_os_family == "RedHat"
- ansible_distribution not in ["Amazon", "Fedora"]
tags:
- reset_crio

- name: CRI-O | Run yum-clean-metadata
command: yum clean metadata
args:
warn: no
when:
- ansible_os_family == "RedHat"
tags:
- reset_crio

- name: CRI-O | Remove crictl
file:
name: "{{ item }}"
state: absent
loop:
- /etc/crictl.yaml
- "{{ bin_dir }}/crictl"
tags:
- reset_crio

- name: CRI-O | Stop crio service
service:
name: crio
daemon_reload: true
enabled: false
masked: true
state: stopped
tags:
- reset_crio

- name: CRI-O | Remove CRI-O configuration files
file:
name: "{{ item }}"
state: absent
loop:
- /etc/crio
- /etc/containers
- /etc/systemd/system/crio.service.d
tags:
- reset_crio

- name: CRI-O | Uninstall CRI-O package
package:
name: "{{ item }}"
state: absent
when: not is_ostree
with_items: "{{ crio_packages }}"
tags:
- reset_crio
61 changes: 61 additions & 0 deletions roles/container-engine/docker/tasks/reset.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
- name: Docker | ensure docker-ce repository is removed
apt_repository:
repo: "{{ item }}"
state: absent
with_items: "{{ docker_repo_info.repos }}"
when: ansible_pkg_mgr == 'apt'
tags:
- reset_docker

- name: Docker | Remove docker repository on Fedora
file:
name: "{{ yum_repo_dir }}/docker.repo"
state: absent
when: ansible_distribution == "Fedora" and not is_ostree
tags:
- reset_docker

- name: Docker | Remove docker repository on RedHat/CentOS/Oracle/AlmaLinux Linux
template:
name: "{{ yum_repo_dir }}/docker-ce.repo"
state: absent
when:
- ansible_os_family == "RedHat"
- ansible_distribution != "Fedora"
- 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
file:
name: "{{ item }}"
state: absent
loop:
- /etc/systemd/system/docker.service.d/
- /var/lib/docker
- /etc/docker
tags:
- reset_docker

- name: Docker | Remove docker package
package:
name: "{{ docker_package_info.pkgs }}"
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
5 changes: 5 additions & 0 deletions roles/container-engine/meta/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# noqa role-name - this is a meta role that doesn't need a name
---
dependencies:
- role: container-engine/validate-container-engine
tags:
- container-engine
- validate-container-engine

- role: container-engine/kata-containers
when:
- kata_containers_enabled
Expand Down
56 changes: 56 additions & 0 deletions roles/container-engine/validate-container-engine/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
- name: Check if containerd is installed
find:
file_type: file
recurse: yes
patterns:
- containerd*
paths: /usr
register: containerd_installed

- name: Check if docker is installed
find:
file_type: file
recurse: yes
patterns:
- docker*
paths: /usr
register: docker_installed

- name: Check if crio is installed
find:
file_type: file
recurse: yes
patterns:
- crio*
paths: /usr
register: crio_installed

- name: Uninstall containerd
include_role:
name: container-engine/containerd
apply:
tags:
- reset_containerd
when:
- container_manager != "containerd"
- not docker_installed.files|length
- containerd_installed|length

- name: Uninstall docker
include_role:
name: container-engine/docker
apply:
tags:
- reset_docker
when:
- container_manager != "docker"
- docker_installed.files|length

- name: Uninstall crio
include_role:
name: container-engine/crio
apply:
tags:
- reset_crio
when: container_manager != "crio" and crio_installed.files|length

0 comments on commit 6b56ffb

Please sign in to comment.