Overview
Every step of Capsule setup that’s normally interactive in the TUI has a non-interactive CLI equivalent, so a fresh server can be fully provisioned from a playbook: install the binary, authenticate, add database connections, schedule backups, and install the systemd service. Secrets (your license key, database passwords, MongoDB URIs) are always passed as environment variables, never as plain command-line flags — so they never land in shell history,ps output, or Ansible’s own command logging.
Full example playbook
Step by step
1. Install the binary
creates: /usr/local/bin/capsule makes this idempotent — Ansible skips the install script entirely on subsequent runs once the binary exists.
2. Authenticate
capsule auth prompts interactively for your license key. It also checks CAPSULE_LICENSE_KEY in the environment first — if set, it skips the prompt entirely and saves that key. Keep the key in Ansible Vault, never in plain YAML.
3. Add connections
capsule connection add normally prompts for the password with input hidden. Setting CAPSULE_CONN_PASSWORD in the task’s environment skips that prompt. For MongoDB, use --type mongo and set CAPSULE_CONN_URI instead (see capsule connection for the full flag reference).
Re-running add for a label that already exists fails with a connection named "..." already exists — the failed_when above treats that as a no-op so the playbook stays idempotent instead of erroring on every re-run.
4. Schedule backups
schedule add upserts by connection label — re-running it with the same cron expression is naturally idempotent, no special handling needed. See capsule schedule for pausing/resuming and other subcommands.
5. Install the service
install-service must run as root (become: true) and creates a systemd unit that starts on boot and restarts on failure. The daemon’s working directory is always the invoking user’s home directory (resolved via $SUDO_USER when run under sudo, so it correctly picks the human user’s home rather than /root) — it isn’t configurable through chdir or any other Ansible task option. See capsule service for details.
Backing up a dockerized database
If the target database runs in a container on the same host, add--docker <container_name> to the connection:
docker exec -i myapp_postgres pg_dump ... instead of natively — you don’t need the Postgres client tools installed on the host, just Docker itself. Run capsule doctor afterward to confirm everything required is reachable.
Updating a schedule
schedule add upserts by connection label, so changing a cron expression later is just re-running the same task with a new value — no separate “update” step needed:
vars file changes, re-running the play applies it; if it’s unchanged, the daemon just re-reads the same value.
Rotating database credentials
Unlike connections,capsule connection add refuses to touch an existing label (a connection named "..." already exists) — it’s meant for first-time creation, not updates. Use capsule connection update instead, which changes fields in place on the same connection ID, so its attached schedule is left untouched:
no_log: true on this task — otherwise Ansible may echo the task’s resolved environment into its own output/logs on failure, which would leak the new password into your CI logs.
This also works for a host change, without touching the password:
Verifying the setup
See also
capsule auth— license key authentication detailscapsule connection— full flag reference, including MongoDB URIscapsule schedule— cron expressions, pause/resume, live reloadcapsule service— systemd service management