This is the multi-page printable view of this section. .
Infra as Code
Pigsty uses IaC and GitOps. Describe the environment in a declarative inventory. Apply it with idempotent playbooks.
Declare the target state with parameters. Playbooks can repeatedly adjust nodes to that state. This resembles Kubernetes CRDs and Operators, implemented through Ansible on physical servers and VMs.
Pigsty was designed to manage large PostgreSQL deployments. Its target was to reproduce more than 100 database clusters, PG/Redis services, and monitoring on prepared servers within ten minutes. Manual GUI operations cannot complete that work in the available time. CLI-based IaC provides precise, efficient control.
pigsty.yml describes the deployment state. Production, staging, test, and development environments use the same deployment logic. Their inventories define the differences.
Store this configuration in Git for version history and auditing. You can also store it in PostgreSQL CMDB tables as infrastructure data. Integrate either method with existing workflows.
IaC supports enterprise operators, individual developers, and smaller organizations. Default values avoid the need to understand every parameter. Start a single-node database with zero configuration. Add two IP addresses for an enterprise HA PostgreSQL cluster.
Declare Modules
This default example installs INFRA, NODE, ETCD, and PGSQL on 10.10.10.10.
Run these playbooks to install the modules:
Declare Clusters
Install PGSQL on multiple nodes to declare a PostgreSQL cluster as one service unit:
For a three-node HA cluster using streaming replication, add this definition to all.children in pigsty.yml. The three nodes must already be managed by Pigsty.
After defining the cluster, create it with playbooks:

Instance roles include primary, replica, offline, delayed, and synchronous standby. Cluster types include standby, Citus, Redis, MINIO (Silo), and Etcd.
Customize Cluster Content
Declare databases, users, services, and HBA rules inside each cluster. This example customizes the default pg-meta single-node cluster:
It declares six business databases and seven business users. It adds a standby service for reads without replication delay, additional pg_hba rules, a primary L2 VIP, and a custom backup strategy.
Declare Access Control
Declarative configuration also controls access permissions. This example customizes security for pg-meta:
The three-node crit.yml template prioritizes consistency and zero-loss failover. It enables L2 VIP and restricts database and pool listeners to loopback, internal, and VIP addresses. It enables TLS for the Patroni API and PgBouncer. HBA rules require SSL for database access. $libdir/passwordcheck in pg_libs enforces the password policy.
A separate pg-meta-delay cluster follows pg-meta with a one-hour delay for emergency recovery after data deletion.
Citus Distributed Cluster
This configuration declares a four-node Citus cluster:
Redis Clusters
These examples declare Redis primary-replica, sentinel, and Redis Cluster deployments:
ETCD Cluster
This configuration declares a three-node Etcd cluster:
MINIO (Silo) Cluster
This configuration declares a three-node Silo cluster. Inventory groups and parameters retain MINIO compatibility names:
1 - Inventory
Each Pigsty deployment has an inventory that describes the infrastructure and database clusters.
Configuration File
By default, Pigsty uses Ansible YAML configuration format. The inventory is a single file, pigsty.yml.
Edit this file to customize the deployment. Alternatively, use the configure wizard to generate it automatically.
Configuration Structure
The inventory uses Ansible YAML configuration format. It contains global parameters in all.vars and groups in all.children.
Define clusters in all.children. Define infrastructure settings in all.vars, as this example shows:
Cluster Definition
Each Ansible group can represent a cluster. Examples include node, PostgreSQL, Redis, Etcd, and Silo clusters.
A cluster definition contains members (hosts) and parameters (vars). Define members in <cls>.hosts. Set configuration parameters in <cls>.vars. This example defines a three-node HA PostgreSQL cluster:
Cluster vars override global parameters. Instance vars override both cluster and global parameters.
Splitting Configuration
For a large deployment, you can split the inventory into multiple files. This can also help organize and maintain configuration.
Put cluster members in hosts.yml. Put cluster configuration parameters in the corresponding files under group_vars.
Switching Configuration
When you run a playbook, use -i to temporarily select a different inventory.
Ansible also accepts local yaml|ini configuration files, a CMDB, or other dynamic configuration scripts.
The ansible.cfg file in the Pigsty home directory sets the default inventory to pigsty.yml in that directory. You can change this setting.
You can store the inventory in a CMDB metabase to integrate it with existing systems.
2 - Configure
The configure configuration wizard generates pigsty.yml for your current environment.
This script is optional. If you know how to configure Pigsty, edit pigsty.yml directly and skip the wizard.
Quick Start
Enter the Pigsty source directory and run ./configure to start the wizard. Without arguments, it uses the meta single-node template:
The command starts with the selected template. It detects the current node IP address and region, then generates pigsty.yml for that environment.
demo/configure.cast β /demo/configure.cast
Features
The configure script makes these adjustments from your environment and input. By default, it generates pigsty.yml in the Pigsty directory.
- Detect the current node IP address. If the node has multiple addresses, ask you to select a primary IP address as its identity.
- Replace
10.10.10.10in the template with this address. Setadmin_ipto the same value. - Detect the region. Set
regiontodefaultfor global software repositories orchinafor Chinese mirrors. - For instances with fewer than four vCPUs, use the
tinytemplate fornode_tuneandpg_conf. This reduces resource use. - With
-v, changepg_versionandpg18-*package-group aliases to the specified major version. Exclude the fixed-kernel templatesmssql,polar, andpg19. - With
-g, replace recognized default passwords with strong random passwords. This is strongly recommended. Review other values against the Default Credentials Checklist. - For PG major versions β₯ 17, prefer the built-in
C.UTF-8locale, or the OS-supportedC.UTF-8. - Check that the core deployment dependency
ansibleis available. - Check that the deployment target accepts SSH connections and can run commands with sudo. Use
-sto skip these checks.
Usage Examples
Command Arguments
Argument Details
| Argument | Description |
|---|---|
-c, --conf | Generate config from conf/<template>.yml, supports subdirectories like ha/full |
-i, --ip | Replace placeholder 10.10.10.10 in config template with specified IP |
-v, --version | Specify PostgreSQL major version (14-19); PG19 is Beta, so prefer the dedicated pg19 template |
-r, --region | Set software repo mirror region: default, china (Chinese mirrors), europe (European) |
-o, --output | Output path, default pigsty.yml; relative paths use Pigsty home, absolute paths are used as given |
-s, --skip | Skip IP probing, target SSH/Sudo checks, and effective IP replacement; keep 10.10.10.10 |
-x, --proxy | Write current environment proxy variables (HTTP_PROXY, HTTPS_PROXY, ALL_PROXY, NO_PROXY) to config |
-n, --non-interactive | Non-interactive mode; a single/demo IP is auto-selected, while ambiguous multi-IP hosts require -i |
-p, --port | SSH port used by readiness checks only; it does not write ansible_port into the generated config |
-g, --generate | Generate random values for passwords in config file, improving security (strongly recommended) |
Execution Flow
The configure script detects and configures settings in this order:
Automatic Behaviors
Region Detection
The script tests network access to detect mainland China behind the GFW:
- If Google is reachable, use
region: defaultrepositories. - If Google is unreachable but
https://pigsty.ccis reachable, setregion: china. - If neither endpoint is reachable, use
region: defaultand warn that internet access is unavailable. - To set the region manually, use
-r.
IP Address Handling
The script selects the primary IP address in this order:
- Command line argument: Use the address specified with
-i. - Single IP detection: If the node has only one IP address, select it automatically.
- Demo IP detection: If
10.10.10.10exists, select it automatically for the sandbox environment. - Interactive input: If multiple addresses remain, ask you to select or enter one.
Low-End Hardware Optimization
If the script detects fewer than four CPU cores (1β3), it changes these settings:
These settings support operation on virtual machines with limited resources.
Locale Settings
The script enables C.UTF-8 as the default locale if either condition applies:
- PostgreSQL version is β₯ 17, with built-in Locale Provider support.
- The operating system supports the
C.UTF-8orC.utf8locale.
China Region Special Handling
For region china, the script automatically enables:
docker_registry_mirrorsfor faster Docker downloads through mirrors.PIP_MIRROR_URLfor faster Python downloads through mirrors.
Password Generation
With -g, the script generates a random 24-character string for each of these passwords:
| Password Parameter | Description |
|---|---|
grafana_admin_password | Grafana admin password |
pg_admin_password | PostgreSQL admin password |
pg_monitor_password | PostgreSQL monitor user password |
pg_replication_password | PostgreSQL replication user password |
patroni_password | Patroni API password |
haproxy_admin_password | HAProxy admin password |
minio_secret_key | Silo Root Secret |
etcd_root_password | ETCD Root password |
It also replaces the following placeholder passwords:
DBUser.Metaβ random passwordDBUser.Viewerβ random passwordS3User.Backupβ random passwordS3User.Metaβ random passwordS3User.Dataβ random passwordDBUser.Supaβ random passwordVibe.Codingβ random password
Configuration Templates
The script reads templates from conf/. Set -c to a relative path without the .yml suffix, such as ha/full or app/immich.
Core Templates
| Template | Description |
|---|---|
meta | Default template: Single-node installation with INFRA + NODE + ETCD + PGSQL |
rich | Feature-rich version: Includes almost all extensions, Silo, local repo |
slim | Minimal version: PostgreSQL + ETCD only, no monitoring infrastructure |
fat | Complete version: rich base with more extensions installed |
pgsql | Pure PostgreSQL template |
pg19 | Single-node PostgreSQL 19 Beta evaluation template |
infra | Pure infrastructure template |
HA Templates (ha/)
| Template | Description |
|---|---|
ha/dual | 2-node HA cluster |
ha/trio | 3-node HA cluster |
ha/full | 4-node complete sandbox environment |
ha/safe | Security-hardened HA configuration |
ha/octo | Compact 8-node HA simulation |
ha/simu | 20-node production simulation environment |
ha/citus | 13-node Citus distributed cluster |
Application Templates
| Template | Description |
|---|---|
supabase | Supabase self-hosted configuration |
app/dify | Dify AI platform configuration |
app/odoo | Odoo ERP configuration |
app/electric | Electric sync engine configuration |
app/insforge | Insforge backend platform configuration |
app/hindsight | Hindsight application configuration |
app/teable | Teable table database configuration |
app/mattermost | Mattermost collaboration platform configuration |
app/maybe | Maybe finance application configuration |
app/registry | Docker Registry configuration |
app/immich | Immich photo and video management |
app/jumpserver | JumpServer bastion host |
Special Kernel Templates
| Template | Description |
|---|---|
ivory | IvorySQL: Oracle-compatible PostgreSQL |
mssql | Babelfish: SQL Server-compatible PostgreSQL |
polar | PolarDB: Alibaba Cloud open-source distributed PostgreSQL |
ha/citus | Citus: Distributed PostgreSQL HA cluster |
mysql | OpenHalo: MySQL protocol-compatible PostgreSQL |
pgtde | Percona PostgreSQL Server: transparent encryption |
oriole | OrioleDB: Next-generation storage engine |
agens | AgensGraph: graph database kernel |
pgedge | pgEdge: distributed PostgreSQL kernel |
mongo | MongoDB-compatible stack template |
Demo and Build Templates
| Template | Description |
|---|---|
vibe | Vibe Coding development environment |
docker | Run Pigsty inside a Docker container |
demo/bare | Minimal readable single-node example |
demo/el | Full parameter example for EL distributions |
demo/debian | Full parameter example for Debian/Ubuntu |
demo/demo | Multi-module demo environment |
demo/kernel | Ten-node database-kernel matrix |
demo/redis | Redis replica, Sentinel, and native Cluster demo |
demo/minio | Multi-node, multi-drive Silo demo (source default) |
demo/kafka | Kafka KRaft development and secure-cluster demo |
demo/mysql | Native MySQL 8.4 pilot demo |
demo/remote | Remote PostgreSQL/RDS monitoring example |
demo/saas | Legacy single-node SaaS component bundle |
demo/wool | Small cloud-instance example for China |
build/oss | Cross-distribution open-source package build env |
build/dev | Three-node development and build environment |
Output Example
Environment Variables
The script supports the following environment variables:
| Environment Variable | Description | Default |
|---|---|---|
PIGSTY_HOME | Pigsty installation directory | ~/pigsty |
METADB_URL | Metabase connection URL | service=meta |
HTTP_PROXY | HTTP proxy | - |
HTTPS_PROXY | HTTPS proxy | - |
ALL_PROXY | Universal proxy | - |
NO_PROXY | Proxy whitelist | Built-in default |
Notes
Passwordless access: Before you run
configure, the current user must have passwordless sudo and passwordless SSH access to localhost. Thebootstrapscript can configure both.IP address selection: Select an internal IP as the primary address. Do not select a public IP or
127.0.0.1.Password security: In production, always change default passwords. Use
-gto randomize recognized credentials. Review the Default Credentials Checklist for remaining values.Configuration review: After the script completes, review the generated
pigsty.yml. Check that it meets your requirements.Multiple executions: You can run
configureagain to regenerate configuration. Each run overwrites the existingpigsty.yml.macOS limitations: On macOS, the script skips some Linux checks and uses placeholder IP
10.10.10.10. macOS can serve only as an administration node.
FAQ
How to use a custom configuration template?
Place your configuration file in the conf/ directory, then specify it with the -c argument:
How to generate different configurations for multiple clusters?
Use the -o argument to specify different output files:
Then specify the configuration file when running playbooks:
How to handle multiple IPs in non-interactive mode?
You must explicitly specify the IP address using the -i argument:
How to keep the placeholder IP in the template?
Use the -s argument to skip IP replacement:
Related Documentation
- Inventory: Understand the Ansible inventory structure
- Parameters: Understand Pigsty parameter hierarchy and priority
- Templates: View all available configuration templates
- Installation: Understand the complete installation process
- Metabase: Use PostgreSQL as a dynamic configuration source
3 - Parameters
Use inventory parameters to customize infrastructure settings and database configuration.
Parameter List
The current source and reference pages list 373 public parameters across 10 official modules. See Reference - Parameter List for the complete list. The native MySQL 8.4 pilot module has 13 additional public parameters. They are listed separately and excluded from this total.
| Module | Groups | Params | Description |
|---|---|---|---|
| PGSQL | 9 | 124 | PostgreSQL high-availability cluster configuration |
| INFRA | 10 | 73 | Software repositories and Victoria observability infrastructure |
| NODE | 11 | 73 | Node initialization, system tuning, and operations baseline |
| ETCD | 2 | 13 | ETCD cluster and removal protection parameters |
| MINIO | 2 | 22 | Silo deployment, observability, and removal parameters |
| REDIS | 2 | 22 | Redis/Valkey deployment and removal parameters |
| DOCKER | 1 | 8 | Docker engine parameters |
| JUICE | 1 | 2 | JuiceFS instance and cache parameters |
| VIBE | 1 | 18 | Code/Jupyter/Node.js/Claude/Codex configuration |
| KAFKA | 2 | 18 | Kafka deployment and removal-protection parameters |
Parameter Form
Parameters are key-value pairs that describe entities. A key is a string. A value can be a boolean, string, number, array, or object.
Parameter Priority
Set parameters at these levels, listed from highest to lowest priority:
| Level | Location | Description | Priority |
|---|---|---|---|
| CLI | -e command line argument | Passed via command line | Highest (5) |
| Host/Instance | <group>.hosts.<host> | Parameters specific to a single host | Higher (4) |
| Group/Cluster | <group>.vars | Parameters shared by hosts in group/cluster | Medium (3) |
| Global | all.vars | Parameters shared by all hosts | Lower (2) |
| Default | <roles>/default/main.yml | Role implementation defaults | Lowest (1) |
These examples show parameter priority:
- Set
-e grafana_clean=trueon the playbook command line to erase Grafana data. - Set host variable
pg_roleto override the PostgreSQL instance role. - Set group variable
pg_clusterto override the PostgreSQL cluster name. - Set global variable
node_ntp_serversto specify NTP servers. - If you do not set
pg_version, Pigsty uses thepgsqlrole default,18.
Except for identity parameters, all parameters have defaults. You do not need to set them explicitly.
Identity Parameters
Identity parameters identify entities. They have no defaults and must be set explicitly, with the exception below.
| Module | Identity Parameters |
|---|---|
PGSQL | pg_cluster, pg_seq, pg_role, … |
NODE | nodename, node_cluster |
ETCD | etcd_cluster, etcd_seq |
MINIO | minio_cluster, minio_seq |
REDIS | redis_cluster, redis_node, redis_instances |
INFRA | infra_seq |
etcd_cluster is an exception. It defaults to etcd. Set minio_cluster explicitly in each object storage cluster’s variables. It no longer has a default. Do not set it in all.vars: this marks every host as a MINIO module member.
4 - Conf Templates
The inventory defines the deployment through declarative configuration. Customize its pigsty.yml file for your requirements.
New users can start with ready-to-use templates for common deployment scenarios.
Each template is a predefined pigsty.yml file with defaults for a specific scenario.
Select a template, then change it to meet your requirements.
Using Templates
The optional configure wizard generates an inventory from your environment and input, with suitable defaults.
Use ./configure -c <conf> to select a template. <conf> is relative to conf; the .yml suffix is optional.
If no template is specified, Pigsty defaults to the meta.yml single-node configuration template.
Template List
Main Templates
Use these templates to install Pigsty on one server:
| Template | Description |
|---|---|
meta.yml | Default template, single-node PostgreSQL online installation |
rich.yml | Feature-rich template with local repo, Silo, and more examples |
slim.yml | Minimal template, PostgreSQL only without monitoring and infrastructure |
Database Kernel Templates
Templates for various database management systems and kernels:
| Template | Description |
|---|---|
pgsql.yml | Native PostgreSQL kernel, basic features (14~18) |
pg19.yml | PostgreSQL 19 Beta trial template |
mssql.yml | Babelfish kernel, SQL Server protocol compatible (17/18) |
polar.yml | PolarDB PG kernel, Aurora/RAC style (17) |
ivory.yml | IvorySQL kernel, Oracle syntax compatible (18) |
mysql.yml | OpenHalo kernel, MySQL compatible (14) |
pgtde.yml | Percona PostgreSQL Server transparent encryption (18) |
oriole.yml | OrioleDB kernel, OLTP enhanced (16~18) |
agens.yml | AgensGraph graph database kernel (17) |
pgedge.yml | pgEdge distributed database kernel (15~18, default 18) |
supabase.yml | Supabase self-hosted configuration (15~18) |
You can add more nodes later or use HA templates to plan your cluster from the start.
HA Templates
Use these templates for a deployment with multiple nodes and high availability:
| Template | Description |
|---|---|
dual.yml | 2-node semi-HA deployment |
trio.yml | 3-node standard HA deployment |
full.yml | 4-node standard deployment |
safe.yml | 4-node security-enhanced deployment with delayed replica |
octo.yml | Compact 8-node HA simulation |
simu.yml | 20-node production environment simulation |
ha/citus.yml | Citus distributed HA PostgreSQL (14~18) |
Application Templates
Use these templates to run applications with Docker:
| Template | Description |
|---|---|
supabase.yml | Start single-node Supabase |
odoo.yml | Start Odoo ERP system |
dify.yml | Start Dify AI workflow system |
electric.yml | Start Electric sync engine |
insforge.yml | Start Insforge backend platform |
hindsight.yml | Start Hindsight application |
mattermost.yml | Start Mattermost collaboration platform |
teable.yml | Start Teable spreadsheet database |
maybe.yml | Start Maybe finance app |
registry.yml | Start Docker Registry |
Demo Templates
Pigsty also provides these demonstration templates:
| Template | Description |
|---|---|
el.yml | Full-parameter config file for EL 8/9 systems |
debian.yml | Full-parameter config file for Debian/Ubuntu systems |
remote.yml | Example config for monitoring remote PostgreSQL clusters or RDS |
redis.yml | Redis cluster example configuration |
minio.yml | 4-node multi-drive Silo cluster example (source default) |
kafka.yml | Kafka dynamic KRaft example with a single-node dev cluster and a three-node secure cluster |
mysql.yml | Native MySQL 8.4 single-node/three-node pilot example; distinct from OpenHalo conf/mysql.yml |
demo.yml | Configuration file for Pigsty public demo site |
fat.yml | Single-node config with local repo and full feature set |
infra.yml | Deploy only the infrastructure modules |
vibe.yml | Vibe Coding / AI application development template |
mongo.yml | FerretDB / MongoDB-compatible example |
docker.yml | Docker application host template |
Build Templates
Use these templates for development and testing:
| Template | Description |
|---|---|
build/oss.yml | Open source build config for EL 9/10, Debian 12/13, Ubuntu 22.04/24.04/26.04 |
build/dev.yml | Development and testing build config |
5 - Use CMDB as Config Inventory
Use a PostgreSQL metabase as a dynamic configuration source instead of static YAML files.
Overview
A CMDB (Configuration Management Database) stores configuration in database tables.
By default, Pigsty uses static pigsty.yml as the Ansible inventory.
A static file is simple. Larger deployments can need finer control, concurrent editing, and external integration beyond one file’s practical limits.
| Feature | Static YAML File | CMDB Metabase |
|---|---|---|
| Querying | Manual search/grep | SQL queries with any conditions, aggregation analysis |
| Versioning | Depends on Git or manual backup | Database transactions, audit logs, time-travel snapshots |
| Access Control | File system permissions, coarse-grained | PostgreSQL fine-grained access control |
| Concurrent Editing | Requires file locking or merge conflicts | Database transactions naturally support concurrency |
| External Integration | Requires YAML parsing | Standard SQL interface, easy integration with any language |
| Scalability | Difficult to maintain when file becomes too large | Scales to physical limits |
| Dynamic Generation | Static file, changes require manual application | Immediate effect, real-time configuration changes |
The sample pg-meta.meta database baseline defines the CMDB schema.
How It Works
CMDB replaces the static inventory with an executable script that returns JSON, as Ansible supports. Enabling CMDB creates inventory.sh:
Whenever Ansible reads the inventory, this script queries pigsty.inventory in PostgreSQL and returns JSON.
The architecture is:
flowchart LR
conf["bin/inventory_conf"]
tocmdb["bin/inventory_cmdb"]
load["bin/inventory_load"]
ansible["π Ansible"]
subgraph static["π Static Config Mode"]
yml[("pigsty.yml")]
end
subgraph dynamic["ποΈ CMDB Dynamic Mode"]
sh["inventory.sh"]
cmdb[("PostgreSQL CMDB")]
end
conf -->|"switch"| yml
yml -->|"load config"| load
load -->|"write"| cmdb
tocmdb -->|"switch"| sh
sh --> cmdb
yml --> ansible
cmdb --> ansibleData Model
The CMDB database schema is defined in files/cmdb.sql, with all objects in the pigsty schema.
Core Tables
| Table | Description | Primary Key |
|---|---|---|
pigsty.group | Cluster/group definitions, corresponds to Ansible groups | cls |
pigsty.host | Host definitions, belongs to a group | (cls, ip) |
pigsty.global_var | Global variables, corresponds to all.vars | key |
pigsty.group_var | Group variables, corresponds to all.children.<cls>.vars | (cls, key) |
pigsty.host_var | Host variables, host-level variables | (cls, ip, key) |
pigsty.default_var | Default variable definitions, stores parameter metadata | key |
pigsty.job | Job records table, records executed tasks | id |
Table Structure Details
Cluster Table pigsty.group
Host Table pigsty.host
Global Variables Table pigsty.global_var
Group Variables Table pigsty.group_var
Host Variables Table pigsty.host_var
Core Views
These views expose configuration data:
| View | Description |
|---|---|
pigsty.inventory | Core view: Generates Ansible dynamic inventory JSON |
pigsty.raw_config | Raw configuration in JSON format |
pigsty.global_config | Global config view, merges defaults and global vars |
pigsty.group_config | Group config view, includes host list and group vars |
pigsty.host_config | Host config view, merges group and host-level vars |
pigsty.pg_cluster | PostgreSQL cluster view |
pigsty.pg_instance | PostgreSQL instance view |
pigsty.pg_database | PostgreSQL database definition view |
pigsty.pg_users | PostgreSQL user definition view |
pigsty.pg_service | PostgreSQL service definition view |
pigsty.pg_hba | PostgreSQL HBA rules view |
pigsty.pg_remote | Remote PostgreSQL instance view |
pigsty.inventory converts database configuration to Ansible inventory JSON:
Utility Scripts
Use these three scripts to manage the CMDB:
| Script | Function |
|---|---|
bin/inventory_load | Load YAML configuration file into PostgreSQL database |
bin/inventory_cmdb | Switch configuration source to CMDB (dynamic inventory script) |
bin/inventory_conf | Switch configuration source to static config file pigsty.yml |
inventory_load
Parse a YAML configuration file and import it into the CMDB:
The script performs these operations:
- Clears existing data in the
pigstyschema - Parses the YAML configuration file
- Writes global variables to the
global_vartable - Writes cluster definitions to the
grouptable - Writes cluster variables to the
group_vartable - Writes host definitions to the
hosttable - Writes host variables to the
host_vartable
Environment Variables
PIGSTY_HOME: Pigsty installation directory, defaults to~/pigstyMETADB_URL: Database connection URL, defaults toservice=meta
inventory_cmdb
Switch Ansible to use CMDB as the configuration source:
The script performs these operations:
- Creates dynamic inventory script
${PIGSTY_HOME}/inventory.sh - Modifies
ansible.cfgto setinventorytoinventory.sh
The generated inventory.sh contains:
inventory_conf
Switch back to a static YAML configuration file:
The script modifies ansible.cfg to set inventory back to pigsty.yml.
Usage Workflow
First-time CMDB Setup
- Initialize the CMDB schema. Pigsty installation usually does this automatically:
- Load configuration into the database:
- Switch to CMDB mode:
- Verify configuration:
Query Configuration
After you enable CMDB, use SQL to query the configuration:
Modify Configuration
Use SQL to change the configuration directly:
Configuration changes are immediately available. You do not need to reload or restart a service.
Switch Back to Static Configuration
Switch back to a static configuration file:
Advanced Usage
Export Configuration
Export CMDB configuration to YAML format:
Or use the ansible-inventory command:
Configuration Auditing
Track configuration changes using the mtime field:
Integration with External Systems
CMDB uses standard PostgreSQL. You can integrate it with these systems:
- Web Management Interface: Expose configuration data through a REST API, such as PostgREST.
- CI/CD Pipelines: Read and write database data directly from deployment scripts.
- Monitoring & Alerting: Generate monitoring rules from configuration data.
- ITSM Systems: Synchronize data with enterprise CMDB systems.
Considerations
Data Consistency: After you change configuration, run the corresponding Ansible playbooks again to apply it to the environment.
Backup: CMDB configuration data is critical. Back it up regularly.
Permissions: Set appropriate CMDB database access permissions to prevent accidental changes.
Transactions: Make batch configuration changes in a transaction. This permits rollback if an error occurs.
Connection Pooling:
inventory.shopens a new connection each time it runs. Consider connection pooling if Ansible runs frequently.
Summary
Use CMDB for large cluster deployments, complex queries, external integration, or fine-grained access control. PostgreSQL stores the configuration and provides database functions to manage it.
| Feature | Description |
|---|---|
| Storage | PostgreSQL pigsty schema |
| Dynamic Inventory | inventory.sh script |
| Config Load | bin/inventory_load |
| Switch to CMDB | bin/inventory_cmdb |
| Switch to YAML | bin/inventory_conf |
| Core View | pigsty.inventory |