Playbooks

Run idempotent playbooks to install modules on nodes.

Playbooks are used in Pigsty to install modules on nodes.To run playbooks, just treat them as executables.

e.g. run with ./install.yml.

Playbooks

Here are default playbooks included in Pigsty.

PlaybookFunction
install.ymlInstall Pigsty on current node in one-pass
infra.ymlInit pigsty infrastructure on infra nodes
infra-rm.ymlRemove infrastructure components from infra nodes
node.ymlInit node for pigsty, tune node into desired status
node-rm.ymlRemove node from pigsty
pgsql.ymlInit HA PostgreSQL clusters, or adding new replicas
pgsql-rm.ymlRemove PostgreSQL cluster, or remove replicas
pgsql-user.ymlAdd new business user to existing PostgreSQL cluster
pgsql-db.ymlAdd new business database to existing PostgreSQL cluster
pgsql-monitor.ymlMonitor remote postgres instance with local exporters
pgsql-migration.ymlGenerate Migration manual & scripts for existing PostgreSQL
redis.ymlInit redis cluster/node/instance
redis-rm.ymlRemove redis cluster/node/instance
etcd.ymlInit etcd cluster (required for patroni HA DCS)
minio.ymlInit minio cluster (optional for pgbackrest repo)
cert.ymlIssue cert with pigsty self-signed CA (e.g. for pg clients)
docker.ymlInstall docker on nodes

One-Pass Install

The special playbook install.yml is actually a composed playbook that install everything on current environment.

  1. playbook / command / group infra nodes etcd minio pgsql
  2. [infra.yml] ./infra.yml [-l infra] [+infra][+node]
  3. [node.yml] ./node.yml [+node] [+node] [+node] [+node]
  4. [etcd.yml] ./etcd.yml [-l etcd ] [+etcd]
  5. [minio.yml] ./minio.yml [-l minio] [+minio]
  6. [pgsql.yml] ./pgsql.yml [+pgsql]

Note that there’s a 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.

The solution is that INFRA playbook will also install NODE module in addition to INFRA on infra nodes. Make sure that infra nodes are init first.

Ansible

Playbooks require ansible-playbook executable to run, playbooks which is included in ansible package.

Pigsty will install ansible on admin node during bootstrap.

You can install it by yourself with yum install ansible or brew install ansible, it is included in default OS repo.

Knowledge about ansible is good but not required. Only three parameters needs your attention:

  • -l|--limit <pattern> : Limit execution target on specific group/host/pattern (Where)
  • -t|--tags <tags>: Only run tasks with specific tags (What)
  • -e|--extra-vars <vars>: Extra command line arguments (How)

Limit Host

The target of playbook can be limited with -l|-limit <selector>.

Missing this value could be dangerous since most playbooks will execute on all host, DO USE WITH CAUTION.

Here are some examples of host limit:

  1. ./pgsql.yml # run on all hosts (very dangerous!)
  2. ./pgsql.yml -l pg-test # run on pg-test cluster
  3. ./pgsql.yml -l 10.10.10.10 # run on single host 10.10.10.10
  4. ./pgsql.yml -l pg-* # run on host/group matching glob pattern `pg-*`
  5. ./pgsql.yml -l '10.10.10.11,&pg-test' # run on 10.10.10.10 of group pg-test
  6. /pgsql-rm.yml -l 'pg-test,!10.10.10.11' # run on pg-test, except 10.10.10.11
  7. ./pgsql.yml -l pg-test # Execute the pgsql playbook against the hosts in the pg-test cluster

Limit Tags

You can execute a subset of playbook with -t|--tags <tags>.

You can specify multiple tags in comma separated list, e.g. -t tag1,tag2.

If specified, tasks with given tags will be executed instead of entire playbook.

Here are some examples of task limit:

  1. ./pgsql.yml -t pg_clean # cleanup existing postgres if necessary
  2. ./pgsql.yml -t pg_dbsu # setup os user sudo for postgres dbsu
  3. ./pgsql.yml -t pg_install # install postgres packages & extensions
  4. ./pgsql.yml -t pg_dir # create postgres directories and setup fhs
  5. ./pgsql.yml -t pg_util # copy utils scripts, setup alias and env
  6. ./pgsql.yml -t patroni # bootstrap postgres with patroni
  7. ./pgsql.yml -t pg_user # provision postgres business users
  8. ./pgsql.yml -t pg_db # provision postgres business databases
  9. ./pgsql.yml -t pg_backup # init pgbackrest repo & basebackup
  10. ./pgsql.yml -t pgbouncer # deploy a pgbouncer sidecar with postgres
  11. ./pgsql.yml -t pg_vip # bind vip to pgsql primary with vip-manager
  12. ./pgsql.yml -t pg_dns # register dns name to infra dnsmasq
  13. ./pgsql.yml -t pg_service # expose pgsql service with haproxy
  14. ./pgsql.yml -t pg_exporter # expose pgsql service with haproxy
  15. ./pgsql.yml -t pg_register # register postgres to pigsty infrastructure
  16. # run multiple tasks: reload postgres & pgbouncer hba rules
  17. ./pgsql.yml -t pg_hba,pgbouncer_hba,pgbouncer_reload
  18. # run multiple tasks: refresh haproxy config & reload it
  19. ./node.yml -t haproxy_config,haproxy_reload

Extra Vars

Extra command-line args can be passing via -e|-extra-vars KEY=VALUE.

It has the highest precedence over all other definition.

Here are some examples of extra vars

  1. ./node.yml -e ansible_user=admin -k -K # run playbook as another user (with admin sudo password)
  2. ./pgsql.yml -e pg_clean=true # force purging existing postgres when init a pgsql instance
  3. ./pgsql-rm.yml -e pg_uninstall=true # explicitly uninstall rpm after postgres instance is removed
  4. ./redis.yml -l 10.10.10.11 -e redis_port=6501 -t redis # init a specific redis instance: 10.10.10.11:6501
  5. ./redis-rm.yml -l 10.10.10.13 -e redis_port=6501 # remove a specific redis instance: 10.10.10.11:6501

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

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

Last modified 2023-02-27: add v2.0 images and docs (5b09f12)