# Playbook

> control primitives
---

There are three playbooks related to the INFRA module:

- [`infra.yml`](#infrayml): Initialize Pigsty infrastructure on infra nodes
- [`infra-rm.yml`](#infra-rmyml): Remove infrastructure components from infra nodes
- [`install.yml`](#installyml): Perform a complete one-time installation of Pigsty on the current node



------

## `infra.yml`

The INFRA module playbook [`infra.yml`](https://github.com/pgsty/pigsty/blob/v3.7.0/infra.yml) initializes the infrastructure module on [**Infra nodes**](/docs/node/arch#infra-node) defined in the `infra` group of your config file.

**This playbook performs the following tasks:**

- Configures directories and environment variables on Infra nodes
- Downloads and creates a local software repository to accelerate subsequent installations (skipped if offline packages are used or if a local repository already exists)
- Incorporates the current Infra node as a [common node](/docs/node/arch#common-node) managed by Pigsty
- Deploys **infrastructure** components, including Prometheus, Grafana, Loki, Alertmanager, PushGateway, Blackbox Exporter, etc.

**This playbook executes on the [`infra`](/docs/node/arch#infra-node) group by default:**

- Pigsty installs the [**`INFRA`**](/docs/infra/) module on the group named `infra` in the config file
- During [configure](/docs/config/configure), Pigsty marks the current installation node as an Infra node and replaces the placeholder IP address `10.10.10.10` in the config template with the [**current node’s primary IP address**](/docs/prepare/hardware#network)
- This node can initiate management tasks and host infrastructure components while functioning like any regular managed node

**Playbook notes:**

- This is an idempotent playbook - repeated execution will overwrite infra components on Infra nodes
  - Unless [`prometheus_clean`](/docs/infra/param#prometheus_clean) is set to `false`, Prometheus time series metrics will be lost
  - Unless [`loki_clean`](/docs/infra/param#loki_clean) is set to `false`, Loki log data will be lost
  - Unless [`grafana_clean`](/docs/infra/param#grafana_clean) is set to `false`, Grafana dashboards and configuration changes will be lost

- When the local software repo `/www/pigsty/repo_complete` exists, this playbook skips downloading software from the internet
  - Complete execution takes approximately 1 ~ 3 minutes, depending on machine configuration and network conditions
  - Downloading software directly from the original upstream sources (without using offline packages) may take 5-10 minutes, depending on your network connection

### Demo

[![asciicast](/img/asciinema/infra.svg)](https://asciinema.org/a/566412)

### Available Tasks

Here’s the list of available tasks in the `infra.yml` playbook:

```yaml
#--------------------------------------------------------------#
# Tasks
#--------------------------------------------------------------#
# ca            : create self-signed CA in localhost files/pki
#   - ca_dir        : create CA directory
#   - ca_private    : generate CA private key: files/pki/ca/ca.key
#   - ca_cert       : sign CA certificate: files/pki/ca/ca.crt
#
# id            : generate node identity
#
# repo          : bootstrap a local YUM repository from internet or offline packages
#   - repo_dir      : create repository directory
#   - repo_check    : check repository exists
#   - repo_prepare  : use existing repository if exists
#   - repo_build    : build repository from upstream if not exists
#     - repo_upstream    : handle upstream repository files in /etc/yum.repos.d
#       - repo_remove    : remove existing repository file if repo_remove == true
#       - repo_add       : add upstream repository files to /etc/yum.repos.d
#     - repo_url_pkg     : download packages from internet defined by repo_url_packages
#     - repo_cache       : make upstream YUM cache with yum makecache
#     - repo_boot_pkg    : install bootstrap packages such as createrepo_c, yum-utils, etc.
#     - repo_pkg         : download packages & dependencies from upstream repository
#     - repo_create      : create a local YUM repository with createrepo_c & modifyrepo_c
#     - repo_use         : add newly built repository into /etc/yum.repos.d
#   - repo_nginx    : launch nginx for repository if no nginx is serving
#
# node/haproxy/docker/monitor : set up infra node as a common node (check node.yml)
#   - node_name, node_hosts, node_resolv, node_firewall, node_ca, node_repo, node_pkg
#   - node_feature, node_kernel, node_tune, node_sysctl, node_profile, node_ulimit
#   - node_data, node_admin, node_timezone, node_ntp, node_crontab, node_vip
#   - haproxy_install, haproxy_config, haproxy_launch, haproxy_reload
#   - docker_install, docker_admin, docker_config, docker_launch, docker_image
#   - haproxy_register, node_exporter, node_register, promtail
#
# infra         : set up infra components
#   - infra_env      : env_dir, env_pg, env_pgadmin, env_var
#   - infra_pkg      : infra_pkg_yum, infra_pkg_pip
#   - infra_user     : set up infra OS user group
#   - infra_cert     : issue certificate for infra components
#   - dns            : dns_config, dns_record, dns_launch
#   - nginx          : nginx_config, nginx_cert, nginx_static, nginx_launch, nginx_certbot, nginx_reload, nginx_exporter
#   - prometheus     : prometheus_clean, prometheus_dir, prometheus_config, prometheus_launch, prometheus_reload
#   - alertmanager   : alertmanager_config, alertmanager_launch
#   - pushgateway    : pushgateway_config, pushgateway_launch
#   - blackbox       : blackbox_config, blackbox_launch
#   - grafana        : grafana_clean, grafana_config, grafana_launch, grafana_provision
#   - loki           : loki clean, loki_dir, loki_config, loki_launch
#   - infra_register : register infra components to prometheus
#--------------------------------------------------------------#
```




------

## `infra-rm.yml`

The INFRA module playbook [`infra-rm.yml`](https://github.com/pgsty/pigsty/blob/v3.7.0/infra-rm.yml) removes Pigsty infrastructure from [Infra nodes](/docs/node/arch#infra-node) defined in the `infra` group of your config file.

Common subtasks include:

```bash
./infra-rm.yml               # Remove the INFRA module
./infra-rm.yml -t service    # Stop infrastructure services on INFRA
./infra-rm.yml -t data       # Remove retained data on INFRA
./infra-rm.yml -t package    # Uninstall packages installed on INFRA
```






------

## `install.yml`

The INFRA module playbook [`install.yml`](https://github.com/pgsty/pigsty/blob/v3.7.0/install.yml) performs a complete one-time installation of Pigsty on **all nodes**.

This playbook is described in more detail in [Playbook: One-Pass Deployment](/docs/admin/playbook#deployment).
