pig inventory
pig inventory (alias pig inv) inspects, edits, and validates the Pigsty inventory, pigsty.yml. It also checks deployment prerequisites and exchanges configuration with PostgreSQL through the experimental cmdb commands.
When you edit a fragment, PIG preserves the YAML content and formatting outside that fragment. Before saving, it parses the complete file again. If parsing fails or another process has changed the original file, PIG keeps the original and reports an error.
| Command | Alias | Description |
|---|---|---|
inv status | Inspect the active inventory source (without executing) | |
inv list | ls | List inventory topology and value kinds (--depth) |
inv show | Show verbatim inventory YAML (may contain secrets) | |
inv edit | e | Edit the inventory or one fragment in $EDITOR |
inv validate | v | Validate one complete static Pigsty inventory |
inv check | ck | Check inventory, controller, and target readiness |
inv diff | Compare declarations of two inventories (value-free) | |
inv cmdb | Exchange with the PostgreSQL CMDB (experimental) |
Use global -i, --inventory to select the inventory or -H, --home to select the Pigsty directory. Without these options, PIG resolves the source from its configuration and the Pigsty directory. Commands support structured results with -o json or -o yaml, except show, which always prints the selected YAML verbatim.
Source selection
PIG selects the first configured source in this order. If a selected source is missing or invalid, PIG reports that problem instead of falling through to another inventory.
| Priority | Source | Base for a relative path |
|---|---|---|
| 1 | -i, --inventory PATH | Current working directory |
| 2 | PIGSTY_INVENTORY | Current working directory |
| 3 | inventory in ~/.pig/config.yml | Resolved Pigsty home |
| 4 | [defaults] inventory in the Pigsty home’s ansible.cfg | Directory containing ansible.cfg |
| 5 | pigsty.yml | Resolved Pigsty home |
PIG expands ~/ before resolving the path, including a quoted path in ansible.cfg.
pig inv status reports the selected source without executing it. Static Inventory operations
require a supported YAML source. pig do can forward a directory or executable inventory
to Ansible; pig sty deploy requires a regular file. Both pass the resolved
path explicitly to Ansible, so it cannot silently select a different default.
Quick Start
inv status / list / show
status inspects the source without executing a dynamic inventory. list shows groups, hosts, keys, and value types. show prints actual values, including any passwords in the selected configuration. Adding -o json does not change its YAML output.
Selectors
list / show / edit accept an optional selector that addresses one fragment:
inv edit
Open the selected fragment in $EDITOR. After you save and exit, PIG restores the indentation and newline style, parses the complete document, checks for concurrent changes, and replaces the original file atomically. If parsing fails, PIG keeps the temporary file so you can correct it.
| Option | Description |
|---|---|
--from | Replace the selected fragment from a regular file or stdin (-), skipping the editor |
The saved file belongs to the current user. PIG removes group and other permissions, usually producing mode 0600, and preserves stricter owner-only permissions. The structured result’s mode_tightened field reports this change.
inv validate
Validates one complete static Pigsty inventory: YAML structure, Ansible conventions, and
Pigsty semantics (such as admin_ip, the infra group, and IPv4 host keys) are checked
layer by layer; diagnostics never echo sensitive values.
| Option | Description |
|---|---|
--strict | Treat validation warnings as failures |
--ansible | Also parse with ansible-inventory |
--timeout | Timeout for --ansible compatibility validation (default 10s) |
Validation follows Pigsty’s configuration rules, including requirements for admin_ip, the infra group, and host addresses. The file must contain one YAML document with no duplicate keys. These parsing rules also apply to show and edit.
pg_users[].roles accepts role names and objects containing name, optional
state (grant, revoke, absent), and nullable boolean admin, set, and inherit.
Editing, serialization, and CMDB YAML export preserve strings that look like YAML 1.1 scalars,
including "1:30", "010", dates, and timestamps supplied as strings. Necessary quotes prevent
downstream YAML consumers from changing their types. Existing unquoted or explicitly tagged timestamps
retain their source bytes and use the opaque unknown scalar kind; quote them when a string is intended.
show and explicit CMDB exports retain their raw-data contract.
inv check
Readiness checks on top of static validation: by default only the inventory and local
controller conditions are checked; add probes with --profile.
| Option | Short | Description |
|---|---|---|
--profile | -p | Additional probes: ansible / network / ssh |
--user | Explicit SSH user (defaults to the controller user) | |
--port | TCP/SSH target port (default 22) | |
--sudo | With the ssh profile, also observe sudo -n true |
--user and --port use explicit arguments or the defaults above. They do not infer effective SSH variables from the inventory. Combine profiles with commas, for example --profile ansible,ssh.
inv diff
Compare the active inventory with another file. The result lists added, removed, and changed declarations by path and value type, without configuration values:
inv cmdb (experimental)
pig inventory cmdb exchanges the inventory with Pigsty’s existing CMDB schema
(files/cmdb.sql, the pigsty / pglog schemas) over a native PostgreSQL driver.
Connection resolution: -d/--database (database name, URI, or libpq conninfo) →
METADB_URL environment variable → service=meta.
| Subcommand | Description |
|---|---|
check | Read-only: verify CMDB projections, optionally against the static inventory |
init | Apply the cmdb.sql baseline (confirmation required over existing schemas; --plan previews) |
load | Replace all CMDB declaration rows from the static inventory (one transaction; confirmation required; --plan/--strict) |
dump | Export the CMDB as a static inventory file (--force to overwrite a differing target) |
enable | Switch the ansible.cfg inventory to the CMDB (inventory.sh) |
disable | Switch back to the static pigsty.yml (both support --plan) |
init runs cmdb.sql and replaces existing pigsty / pglog schemas. Back up data you need to retain before running it. load replaces all declaration rows in one transaction. Interactive mode asks you to confirm the target; use --yes for automation and structured output. Use --plan to inspect the operation first.
Design records
Was this page helpful?
Thanks—your feedback helps us improve this page.
What got in the way? (optional)