PIGSTY

Playbook

Run playbooks with ansible

Pigsty implements admin controllers with idempotent Ansible playbooks. Playbooks require the ansible-playbook executable bin in your PATH. You'll have to install ansible to run playbooks.

Here are built-in playbooks in Pigsty, you can also add your own.

ModulePlaybookFunction
INFRAinstall.ymlInstall Pigsty on current node in one-pass
INFRAinfra.ymlInit pigsty infrastructure on infra nodes
INFRAinfra-rm.ymlRemove infrastructure components from infra nodes
INFRAcache.ymlMake offline install packages from target node
INFRAcert.ymlIssue cert with pigsty self-signed CA (e.g. for pg clients)
NODEnode.ymlInit node for pigsty, tune node into desired status
NODEnode-rm.ymlRemove node from pigsty
PGSQLpgsql.ymlInit HA PostgreSQL clusters, or adding new replicas
PGSQLpgsql-rm.ymlRemove PostgreSQL cluster, or remove replicas
PGSQLpgsql-user.ymlAdd new business user to existing PostgreSQL cluster
PGSQLpgsql-db.ymlAdd new business database to existing PostgreSQL cluster
PGSQLpgsql-monitor.ymlMonitor remote postgres instance with local exporters
PGSQLpgsql-migration.ymlGenerate Migration manual & scripts for existing PostgreSQL
PGSQLslim.ymlInstall Pigsty with minimal components
REDISredis.ymlInit redis cluster/node/instance
REDISredis-rm.ymlRemove redis cluster/node/instance
ETCDetcd.ymlInit etcd cluster (required for patroni HA DCS)
MINIOminio.ymlInit minio cluster (optional for pgbackrest repo)
DOCKERdocker.ymlInstall docker on nodes
DOCKERapp.ymlInstall application with docker compose
FERRETmongo.ymlInstall Mongo/FerretDB on nodes

Deployment

The special playbook install.yml will deploy everything with ad hoc playbooks:

PlaybookCommandGroupinfra[nodes]etcdminio[pgsql]
infra.yml./infra.yml-l infra
node.yml./node.yml
etcd.yml./etcd.yml-l etcd
minio.yml./minio.yml-l minio
pgsql.yml./pgsql.yml

Circular Dependency Between NODE and INFRA

There is a weak circular dependency between NODE and INFRA: to register a NODE to INFRA, the INFRA should already exist, while the INFRA module relies on NODE to work.

One way to work around it is to init infra nodes first, then add other nodes, if you wish to deploy them all in one-pass, install.yml is the way to go.


Safety Considerations

Idempotent but Potentially Destructive

Most playbooks are idempotent, meaning that some deployment playbooks may erase existing databases and create new ones without the protection option turned on. Especially care with pgsql, minio, and infra playbooks.

Please read the documentation carefully and operate with caution. The author is not responsible for any loss of databases due to misuse.

Safety Best Practices

  1. Read playbook documentation carefully before execution
  2. Ctrl-C to stop immediately if you see something wrong
  3. Start with non-production environments for testing
  4. Limit execution hosts (-l) to avoid unintended hosts if applicable
  5. Use specific tags (-t) to run subset of tasks if possible

Dry Run Mode

# Preview what would be changed without actually executing
./pgsql.yml -l pg-test --check --diff

# Combine with tags to check specific tasks
./pgsql.yml -l pg-test -t pg_config --check --diff