|
| 1 | +--- |
| 2 | +# This is the playbook version of the wazuh purge tool from: |
| 3 | +# https://github.com/stackhpc/wazuh-server-purge |
| 4 | + |
| 5 | +- name: Purge Wazuh Server Components |
| 6 | + hosts: wazuh-manager |
| 7 | + become: true |
| 8 | + become_user: root |
| 9 | + tasks: |
| 10 | +# Dashboard |
| 11 | + - name: Disable and stop wazuh-dashboard service |
| 12 | + ansible.builtin.systemd_service: |
| 13 | + name: wazuh-dashboard |
| 14 | + state: stopped |
| 15 | + enabled: no |
| 16 | + daemon_reload: true |
| 17 | + register: svc_result |
| 18 | + failed_when: |
| 19 | + - svc_result.failed |
| 20 | + - "'Could not find the requested service' not in svc_result.msg" |
| 21 | + |
| 22 | + - name: Remove wazuh-dashboard and files |
| 23 | + ansible.builtin.package: |
| 24 | + name: wazuh-dashboard |
| 25 | + state: absent |
| 26 | + |
| 27 | + - name: Remove wazuh-dashboard directories |
| 28 | + ansible.builtin.file: |
| 29 | + path: "{{ item }}" |
| 30 | + state: absent |
| 31 | + loop: |
| 32 | + - /var/lib/wazuh-dashboard |
| 33 | + - /usr/share/wazuh-dashboard |
| 34 | + - /etc/wazuh-dashboard |
| 35 | +# Manager |
| 36 | + - name: Remove wazuh-manager service |
| 37 | + ansible.builtin.systemd_service: |
| 38 | + name: wazuh-manager |
| 39 | + state: stopped |
| 40 | + enabled: no |
| 41 | + daemon_reload: true |
| 42 | + register: svc_result |
| 43 | + failed_when: |
| 44 | + - svc_result.failed |
| 45 | + - "'Could not find the requested service' not in svc_result.msg" |
| 46 | + |
| 47 | + - name: Remove wazuh-manager and files |
| 48 | + ansible.builtin.package: |
| 49 | + name: wazuh-manager |
| 50 | + state: absent |
| 51 | + |
| 52 | + - name: Remove wazuh-manager directories |
| 53 | + ansible.builtin.file: |
| 54 | + path: /var/ossec |
| 55 | + state: absent |
| 56 | +# Filebeat |
| 57 | + - name: Disable and stop filebeat service |
| 58 | + ansible.builtin.systemd_service: |
| 59 | + name: filebeat |
| 60 | + state: stopped |
| 61 | + enabled: no |
| 62 | + daemon_reload: true |
| 63 | + register: svc_result |
| 64 | + failed_when: |
| 65 | + - svc_result.failed |
| 66 | + - "'Could not find the requested service' not in svc_result.msg" |
| 67 | + |
| 68 | + - name: Remove filebeat and files |
| 69 | + ansible.builtin.package: |
| 70 | + name: filebeat |
| 71 | + state: absent |
| 72 | + |
| 73 | + - name: Remove filebeat directories |
| 74 | + ansible.builtin.file: |
| 75 | + path: "{{ item }}" |
| 76 | + state: absent |
| 77 | + loop: |
| 78 | + - /var/lib/filebeat |
| 79 | + - /usr/share/filebeat |
| 80 | + - /etc/filebeat |
| 81 | +# Indexer |
| 82 | + - name: Disable and stop wazuh-indexer service |
| 83 | + ansible.builtin.systemd_service: |
| 84 | + name: wazuh-indexer |
| 85 | + state: stopped |
| 86 | + enabled: no |
| 87 | + daemon_reload: true |
| 88 | + register: svc_result |
| 89 | + failed_when: |
| 90 | + - svc_result.failed |
| 91 | + - "'Could not find the requested service' not in svc_result.msg" |
| 92 | + |
| 93 | + - name: Remove wazuh-indexer and files |
| 94 | + ansible.builtin.package: |
| 95 | + name: wazuh-indexer |
| 96 | + state: absent |
| 97 | + |
| 98 | + - name: Remove wazuh-indexer directories |
| 99 | + ansible.builtin.file: |
| 100 | + path: "{{ item }}" |
| 101 | + state: absent |
| 102 | + loop: |
| 103 | + - /var/lib/wazuh-indexer |
| 104 | + - /usr/share/wazuh-indexer |
| 105 | + - /etc/wazuh-indexer |
0 commit comments