# Inventory

> The main config file for Pigsty
---

Each pigsty deployment has a corresponding config **inventory**.
It could be stored in a local config file in YAML format, or dynamically generated from [CMDB](https://docs.ansible.com/ansible/2.9/user_guide/intro_dynamic_inventory.html) or any ansible compatible format.
Pigsty uses one monolith YAML config file by default, which is [`pigsty.yml`](https://github.com/pgsty/pigsty/blob/v3.7.0/pigsty.yml), [located](https://github.com/pgsty/pigsty/blob/v3.7.0/ansible.cfg#L3) in the pigsty home directory.

- **`pigsty/`**
  - [`pigsty.yml`](https://github.com/pgsty/pigsty/blob/v3.7.0/pigsty.yml)
  - [`ansible.cfg`](https://github.com/pgsty/pigsty/blob/v3.7.0/ansible.cfg)

The [`configure`](/docs/config/configure) script will generate the `pigsty.yml` file scaffold with good defaults according to your env and input,
but it's **OPTIONAL**: you can always edit the `pigsty.yml` file directly as the [**tutorial**](/docs/config/tutorial) shows.


--------

## Structure

The inventory consists of two parts: **global vars**  & multiple **groups**. You can define new clusters in `all.children`.
And describe infra with global vars: `all.vars`. Which may look like this:

```yaml
all:                  # Top-level object: all
  vars: {...}         # Global Parameters
  children:           # Group Definitions
    infra:            # Group Definition: 'infra'
      hosts: {...}        # Group Membership: 'infra'
      vars:  {...}        # Group Parameters: 'infra'
    etcd:    {...}    # Group Definition: 'etcd'
    pg-meta: {...}    # Group Definition: 'pg-meta'
    pg-test: {...}    # Group Definition: 'pg-test'
    redis-test: {...} # Group Definition: 'redis-test'
    # ...
```

There are plenty of examples under [`conf/`](https://github.com/pgsty/pigsty/blob/v3.7.0/conf/README.md), which can also be used as templates during `configure`.

------

## Cluster

Each ansible group may represent a cluster, which could be a Node cluster, PostgreSQL cluster, Redis cluster, Etcd cluster, or Minio cluster, etc…

Cluster definition consists of two parts: **hosts** & **vars**.
You can define cluster members in `<cls>.hosts` and describe cluster with parameters in `<cls>.vars`.
Here's an example of a 3-node HA PG cluster:

```yaml
all:
  children:    # All Groups
    pg-test:   # Group Name
      hosts:   # Group Host (Cluster Membership)
        10.10.10.11: { pg_seq: 1, pg_role: primary } # Host1
        10.10.10.12: { pg_seq: 2, pg_role: replica } # Host2
        10.10.10.13: { pg_seq: 3, pg_role: offline } # Host3
      vars:    # Group Vars (Cluster Parameters)
        pg_cluster: pg-test
```

The `vars` in cluster level will override the global vars, and `vars` in host level will override the cluster vars and global vars.



------

## Parameter

Parameters are key-value pairs that define all entities in the deployment.
The key is a string name, and the value can be one of five types: boolean, string, number, array, or object.

And parameters can be set at different levels with the following precedence:

| Level       | Location                   | Description                                   | Precedence  |
|:------------|:---------------------------|:----------------------------------------------|:------------|
| CLI Args    | Command Line               | via `-e` cli param arg                        | Highest (5) |
| Host Vars   | `<group>.hosts.<host>`     | Parameters specific to a single host          | High (4)    |
| Group Vars  | `<group>.vars`             | Parameters shared by hosts in a group/cluster | Medium (3)  |
| Global Vars | `all.vars`                 | Parameters shared by all hosts                | Low (2)     |
| Defaults    | `<roles>/default/main.yml` | Role implementation default values            | Lowest (1)  |

Here are some examples about parameter precedence:

- Override the PostgreSQL major version with Playbook CLI Args `-e pg_version=16`
- Override pg instance role with Instance Level Parameter `pg_role` on Host Vars
- Override pg cluster name with Cluster Level Parameter `pg_cluster` on Group Vars.
- Specify global NTP servers with Global Parameter `node_ntp_servers` on Global Vars
- If no `pg_version` is set, pigsty will use the default value from role implementation (`18` by default)


Every parameter has a proper default value except for mandatory **IDENTITY PARAMETERS**; they are used as identifiers and must be set explicitly.
Such as [`pg_cluster`](/docs/pgsql/param#pg_cluster), [`pg_role`](/docs/pgsql/param#pg_role), and [`pg_seq`](/docs/pgsql/param#pg_seq) in above snippet.


Available parameters vary according to the modules:

| [<span class="text-sky-600 font-bold">PGSQL</span>](/docs/pgsql/param) | [<span class="text-green-700 font-bold">INFRA</span>](/docs/infra/param) |  [<span class="text-amber-500 font-bold">NODE</span>](/docs/node/param)   |   [<span class="text-sky-400 font-bold">ETCD</span>](/docs/etcd/param)    |
|:----------------------------------------------------------------------------:|:------------------------------------------------------------------------------:|:-------------------------------------------------------------------------------:|:-------------------------------------------------------------------------------:|
| [<span class="text-red-800 font-bold">MINIO</span>](/docs/minio/param) |  [<span class="text-red-400 font-bold">REDIS</span>](/docs/redis/param)  | [<span class="text-blue-500 font-bold">DOCKER</span>](/docs/docker/param) | [<span class="text-gray-500 font-bold">FERRET</span>](/docs/ferret/param) |



------

## Reference

Pigsty has **290+** parameters, check module parameters for details.

| Module                         | Section                                            | Description                         | Count |
|--------------------------------|----------------------------------------------------|-------------------------------------|-------|
| [`INFRA`](/docs/infra/param)   | [`META`](/docs/infra/param#meta)                   | Pigsty Metadata                     | 4     |
| [`INFRA`](/docs/infra/param)   | [`CA`](/docs/infra/param#ca)                       | Self-Signed CA                      | 3     |
| [`INFRA`](/docs/infra/param)   | [`INFRA_ID`](/docs/infra/param#infra_id)           | Infra Portals & Identity            | 2     |
| [`INFRA`](/docs/infra/param)   | [`REPO`](/docs/infra/param#repo)                   | Local Software Repo                 | 9     |
| [`INFRA`](/docs/infra/param)   | [`INFRA_PACKAGE`](/docs/infra/param#infra_package) | Infra Packages                      | 2     |
| [`INFRA`](/docs/infra/param)   | [`NGINX`](/docs/infra/param#nginx)                 | Nginx Web Server                    | 7     |
| [`INFRA`](/docs/infra/param)   | [`DNS`](/docs/infra/param#dns)                     | DNSMASQ Nameserver                  | 3     |
| [`INFRA`](/docs/infra/param)   | [`PROMETHEUS`](/docs/infra/param#prometheus)       | Prometheus Stack                    | 18    |
| [`INFRA`](/docs/infra/param)   | [`GRAFANA`](/docs/infra/param#grafana)             | Grafana Stack                       | 6     |
| [`INFRA`](/docs/infra/param)   | [`LOKI`](/docs/infra/param#loki)                   | Loki Logging Service                | 4     |
| [`NODE`](/docs/node/param)     | [`NODE_ID`](/docs/node/param#node_id)              | Node Identity Parameters            | 5     |
| [`NODE`](/docs/node/param)     | [`NODE_DNS`](/docs/node/param#node_dns)            | Node domain names & resolver        | 6     |
| [`NODE`](/docs/node/param)     | [`NODE_PACKAGE`](/docs/node/param#node_package)    | Node Repo & Packages                | 5     |
| [`NODE`](/docs/node/param)     | [`NODE_TUNE`](/docs/node/param#node_tune)          | Node Tuning & Kernel features       | 10    |
| [`NODE`](/docs/node/param)     | [`NODE_ADMIN`](/docs/node/param#node_admin)        | Admin User & Credentials            | 7     |
| [`NODE`](/docs/node/param)     | [`NODE_TIME`](/docs/node/param#node_time)          | Node Timezone, NTP, Crontabs        | 5     |
| [`NODE`](/docs/node/param)     | [`NODE_VIP`](/docs/node/param#node_vip)            | Node Keepalived L2 VIP              | 8     |
| [`NODE`](/docs/node/param)     | [`HAPROXY`](/docs/node/param#haproxy)              | HAProxy the load balancer           | 10    |
| [`NODE`](/docs/node/param)     | [`NODE_EXPORTER`](/docs/node/param#node_exporter)  | Node Monitoring Agent               | 3     |
| [`NODE`](/docs/node/param)     | [`PROMTAIL`](/docs/node/param#promtail)            | Promtail logging Agent              | 4     |
| [`DOCKER`](/docs/docker/param) | [`DOCKER`](/docs/docker/param)                     | Docker Daemon                       | 4     |
| [`ETCD`](/docs/etcd/param)     | [`ETCD`](/docs/etcd/param#etcd)                    | ETCD DCS Cluster                    | 10    |
| [`MINIO`](/docs/minio/param)   | [`MINIO`](/docs/minio/param#minio)                 | MINIO S3 Object Storage             | 15    |
| [`REDIS`](/docs/redis/param)   | [`REDIS`](/docs/redis/param)                       | Redis the key-value NoSQL cache     | 20    |
| [`PGSQL`](/docs/pgsql/param)   | [`PG_ID`](/docs/pgsql/param#pg_id)                 | PG Identity Parameters              | 11    |
| [`PGSQL`](/docs/pgsql/param)   | [`PG_BUSINESS`](/docs/pgsql/param#pg_business)     | PG Business Object Definition       | 12    |
| [`PGSQL`](/docs/pgsql/param)   | [`PG_INSTALL`](/docs/pgsql/param#pg_install)       | Install PG Packages & Extensions    | 10    |
| [`PGSQL`](/docs/pgsql/param)   | [`PG_BOOTSTRAP`](/docs/pgsql/param#pg_bootstrap)   | Init HA PG Cluster with Patroni     | 35    |
| [`PGSQL`](/docs/pgsql/param)   | [`PG_PROVISION`](/docs/pgsql/param#pg_provision)   | Create in-database objects          | 9     |
| [`PGSQL`](/docs/pgsql/param)   | [`PG_BACKUP`](/docs/pgsql/param#pg_backup)         | Set Backup Repo with pgBackRest     | 5     |
| [`PGSQL`](/docs/pgsql/param)   | [`PG_ACCESS`](/docs/pgsql/param#pg_access)         | Exposing service, bind vip, dns     | 16    |
| [`PGSQL`](/docs/pgsql/param)   | [`PG_MONITOR`](/docs/pgsql/param#pg_monitor)       | Collect metrics & logs for Postgres | 18    |
| [`PGSQL`](/docs/pgsql/param)   | [`PG_EXPORTER`](/docs/pgsql/param#pg_remove)       | Remove a Postgres cluster           | 4     |
