#!/usr/bin/env ansible-playbook
---
#==============================================================#
# File      :   etcd-rm.yml
# Desc      :   remove etcd from hosts
# Ctime     :   2025-07-20
# Mtime     :   2025-12-31
# Path      :   etcd-rm.yml
# Docs      :   https://pigsty.io/docs/etcd/playbook
# License   :   Apache-2.0 @ https://pigsty.io/docs/about/license/
# Copyright :   2018-2026  Ruohang Feng / Vonng (rh@vonng.com)
#==============================================================#
- name: ETCD REMOVE
  become: true
  hosts: etcd
  gather_facts: no
  ignore_errors: true
  vars:
    #etcd_safeguard: true              # safeguard for etcd remove, set to true halt remove execution
    #etcd_rm_data: true                # remove etcd data during remove? true by default
    #etcd_rm_pkg: false                # uninstall etcd packages during remove? false by default
  roles: [ { role: node_id }, { role: etcd_remove } ]


#--------------------------------------------------------------#
# Usage
#--------------------------------------------------------------#
#  Remove etcd cluster `etcd`
#     etcd-rm.yml -l etcd           # remove cluster `etcd`
#         -e etcd_rm_data=true      # remove etcd data by default
#         -e etcd_rm_pkg=false      # do not uninstall etcd packages by default
#         -e etcd_safeguard=false   # safeguard is not enabled by default, if enabled, can be override with cli args
#  It will abort if `etcd_safeguard` is set to `true` explicitly
#
#  Remove a etcd member:
#     ./etcd-rm.yml -l 10.10.10.12  # remove instance `10.10.10.12` from cluster `etcd`
#     vi pigsty.yml                 # remove the `10.10.10.12` from `etcd` cluster in `pigsty.yml`
#     ./etcd.yml                    # refresh etcd cluster after member removal
#
#--------------------------------------------------------------#
# Utils
#--------------------------------------------------------------#
# bin/etcd-rm                # remove the entire etcd cluster
# bin/etcd-rm 10.10.10.13    # remove member `10.10.10.13` from etcd cluster
#
#--------------------------------------------------------------#
# Tasks
#--------------------------------------------------------------#
# etcd_safeguard  : check safeguard and abort if enabled
# etcd_pause      : pause for confirmation (3s)
# etcd_deregister : remove etcd targets from victoria-metrics
# etcd_leave      : try graceful leaving etcd cluster before purging
# etcd_svc        : stop and disable etcd service with systemd
# etcd_data       : remove etcd data (disable with `etcd_rm_data=false`)
# etcd_pkg        : uninstall etcd packages (enable with `etcd_rm_pkg=true`)
#--------------------------------------------------------------#
...