# Replacing Vagrant in Pigsty: what Barn still needs

> A source check of the Vagrant behavior Pigsty relies on, with priorities and acceptance criteria for readiness gates, forced power-off, VIP addresses, persistent disks, and fault injection.

---

LLMS index: [llms.txt](/v1.5/llms.txt)

---

Pigsty's `vagrant/` directory, Makefile, and public tutorials define the behavior Barn has to take over. The [sandbox migration plan](/v1.5/blog/design/pigsty-barn-migration/) already covers resource scaling, local host names, and the entry-point switch, and [Vagrant and the development loop](/v1.5/blog/design/vagrant-workflow-boundary/) lists candidates such as provisioning steps, file transfer, and snapshots. This page adds the remaining layer: it checks the Vagrant behavior Pigsty actually relies on, sets out what Barn must add before Vagrant can be retired, and then lists capabilities Vagrant never offered but that Pigsty's high-availability tutorials need.

**Status (2026-11-27)**: this is a design proposal based on a source check of Barn's unreleased `main` (`22f6a28`), Pigsty `main`, and the pigsty.io documentation. None of the new capabilities is implemented, and the priorities are not tied to a release.

## The Vagrant behavior Pigsty relies on {#vagrant-contract}

| Pigsty today | Barn today | Gap |
|---|---|---|
| `vagrant/config` and `spec/*.rb`: topology, image aliases, resource scale, architecture | `vm_*`, `vm_scale`, `-I`/`-A`, short image aliases | None; the specs move into Pigsty inventories |
| `BOX_VERSION_PINS` fixes box versions | Exact versions in the inventory, resolved through the signed catalog | No exportable, verifiable lock record |
| Fixed private IPs and NAT NIC fixes (`bin/el-fix`) | Two NICs; the `private-network` stage checks the guest NIC configuration | Host and peer reachability is not verified, and a failure only reports `limited` |
| `/data` disk, four MinIO disks, `root_disk` | `vm_disks`, `vm_disk` | A persistent disk judged corrupt is reset |
| `vagrant/ssh` writes node-name and IP aliases | `ssh-config` covers node names, IPs, and `vm_alias` | None |
| `vagrant/dns` writes `/etc/hosts` | `vm_hosts` and `hosts install -f` (since 1.2.0) | The Pigsty-side name extractor is still missing |
| Subset operations such as `up-test` | Selectors accept resolved node names only | No selection by group, IP, or alias |
| `halt`, `destroy`, `nuke` | `stop`, `destroy`, `purge` | `stop` only sends an ACPI shutdown; nothing matches `halt --force` |
| `suspend`, `resume` | None | Memory state is not promised; see [scope](#scope) |
| Windows hosts | macOS, Linux | Needs a product decision; see [scope](#scope) |
{.wide .expand}

Two rows need context. `ssh 10.10.10.11` reaches the management forward on `127.0.0.1` through Barn's OpenSSH configuration; under the VirtualBox provider, Pigsty's `vagrant/ssh` also copies the `127.0.0.1:2222` entry from `vagrant ssh-config` into an IP alias. That is not a regression, but a place where Barn can do better than Vagrant. Data disks go the other way: the Vagrant templates format a disk only when `blkid` finds no signature at all, and when a signature remains but the mount fails, `mount -a || true` fails silently. Barn rebuilds the filesystem once the checker confirms damage.

## Required before retiring Vagrant {#p0}

### Strict readiness gate {#readiness}

The `private-network`, `control-ssh`, and `data-disks` guest setup stages are optional. A failure is written to `nodes[].warnings`, `up` summarizes the node as `limited`, and the command exits `0`. `private-network` checks only the guest's own NIC configuration — the right address, no default route, no DNS — and then sends one UDP packet to the host `.1` without waiting for a reply. It does not show that the host can reach the private address directly, or that the control node can log in to its peers without a password, which is exactly what PostgreSQL streaming replication, etcd, and Silo depend on.

Proposal:

- After the guests are ready, `up` runs three probes: the host connects directly to port `22` on each node's private address, bypassing the OpenSSH configuration; the control node runs `ssh -o BatchMode=yes <ip> sudo -n true` against every peer; and each declared mount point is backed by its own block device and is writable.
- A new `--strict` flag turns any guest warning into a non-zero exit. The VMs keep running, and the structured result names the cause per node and stage.
- The same probes are available as a separate, repeatable command (name to be decided, for example `barn verify`) for use after a host reboot or a socket_vmnet reinstall.

Until Barn ships this, Pigsty can check the `barn --json up` result as the [automation guide](/v1.5/docs/start/automation/#run-a-lab-end-to-end) shows and reject nodes that report `warnings` or `repairs`.

**Acceptance**: a healthy four-node `full` lab returns `0` under `--strict`. Blocking the private network on the host or in a guest makes `--strict` return non-zero and name the node and stage, and so does a missing control-node private key.

### Forced power-off {#power-off}

Linux `stop` sends `system_powerdown` over QMP and waits up to `GracefulGuestShutdownTimeout` (two minutes); there is no forced option. During a clean shutdown Patroni hands over leadership on its own, so the "node down" case in Pigsty's [failure model](https://pigsty.io/docs/concept/ha/failure/), which relies on passive detection, cannot be tested. The [2-of-3 failure drill](https://pigsty.io/docs/pgsql/tutorial/drill/) also asks for an outright power or network cut. Pigsty's MySQL hardware test also recorded a `purge` that failed because the shutdown grace period exceeded the test's 120-second timeout.

Proposal:

- `stop --force` verifies the process identity and then runs QMP `quit`, the same path start compensation already uses. The node is recorded as stopped and starts normally with `start`.
- `purge` discards everything anyway, so it takes the forced path; `destroy` that keeps persistent disks still tries a clean shutdown first.

**Acceptance**: after a forced power-off of the primary in `full`, Patroni promotes a replica within the TTL, and the node rejoins the cluster after `start`. A four-node `purge` no longer waits for guest shutdown.

### VIP address rule {#vip}

The current rules contradict each other. The code rejects node addresses and `vm_hosts` in `.2`–`.8`, and the [sandbox migration plan](/v1.5/blog/design/pigsty-barn-migration/#audit) therefore asks Pigsty to move its VIPs off `.2/.3/.4`. The [two-NIC design](/v1.5/blog/design/fixed-ip-two-nics/), however, lists that range as "available for L2 VIPs". Moving is costly: as of 2026-11-27, 14 files in Pigsty's `conf/` and `roles/` reference `10.10.10.2`–`10.10.10.4`, and so do 25 pages each on pigsty.io and pigsty.cc.

| Option | Approach | Cost and risk |
|---|---|---|
| A: Pigsty moves | VIPs move to `.100` and up | 14 configuration files and about 50 documentation pages, with their connection strings and examples; Barn is unchanged |
| B: Barn accepts declared service addresses | A new service-address declaration (for example `vm_vips`) may use `.2`–`.8`; `up` and `hosts install` check for conflicts | Linux `barn0` runs no DHCP. The macOS vmnet pool serves only DHCP clients, and Barn guests use a static address on the private NIC. The risk comes from other clients on the same vmnet segment, which are likely to receive `.2`, so Barn has to check leases and probe ARP |
{.wide .expand}

Option B is recommended, provided two things are tested first: an EL guest's private NIC does not try DHCP during first boot, and the macOS host refreshes its ARP cache after a gratuitous ARP. Whichever option is chosen, service addresses take part in address-conflict validation and hosts publishing, and the contradictory page is corrected.

**Acceptance**: on both macOS socket_vmnet and Linux `barn0`, after the `pg-test` VIP moves from node A to node B — once through a switchover and once through a forced power-off — the host and a third guest reconnect to the service on the original address, and the host's ARP table points to the new MAC.

### Keep evidence on persistent disks {#persistent-disks}

When a data disk fails to mount and the checker confirms ext4 or XFS damage, the setup script rebuilds the filesystem, including on a disk marked persistent; [storage and access](/v1.5/docs/start/storage/) documents the current rule. In a database failure drill this erases exactly the evidence that needs analysis. In addition, `--delete-persistent` works only for a whole-deployment `destroy`, so Pigsty's MySQL whole-VM replacement test had to fall back to a new root disk with the old data disk detached.

Proposal:

- Persistent disks are no longer reset automatically. Barn marks the disk as failed and reports the node, mount point, device, and checker output. Non-persistent disks keep the current behavior.
- Two explicit operations: delete a node's persistent disks, and reset one disk (name to be decided, for example `barn disk reset NODE MOUNT`). Both reuse the `destroy` scope confirmation.

**Acceptance**: after controlled damage to an ext4 and an XFS persistent disk, a second `up` leaves the disk file's digest unchanged and the status points to the failed disk. An explicit reset produces an empty filesystem, and a single-node replacement deletes only that node's persistent disks.

## Smoother Pigsty labs {#p1}

### Select nodes by group, address, and alias {#selectors}

Selectors accept only resolved node names today. Barn already reads the group structure of the Ansible inventory, so the proposal is for `plan`, `up`, `start`, `stop`, `restart`, and `destroy` to also accept group names (such as `pg-test` and `minio`), private IPs, and unique `vm_alias` values, and to print the expanded node list before acting. A name that is both a group and a node is an error, and the `destroy` confirmation lists the expanded nodes.

**Acceptance**: in `full`, `barn stop pg-test` stops only the three nodes in the `pg-test` group, and an ambiguous selector returns a usage error.

### Fault injection {#fault-injection}

Pigsty's high-availability tutorials need three kinds of failure: a node going down, a hung process, and a network partition. All three can be produced through QMP without touching the guest configuration:

| Operation | QMP command | Simulated failure |
|---|---|---|
| Forced power-off | `quit` | Node down; see [above](#power-off) |
| Pause, resume | `stop`, `cont` | Hung node: vCPUs freeze and memory is kept; after resume, `barn time sync` corrects the clock |
| Disconnect, reconnect the private network | `set_link` on the private NIC only | Network partition; management SSH stays available for observation and recovery |
{.wide .expand}

Pausing also covers part of what Vagrant `suspend` was used for — temporarily giving CPU back — though it does not free memory. Asymmetric partitions, such as cutting only the link between A and B, remain the job of firewall rules that Pigsty scripts apply inside the guests.

**Acceptance**: pausing the primary for longer than the Patroni TTL promotes a replica, and after resume the old primary becomes a replica. Disconnecting the primary's private network causes a failover, and the node rejoins after reconnecting; management SSH to that node works throughout.

### Image release discipline and lock records {#image-lock}

Replacing Vagrant does not depend on a lock file. Pigsty profiles can write exact versions in the inventory (for example `vm_image: d13@20261123.2671.1`), which matches the old `BOX_VERSION_PINS`. Two release rules are more urgent:

- The Pigsty entry point checks a minimum Barn version. Barn 1.4.0 changes the catalog signing key, and 1.3.0 rejects catalog signatures from `2026112601` onward; see the [1.4.0 upgrade notes](https://github.com/pgsty/barn/blob/main/.github/releases/1.4.0.md). Pigsty should switch after 1.4.0 is released.
- The official image repository keeps every artifact that a published Pigsty release references.

After that, lock records follow the environment record in [Vagrant and the development loop](/v1.5/blog/design/vagrant-workflow-boundary/#priorities): export each node's image, architecture, full version, digest, and catalog revision, and provide a replay mode that refuses drift.

### Cold snapshots {#snapshots}

[Vagrant and the development loop](/v1.5/blog/design/vagrant-workflow-boundary/#priorities) already lists cold snapshots as P1. For Pigsty their main value is a saved baseline after deployment: each run of the PITR tutorial or an upgrade regression restores from it instead of spending ten or more minutes reinstalling. Taking the snapshot from a stopped VM also avoids the migration limits of 9p shares.

## Out of scope for this round {#scope}

- **Named parallel environments**: in the Vagrant era, environments in different directories also shared the same `10.10.10.0/24` host-only network, so Pigsty could never run two at once, and Barn's single deployment is not a regression. When switching profiles, `up` refuses with `nodes_removed`; the Pigsty entry point runs `barn destroy --yes` explicitly, matching the old `del`.
- **Deployment identity checks**: `nodes_removed` already stops most cross-profile mistakes.
- **Built-in upload and download**: both of Pigsty's providers disable the default shared folder, and source and offline packages are delivered with scp, which the existing `ssh-config` already supports. Pigsty defaults to EL images, and whether RHEL-family kernels include 9p modules needs testing; if they do not, `vm_shares` cannot replace scp.
- **Vendor image variants**: the Alma, Oracle, and RHEL aliases in the old `config` move to `image import` or a self-hosted repository.
- **Memory-state suspend**: not promised. Pause covers temporarily giving CPU back.
- **Windows hosts**: needs a product decision. One option is to keep a frozen `vagrant/` as the Windows entry point during the transition and delete it after [WSL2 acceptance](/v1.5/blog/design/windows-host-boundary/); the other is to narrow the host platforms in Pigsty's documentation.

## Pigsty-side work {#pigsty-side}

- The entry script always passes `-f`, runs configure, plan, and up in order, and explicitly destroys the old lab when switching profiles. This keeps `make -j` from running destroy and up concurrently.
- The entry script checks the minimum Barn version and moves or keeps VIPs according to the [VIP address rule](#vip) decision.
- The migration plan records `bin/sandbox-dns` as implemented locally, but no commit in the Pigsty repository contains it; it needs to be recovered or rewritten.
- `bin/release` still packages `vagrant/`; the release manifest and the English and Chinese documentation change with the switch.
- Accept the release package once on Apple Silicon and once on Linux amd64: `full` covers the portal, switchover, and VIP reconnection; `demo/minio` covers four mounted disks and reads and writes after a restart; `simu` covers 20 nodes, partial-failure retries, and group operations; `build/oss` covers retrieving real build artifacts. Cover the default EL9 entry point separately.
{.steps}

## Evidence {#evidence}

| Finding | Source |
|---|---|
| Private network, control SSH, and data disk stages only warn | [finalize.sh](https://github.com/pgsty/barn/blob/main/internal/cloudinit/scripts/finalize.sh), [render.go](https://github.com/pgsty/barn/blob/main/internal/cloudinit/render.go), [private-contract.sh](https://github.com/pgsty/barn/blob/main/internal/cloudinit/scripts/private-contract.sh) |
| Host SSH aliases point to the loopback forward | [access.go](https://github.com/pgsty/barn/blob/main/internal/linuxvm/access.go); Pigsty [vagrant/ssh](https://github.com/pgsty/pigsty/blob/main/vagrant/ssh) |
| `stop` only shuts down cleanly | [vm/lifecycle.go](https://github.com/pgsty/barn/blob/main/internal/vm/lifecycle.go), [qmp.go](https://github.com/pgsty/barn/blob/main/internal/qmp/qmp.go) |
| Reserved range and `vm_hosts` validation | [subnet/layout.go](https://github.com/pgsty/barn/blob/main/internal/network/subnet/layout.go), [config/file.go](https://github.com/pgsty/barn/blob/main/internal/config/file.go); Pigsty [vip.yml](https://github.com/pgsty/pigsty/blob/main/roles/node/tasks/vip.yml) selects the NIC by inventory IP |
| Corrupt persistent disks are reset | [init-disks.sh](https://github.com/pgsty/barn/blob/main/internal/cloudinit/scripts/init-disks.sh); Pigsty [Vagrantfile.libvirt](https://github.com/pgsty/pigsty/blob/main/vagrant/Vagrantfile.libvirt) |
| No per-node persistent disk deletion; `purge` waits for shutdown | [cmd/barn/lifecycle.go](https://github.com/pgsty/barn/blob/main/cmd/barn/lifecycle.go); Pigsty [MySQL hardware test record](https://github.com/pgsty/pigsty/blob/main/roles/mysql/TESTING.zh-CN.md) |
| Selectors and `nodes_removed` | [cmd/barn/lifecycle.go](https://github.com/pgsty/barn/blob/main/cmd/barn/lifecycle.go), [diff.go](https://github.com/pgsty/barn/blob/main/internal/linuxvm/diff.go) |
| Pigsty entry points and default image | Pigsty [Makefile](https://github.com/pgsty/pigsty/blob/main/Makefile), [vagrant/Makefile](https://github.com/pgsty/pigsty/blob/main/vagrant/Makefile), [vagrant/config](https://github.com/pgsty/pigsty/blob/main/vagrant/config) |
{.wide .expand .evidence-table}
