From 4f71632519574c36b3b5c36ae4068d49f83244de Mon Sep 17 00:00:00 2001 From: Someone Date: Fri, 4 Oct 2024 13:42:29 +0200 Subject: [PATCH] [roles/cleanup] Cleanup stuff. Levels above 5 should be followed by or part of a full somesible run --- roles/cleanup/defaults/main.yml | 11 +++++ roles/cleanup/tasks/main.yml | 71 +++++++++++++++++++++++++++++ roles/cleanup/tasks/run-command.yml | 16 +++++++ 3 files changed, 98 insertions(+) create mode 100644 roles/cleanup/defaults/main.yml create mode 100644 roles/cleanup/tasks/main.yml create mode 100644 roles/cleanup/tasks/run-command.yml diff --git a/roles/cleanup/defaults/main.yml b/roles/cleanup/defaults/main.yml new file mode 100644 index 0000000..36afdec --- /dev/null +++ b/roles/cleanup/defaults/main.yml @@ -0,0 +1,11 @@ +##################################### +### someone's ansible provisioner ### +##################################### +# Part of: https://git.somenet.org/root/pub/somesible.git +# 2017-2024 by someone +# +# If not overridden in inventory or as a parameter, this is the value that will be used +# +--- +# level > 5 should be followed by or part of a full somesible run. +cleanup_level: 1 diff --git a/roles/cleanup/tasks/main.yml b/roles/cleanup/tasks/main.yml new file mode 100644 index 0000000..f397642 --- /dev/null +++ b/roles/cleanup/tasks/main.yml @@ -0,0 +1,71 @@ +##################################### +### someone's ansible provisioner ### +##################################### +# Part of: https://git.somenet.org/root/pub/somesible.git +# 2017-2024 by someone +# +# cleanup stuff. +# The aggressive mode should be followed by or part of a full somesible run. +# +--- +- name: cleanup /var/ansible/.ansible + file: + path: "/var/ansible/.ansible" + state: absent + changed_when: False + + +- name: cleanup apt download cache (TEMP) + include_tasks: run-command.yml + vars: + cmd: 'apt-get clean' + when: 'cleanup_level|int >= 2' + + +- name: cleanup old logfiles (543210 min = 377.23 days) + include_tasks: run-command.yml + vars: + cmd: 'find /var/log/ -type f -mmin +543210 -print -delete' + when: 'cleanup_level|int >= 3' + + +- name: cleanup old dist-files + include_tasks: run-command.yml + vars: + cmd: 'find /etc \( -name "*.dpkg-*" -o -name "*.ucf-*" -o -name "*.merge-error" \) -print -delete' + when: 'cleanup_level|int >= 5' + + +- name: cleanup old anope db files (543210 min = 377.23 days) + include_tasks: run-command.yml + vars: + cmd: 'find /srv/anope/db/backups -type f -mmin +543210 -print -delete' + when: 'cleanup_level|int >= 5' + + +################################################### +# cleanup possibly stale configs generated by us. # +################################################### +- name: remove systemd presets + include_tasks: run-command.yml + vars: + cmd: 'rm -vf /etc/systemd/system-preset/*-somesible-*' + when: 'cleanup_level|int >= 6' + + +# level 7 can cause issues by skipping over stuff if run at the wrong time. + +- name: remove all awstat configs + include_tasks: run-command.yml + vars: + cmd: 'rm -vf /etc/awstats/awstats.*.conf' + when: 'cleanup_level|int >= 7' + + +# level 9 is expected to cause downtimes + the need to run multiple times/manually start (now/temp.) broken services. + +- name: remove all vhost configs + include_tasks: run-command.yml + vars: + cmd: 'rm -vf /etc/nginx/sites-enabled/*.vhost' + when: 'cleanup_level|int >= 9' diff --git a/roles/cleanup/tasks/run-command.yml b/roles/cleanup/tasks/run-command.yml new file mode 100644 index 0000000..504b00f --- /dev/null +++ b/roles/cleanup/tasks/run-command.yml @@ -0,0 +1,16 @@ +##################################### +### someone's ansible provisioner ### +##################################### +# Part of: https://git.somenet.org/root/pub/somesible.git +# 2017-2024 by someone +# +--- +- name: run "{{cmd}}" + shell: "{{cmd}}" + register: cmd_output + ignore_errors: True + + +- name: result of "{{cmd}}" + debug: + msg: "{{cmd_output.stdout_lines}}" -- 2.43.0