tpotce/installer/remove/tpot.yml

321 lines
9 KiB
YAML
Raw Normal View History

2023-06-26 02:59:52 +00:00
---
###################
# T-Pot - Removal #
###################
2023-06-26 02:59:52 +00:00
#####################################################################
# T-Pot - Abort if run as tpot, root or on unsupported distribution #
#####################################################################
- name: T-Pot - Abort if run as tpot, root or on unsupported distribution
2023-06-26 02:59:52 +00:00
hosts: all
gather_facts: true
2023-06-30 11:15:30 +00:00
become: false
tags:
- "AlmaLinux"
- "Debian"
- "Fedora"
- "openSUSE Tumbleweed"
- "Raspbian"
- "Rocky"
- "Ubuntu"
2023-06-26 02:59:52 +00:00
tasks:
- name: Check if running as root (All)
2023-06-26 02:59:52 +00:00
assert:
that: ansible_user_id != 'root'
fail_msg: "T-Pot playbook should not be run as root."
success_msg: "Running as user: {{ ansible_user_id }}."
- name: Check if running as tpot (All)
2023-06-26 02:59:52 +00:00
assert:
that: ansible_user_id != 'tpot'
fail_msg: "Reserved username `tpot` detected."
success_msg: "Running as user: {{ ansible_user_id }}."
2023-06-26 02:59:52 +00:00
- name: Check if supported distribution (All)
assert:
that: ansible_distribution in ["AlmaLinux", "Debian", "Fedora", "openSUSE Tumbleweed", "Raspbian", "Rocky", "Ubuntu"]
fail_msg: "T-Pot uninstall is not supported on this plattform: {{ ansible_distribution }}."
success_msg: "T-Pot will now be removed from {{ ansible_distribution }}."
#######################################
# T-Pot - Remove cron job and service #
#######################################
2023-06-26 02:59:52 +00:00
- name: Reverse T-Pot - Remove randomized daily reboot
2023-06-26 02:59:52 +00:00
hosts: all
gather_facts: true
become: true
tags:
- "AlmaLinux"
- "Debian"
- "Fedora"
- "openSUSE Tumbleweed"
- "Raspbian"
- "Rocky"
- "Ubuntu"
2023-06-26 02:59:52 +00:00
tasks:
- name: Remove the randomized daily reboot cron job (All)
cron:
name: "T-Pot Daily Reboot"
user: root
2023-06-26 02:59:52 +00:00
state: absent
when: ansible_distribution in ["AlmaLinux", "Debian", "Fedora", "openSUSE Tumbleweed", "Raspbian", "Rocky", "Ubuntu"]
2023-06-26 02:59:52 +00:00
- name: Reverse T-Pot - Remove systemd service
hosts: all
gather_facts: true
become: true
tags:
- "AlmaLinux"
- "Debian"
- "Fedora"
- "openSUSE Tumbleweed"
- "Raspbian"
- "Rocky"
- "Ubuntu"
2023-06-26 02:59:52 +00:00
tasks:
- name: Stop and disable tpot.service (All)
ansible.builtin.systemd:
name: tpot.service
state: stopped
enabled: no
when: ansible_distribution in ["AlmaLinux", "Debian", "Fedora", "openSUSE Tumbleweed", "Raspbian", "Rocky", "Ubuntu"]
- name: Remove systemd service file for tpot
ansible.builtin.file:
path: '/etc/systemd/system/tpot.service'
state: absent
notify: Reload systemd
when: ansible_distribution in ["AlmaLinux", "Debian", "Fedora", "openSUSE Tumbleweed", "Raspbian", "Rocky", "Ubuntu"]
handlers:
- name: Reload systemd
become: true
ansible.builtin.systemd:
daemon_reload: yes
2023-06-26 02:59:52 +00:00
##################################################
# T-Pot - Adjust bashrc, remove T-Pot repository #
2023-06-26 02:59:52 +00:00
##################################################
- name: T-Pot - Reverse Adjustments
2023-06-26 02:59:52 +00:00
hosts: all
gather_facts: true
become: true
tags:
- "AlmaLinux"
- "Debian"
- "Fedora"
- "openSUSE Tumbleweed"
- "Raspbian"
- "Rocky"
- "Ubuntu"
2023-06-26 02:59:52 +00:00
tasks:
- name: Remove aliases from .bashrc (All)
blockinfile:
path: ~/.bashrc
block: ""
marker: "# {mark} ANSIBLE MANAGED BLOCK"
2023-06-26 02:59:52 +00:00
state: absent
become: false
when: ansible_distribution in ["AlmaLinux", "Debian", "Fedora", "openSUSE Tumbleweed", "Raspbian", "Rocky", "Ubuntu"]
2023-06-26 02:59:52 +00:00
##########################################################
# T-Pot - Restore configs, remove users and groups, etc. #
##########################################################
2023-06-26 02:59:52 +00:00
- name: T-Pot - Adjust configs, add users and groups, etc.
hosts: all
gather_facts: true
become: true
2023-06-26 02:59:52 +00:00
tasks:
- name: Revert DNSStubListener setting in resolved.conf (Fedora, Ubuntu)
2023-06-26 02:59:52 +00:00
lineinfile:
path: /etc/systemd/resolved.conf
regexp: 'DNSStubListener=no'
line: 'DNSStubListener=yes'
2023-06-26 02:59:52 +00:00
state: present
when: ansible_distribution in ["Fedora", "Ubuntu"]
tags:
- "Fedora"
- "Ubuntu"
2023-06-26 02:59:52 +00:00
- name: Revert SELinux config to enforcing (AlmaLinux, Fedora, Rocky)
2023-06-26 02:59:52 +00:00
lineinfile:
path: /etc/selinux/config
regexp: '^SELINUX='
line: 'SELINUX=enforcing'
when: ansible_distribution in ["AlmaLinux", "Fedora", "Rocky"]
tags:
- "AlmaLinux"
- "Fedora"
- "Rocky"
2023-06-26 02:59:52 +00:00
- name: Remove iptables.conf file (AlmaLinux, Fedora, Rocky)
2023-06-26 02:59:52 +00:00
file:
path: /etc/modules-load.d/iptables.conf
2023-06-26 02:59:52 +00:00
state: absent
when: ansible_distribution in ["AlmaLinux", "Fedora", "Rocky"]
tags:
- "AlmaLinux"
- "Fedora"
- "Rocky"
2023-06-26 02:59:52 +00:00
- name: Revert firewall to default target DROP (AlmaLinux, Fedora, openSUSE Tumbleweed, Rocky)
2023-06-26 02:59:52 +00:00
firewalld:
zone: public
target: DROP
2023-06-26 02:59:52 +00:00
permanent: yes
state: enabled
when: ansible_distribution in ["AlmaLinux", "Fedora", "openSUSE Tumbleweed", "Rocky"]
tags:
- "AlmaLinux"
- "Fedora"
- "openSUSE Tumbleweed"
- "Rocky"
- name: Revert firewall to SSH default (AlmaLinux, Fedora, openSUSE Tumbleweed, Rocky)
2023-06-26 02:59:52 +00:00
firewalld:
port: 22/tcp
2023-06-26 02:59:52 +00:00
permanent: yes
state: enabled
when: ansible_distribution in ["AlmaLinux", "Fedora", "openSUSE Tumbleweed", "Rocky"]
tags:
- "AlmaLinux"
- "Fedora"
- "openSUSE Tumbleweed"
- "Rocky"
- name: Remove port.conf file to revert SSH to default port (openSUSE Tumbleweed)
file:
path: /etc/ssh/sshd_config.d/port.conf
state: absent
when: ansible_distribution in ["openSUSE Tumbleweed"]
tags:
- "openSUSE Tumbleweed"
2023-06-26 02:59:52 +00:00
- name: Revert SSH Port to 22 (AlmaLinux, Debian, Fedora, Raspbian, Rocky, Ubuntu)
lineinfile:
path: /etc/ssh/sshd_config
line: "Port 64295"
state: absent
when: ansible_distribution in ["AlmaLinux", "Debian", "Fedora", "Raspbian", "Rocky", "Ubuntu"]
tags:
- "AlmaLinux"
- "Debian"
- "Fedora"
- "Raspbian"
- "Rocky"
- "Ubuntu"
2023-06-26 02:59:52 +00:00
- name: Remove T-Pot user (All)
user:
name: tpot
state: absent
when: ansible_distribution in ["AlmaLinux", "Debian", "Fedora", "openSUSE Tumbleweed", "Raspbian", "Rocky", "Ubuntu"]
tags:
- "AlmaLinux"
- "Debian"
- "Fedora"
- "openSUSE Tumbleweed"
- "Raspbian"
- "Rocky"
- "Ubuntu"
- name: Remove T-Pot group (All)
group:
name: tpot
state: absent
when: ansible_distribution in ["AlmaLinux", "Debian", "Fedora", "openSUSE Tumbleweed", "Raspbian", "Rocky", "Ubuntu"]
tags:
- "AlmaLinux"
- "Debian"
- "Fedora"
- "openSUSE Tumbleweed"
- "Raspbian"
- "Rocky"
- "Ubuntu"
2023-06-26 02:59:52 +00:00
################################
# T-Pot - Remove Docker Engine #
################################
2023-06-26 02:59:52 +00:00
- name: T-Pot - Remove Docker Engine
2023-06-26 02:59:52 +00:00
hosts: all
gather_facts: true
become: true
tasks:
- name: Remove Docker Engine packages (openSUSE Tumbleweed)
2023-06-26 02:59:52 +00:00
package:
name:
- docker
- docker-bash-completion
- docker-buildx
- docker-compose
- docker-compose-switch
- liblvm2cmd2_03
- lvm2
state: absent
when: ansible_distribution in ["openSUSE Tumbleweed"]
tags:
- "openSUSE Tumbleweed"
- name: Remove Docker Engine packages (AlmaLinux, Debian, Fedora, Raspbian, Rocky, Ubuntu)
package:
name:
2023-06-26 02:59:52 +00:00
- docker-ce
- docker-ce-cli
- containerd.io
- docker-buildx-plugin
- docker-compose-plugin
state: absent
when: ansible_distribution in ["AlmaLinux", "Debian", "Fedora", "Raspbian", "Rocky", "Ubuntu"]
tags:
- "AlmaLinux"
- "Debian"
- "Fedora"
- "Raspbian"
- "Rocky"
- "Ubuntu"
2023-06-26 02:59:52 +00:00
######################################
# T-Pot - Remove Docker Engine Repos #
######################################
2023-06-26 02:59:52 +00:00
- name: T-Pot - Revert Docker Engine preparation
2023-06-26 02:59:52 +00:00
hosts: all
gather_facts: true
become: true
tasks:
- name: Remove Docker Engine repository (Debian, Raspbian, Ubuntu)
apt_repository:
filename: docker
2023-06-26 02:59:52 +00:00
state: absent
when: ansible_distribution in ["Debian", "Raspbian", "Ubuntu"]
tags:
- "Debian"
- "Raspbian"
- "Ubuntu"
- name: Remove Docker repository (Fedora)
shell: dnf -y config-manager --remove-repo https://download.docker.com/linux/fedora/docker-ce.repo
when: ansible_distribution in ["Fedora"]
tags:
- "Fedora"
- name: Remove Docker repository (AlmaLinux, Rocky)
shell: dnf -y config-manager --remove-repo https://download.docker.com/linux/centos/docker-ce.repo
when: ansible_distribution in ["AlmaLinux", "Rocky"]
tags:
- "AlmaLinux"
- "Rocky"
2023-06-26 02:59:52 +00:00