---
- name: ETCD | Completely uninstall the etcd service and remove all related files
  block:
    - name: ETCD | Stop and disable the etcd systemd service
      ignore_errors: true
      command: |
        systemctl stop etcd.service
        systemctl disable etcd.service
        rm -rf /etc/systemd/system/etcd.service*
        systemctl daemon-reload
        systemctl reset-failed etcd.service
    - name: ETCD | Remove traffic priority rules for etcd ports
      command: |
        tc filter del dev eth0 parent 1: protocol ip prio 1 u32 match ip sport 2379 0xffff
        tc filter del dev eth0 parent 1: protocol ip prio 1 u32 match ip sport 2380 0xffff
      when: .etcd.traffic_priority
    - name: ETCD | Delete all etcd data, configuration, and binaries
      command: |
        rm -rf {{ .etcd.env.data_dir }}
        rm -rf /etc/ssl/etcd/
        rm -rf /etc/etcd.env
        rm -rf /usr/local/bin/etcd*

- name: ETCD | Uninstall backup-etcd timer and service, and remove backup scripts
  ignore_errors: true
  command: |
    systemctl disable --now backup-etcd.timer
    rm /etc/systemd/system/backup-etcd.timer
    rm -rf /etc/systemd/system/backup-etcd.service*
    rm /usr/local/bin/kube-scripts/backup_etcd.sh
    systemctl daemon-reexec && systemctl daemon-reload
