Playbook
The REDIS module provides two playbooks for deploying/removing Redis clusters/nodes/instances:
redis.yml: Deploy Redis cluster/node/instanceredis-rm.yml: Remove Redis cluster/node/instance
redis.yml
The redis.yml playbook for deploying Redis contains the following subtasks:
Operation Levels
redis.yml supports three operation levels, controlled by -l to limit target scope and -e redis_port=<port> to specify a single instance:
| Level | Parameters | Description |
|---|---|---|
| Cluster | -l <cluster> |
Deploy all nodes and instances of the entire Redis cluster |
| Node | -l <ip> |
Deploy all Redis instances on the specified node |
| Instance | -l <ip> -e redis_port=<port> |
Deploy only a single instance on the specified node |
Cluster-Level Operations
Deploy an entire Redis cluster, including all instances on all nodes:
Cluster-level operations will:
- Install Redis or Valkey according to
redis_type, plusredis-exporter, on all nodes - Create redis user and directory structure on all nodes
- Start redis_exporter on all nodes
- Deploy and start all defined Redis instances
- Register all instances to the monitoring system
- If
sentinelmode, configure sentinel monitoring targets - If
clustermode, form the native cluster
Node-Level Operations
Deploy only all Redis instances on the specified node:
Node-level operations are useful for:
- Scaling up by adding new nodes to an existing cluster
- Redeploying all instances on a specific node
- Reinitializing after node failure recovery
Note: Node-level commands still enter the
redis-ha/redis-joinmode checks. Sentinel mode refreshes managed targets. In cluster mode, the playbook first uses the selected CLI to check the seed instance forcluster_state:ok; it exits for a healthy cluster and otherwise runs--cluster create. This guard does not replace scale-out: useredis-cli/valkey-cli --cluster add-nodeandreshardmanually for an existing native cluster.
Instance-Level Operations
Use the -e redis_port=<port> parameter to operate on a single instance:
Instance-level operations are useful for:
- Adding new instances to an existing node
- Redeploying a single failed instance
- Updating a single instance’s configuration
When redis_port is specified:
- Only renders the config file for that port
- Only starts/restarts the systemd service for that port
- Rewrites the node’s monitoring registration file (content comes from the full
redis_instancesdefinition) - Does not start/stop
redis_exporteror reload Vector log config - Does not affect other Redis instance processes on the same node
Common Tags
Use the -t <tag> parameter to selectively execute certain tasks:
Idempotency
Most tasks in redis.yml can be run repeatedly, but native-cluster initialization still requires attention to topology state:
- Re-running
redis_node/redis_exporter/redis_instance/redis_registeroverwrites config and restarts instances - Re-running
redis-hareappliesSENTINEL REMOVE/MONITORbased onredis_sentinel_monitor redis-joinfirst checks whether the seed instance has reachedcluster_state:okand exits for a healthy cluster. The check does not repair incomplete or damaged topologies or perform scale-out, so do not treat it as a general add-node/reshard operation.
Tip: If you only want to update configs without restarting all instances, use
-t redis_configto render configs only, then manually restart the instances you need.
Redis/Valkey units use Type=notify. During startup, systemd waits up to 1800s for readiness so large RDB/AOF loads and recovery can finish. A timeout is not a reason to broaden data deletion or use a forced stop; inspect instance logs, data size, disk I/O, and memory first.
redis-rm.yml
The redis-rm.yml playbook for removing Redis contains the following subtasks:
Tag-scoped execution follows the data/package switches. -t redis always enters the instance-stop phase; -t redis_data stops instances only when redis_rm_data=true, and -t redis_pkg stops them only when redis_rm_pkg=true. Thus -t redis_data -e redis_rm_data=false and -t redis_pkg -e redis_rm_pkg=false do not stop Redis merely because the tag was selected. Before any real removal, verify the exact same -l, tags, and extra variables.
Operation Levels
redis-rm.yml also supports three operation levels:
| Level | Parameters | Description |
|---|---|---|
| Cluster | -l <cluster> |
Remove all nodes and instances of the entire Redis cluster |
| Node | -l <ip> |
Remove all Redis instances on the specified node |
| Instance | -l <ip> -e redis_port=<port> |
Remove only a single instance on the specified node |
Cluster-Level Removal
Remove an entire Redis cluster:
Cluster-level removal will:
- Deregister all instances on all nodes from the monitoring system
- Stop redis_exporter on all nodes
- Stop and disable all Redis instances
- Delete all data directories (if
redis_rm_data=true) - Uninstall the engine selected by
redis_typeandredis-exporter(ifredis_rm_pkg=true)
Node-Level Removal
Remove only all Redis instances on the specified node:
Node-level removal is useful for:
- Scaling down by removing an entire node
- Cleanup before node decommission
- Preparation before node migration
Node-level removal will:
- Deregister all instances on that node from the monitoring system
- Stop redis_exporter on that node
- Stop all Redis instances on that node
- Delete all data directories on that node
- Delete Vector logging config on that node
Instance-Level Removal
Use the -e redis_port=<port> parameter to remove a single instance:
Instance-level removal is useful for:
- Removing a single replica from a node
- Removing instances no longer needed
- Removing the original primary after failover
Behavioral differences when redis_port is specified:
| Component | Node-Level (no redis_port) | Instance-Level (with redis_port) |
|---|---|---|
| Monitoring registration | Delete entire node’s registration file | Only remove that instance from registration file |
| redis_exporter | Stop and disable | No operation (other instances still need it) |
| Redis instances | Stop all instances | Only stop the specified port’s instance |
| Data directory | Delete entire redis_fs_main (default: /data/redis/) |
Only delete redis_fs_main/<cluster>-<node>-<port>/ (if redis_fs_main=/data, removal is compat-mapped to /data/redis) |
| Vector config | Delete /etc/vector/redis.yaml |
No operation (other instances still need it) |
| Packages | Optionally uninstall | No operation |
Control Parameters
redis-rm.yml provides the following control parameters:
| Parameter | Default | Description |
|---|---|---|
redis_safeguard |
false |
Safety guard; when true, refuses to execute removal |
redis_rm_data |
true |
Whether to delete data directories (RDB/AOF files) |
redis_rm_pkg |
false |
Whether to uninstall the selected engine and redis-exporter |
Usage examples:
redis_safeguard defaults to false, while redis_rm_data defaults to true. The removal playbook also tolerates several service-stop, deregistration, data-deletion, and package-removal errors. After a real run, inspect the target processes, data directories, and monitoring registration; do not treat the playbook return status alone as proof of completion.
Safeguard Mechanism
When a cluster has redis_safeguard: true configured, redis-rm.yml will refuse to execute:
Explicit override is required to execute:
Quick Reference
Deployment Quick Reference
Removal Quick Reference
Wrapper Scripts
Pigsty provides convenient wrapper scripts:
Demo
Initialize Redis cluster with Redis playbook: