# Playbook

> control primitives
---

There’s a built-in playbook: [`etcd.yml`](https://github.com/pgsty/pigsty/blob/v3.7.0/etcd.yml) for etcd cluster installation.

------

## `etcd.yml`

To [create a new etcd cluster](/docs/etcd/admin/#create-cluster), run the following playbook:

```bash tab="playbook"
./etcd.yml    # install etcd cluster on group 'etcd'
```
```bash tab="script"
bin/etcd-add    # create entire etcd cluster
```

Here are available sub tasks:

- `etcd_assert` : generate etcd identity
- `etcd_install` : install etcd rpm packages
- `etcd_dir` : create etcd data & conf dir
- `etcd_config` : generate etcd config
  - `etcd_conf` : generate etcd main config
  - `etcd_cert` : generate etcd ssl cert
- `etcd_launch` : launch etcd service
- `etcd_register` : register etcd to prometheus

If you want to [**append a new member**](/docs/etcd/admin/#append-member) to an existing etcd cluster,
you have to add it to the [config inventory](/docs/config/inventory), and run the playbook with [`etcd_init`](/docs/etcd/param/#etcd_init) = `existing`
against the new member:

```bash tab="playbook"
./etcd.yml -l <new_instance> -e etcd_init=existing
```
```bash tab="script"
bin/etcd-add <ip> # append new members to existing etcd cluster
```

It's usually OK to re-run the playbook, it will update the etcd cluster config and restart etcd instances.

**Change Since Pigsty v3.6&#43;**

Since Pigsty v3.6&#43;, the `etcd.yml` playbook no longer has cluster removal capabilities. Use the dedicated `etcd-rm.yml` playbook and `etcd_remove` role for etcd cluster removal operations.




------

## `etcd-rm.yml`

To [remove the etcd cluster](/docs/etcd/admin/#remove-cluster), run the following playbook:

```bash
./etcd-rm.yml    # remove etcd cluster
```

Here are available sub tasks:

- `etcd_safeguard` : check safeguard and abort if enabled
- `prometheus`     : remove etcd targets registration from prometheus
- `etcd_leave`     : try graceful leaving etcd cluster before purge
- `etcd_stop`      : 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`)

To [**remove a member**](/docs/etcd/admin/#remove-member) from an existing etcd cluster, you can run the playbook

```bash tab="playbook"
./etcd-rm.yml -l <ip>
```
```bash tab="script"
bin/etcd-rm <ip>    # remove specific members from etcd cluster
bin/etcd-rm         # remove entire etcd cluster
```

The removal playbook uses the new **etcd_remove** role with configurable parameters:

- [`etcd_safeguard`](/docs/etcd/param#etcd_safeguard): Prevents accidental removal when set to `true`
- [`etcd_rm_data`](/docs/etcd/param#etcd_rm_data): Controls whether ETCD data is deleted (`true` by default)
- [`etcd_rm_pkg`](/docs/etcd/param#etcd_rm_pkg): Controls whether ETCD packages are uninstalled (`false` by default)
