From 148ffb23f5112d905c1c22e7b0da959a30fa9620 Mon Sep 17 00:00:00 2001 From: Ian Tangney Date: Thu, 16 Sep 2021 13:30:42 +0000 Subject: [PATCH] Resolve KASM-1918 "Feature/ uninstall playbook" --- README.md | 22 ++++++++- roles/uninstall/tasks/main.yml | 83 ++++++++++++++++++++++++++++++++++ uninstall_kasm.yml | 6 +++ 3 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 roles/uninstall/tasks/main.yml create mode 100644 uninstall_kasm.yml diff --git a/README.md b/README.md index dc3a211..6aa87cb 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ The steps below for installing Ansible have been tested on CentOS 7.9.2009, Cent `ansible --version` ## Kasm Multi Server install -This project will deploy Kasm Workspaces in a multi-server deployment using Ansible. +This playbook will deploy Kasm Workspaces in a multi-server deployment using Ansible. * It installs the kasm components on the systems specified in the ansible `inventory` required for the respective roles (db, web, agent). * It creates a new swapfile to ensure that the total swap space matches the size `desired_swap_size` specified on the files in group_vars/. @@ -60,3 +60,23 @@ It has been tested on CentOS 7.9.2009, CentOS 8.4.2105, Debian 9.13, Debian 10.1 4. Login to the deployment as admin@kasm.local using the IP of one of the WebApp servers (eg https://192.168.1.2) 5. Navigate to the Agents tab, and enable each Agent after it checks in. (May take a few minutes) + +## Kasm Uninstall playbook + +This playbook uninstalls Kasm workspaces from DB, WebApp and Agent servers specified in the `inventory` file. + +It has been tested on CentOS 7.9.2009, CentOS 8.4.2105, Debian 9.13, Debian 10.10, Ubuntu 18.04.5, and Ubuntu 20.04.3 + +### Ansible Configuration + +1. Open `inventory` file and fill in the hostnames / ips for the servers that will be fulfilling the agent, webapp and db roles. + +3. Run the deployment. + + `ansible-playbook -Kk -u [username] -i inventory uninstall_kasm.yml` + + Ansible will prompt you for the ssh password and sudo password (will almost always be the same password). + + Or, if you have ssh keys copied over to your servers and have NOPASSWD in sudoers you can just run. + + `ansible-playbook -u [username] -i inventory uninstall_kasm.yml` diff --git a/roles/uninstall/tasks/main.yml b/roles/uninstall/tasks/main.yml new file mode 100644 index 0000000..34d5e10 --- /dev/null +++ b/roles/uninstall/tasks/main.yml @@ -0,0 +1,83 @@ +- name: Check for kasm service containers + shell: docker ps -f name=kasm_* -q + register: service_containers + changed_when: false + become: true + ignore_errors: true + +- name: Remove any kasm service containers + shell: "docker rm -f {{ item }}" + become: true + ignore_errors: true + with_items: "{{ service_containers.stdout_lines }}" + +- name: Check for kasm session containers + shell: docker container ls -qa --filter=label=kasm.kasmid + register: session_containers + changed_when: false + become: true + ignore_errors: true + +- name: Remove any kasm session containers + shell: "docker rm -f {{ item }}" + ignore_errors: true + become: true + with_items: "{{ session_containers.stdout_lines }}" + +- name: Check for kasm docker network + shell: docker network ls -q -f name=kasm_default_network + register: kasm_network + become: true + ignore_errors: true + changed_when: false + +- name: Remove kasm docker network + shell: docker network rm kasm_default_network + ignore_errors: true + become: true + when: kasm_network.stdout | length > 0 + +- name: Get kasm database docker volume + shell: docker volume ls --filter name=kasm_db_* -q + ignore_errors: true + become: true + register: kasm_database + changed_when: false + +- name: Remove kasm database docker volume + shell: "docker volume rm {{ item }}" + ignore_errors: true + become: true + with_items: "{{ kasm_database.stdout_lines }}" + +- name: Get kasm docker images + shell: | + docker images --filter "label=com.kasmweb.image=true" -q + docker images kasmweb/nginx -q + docker images kasmweb/share -q + docker images kasmweb/share-private -q + docker images kasmweb/agent -q + docker images kasmweb/agent-private -q + docker images kasmweb/manager -q + docker images kasmweb/manager-private -q + docker images kasmweb/api -q + docker images kasmweb/api-private -q + docker images redis -q + docker images postgres -q + + register: kasm_images + become: true + ignore_errors: true + changed_when: false + +- name: Remove kasm docker images + shell: "docker rmi {{ item }}" + become: true + ignore_errors: true + with_items: "{{ kasm_images.stdout_lines }}" + +- name: Remove kasm install directory + file: + path: /opt/kasm/ + state: absent + become: true diff --git a/uninstall_kasm.yml b/uninstall_kasm.yml new file mode 100644 index 0000000..d33c2ce --- /dev/null +++ b/uninstall_kasm.yml @@ -0,0 +1,6 @@ +- hosts: + - db + - web + - agent + roles: + - uninstall