Snapshot

The Polycrate workspace snapshot captures resolved workspace, block, and action config for Ansible and debugging via workspace snapshot and run --snapshot.

Before every action run, Polycrate generates a workspace snapshot — a complete, resolved YAML capture of the workspace, block, and action configuration. This snapshot makes runs deterministically traceable and supplies the top-level variables for Ansible playbooks.

How the Snapshot Works

graph TB
    Start[polycrate run block action] --> Load[Load workspace + secrets.poly]
    Load --> Merge[Resolve inheritance & deep-merge]
    Merge --> Snap[Generate snapshot YAML]
    Snap --> Mount[Mount into container via POLYCRATE_WORKSPACE_SNAPSHOT_YAML]
    Mount --> Vars[Ansible vars plugin exposes workspace / block / action]
    Vars --> Exec[Ansible playbook runs]

Contents of a Snapshot

  1. workspace: Complete workspace configuration (name, organization, config), all resolved blocks, and the file paths to inventory.yml and artifacts/secrets/kubeconfig.yml (not their contents).
  2. block: The currently executed block after inheritance and merging with secrets.poly, including artifacts and secrets paths.
  3. action: Metadata and action.config (including any --set overrides) for the invoked action.
  4. env & mounts: All environment variables passed to the container (including POLYCRATE_WORKSPACE, POLYCRATE_WORKSPACE_SNAPSHOT_YAML, KUBECONFIG, K8S_AUTH_KUBECONFIG, ANSIBLE_INVENTORY) as well as host-to-container mounts.

Example Snapshot (Abbreviated)

workspace:
  name: acme-production-1
  organization: acme
  config:
    image:
      reference: cargo.ayedo.cloud/library/polycrate
      version: "0.71.0"
    blocksroot: blocks
    artifactsroot: artifacts
    secretsroot: artifacts/secrets
    containerroot: /workspace
  inventory:
    path: inventory.yml
    localpath: /home/user/.polycrate/workspaces/acme/acme-production-1/inventory.yml
    containerpath: /workspace/inventory.yml
  kubeconfig:
    path: artifacts/secrets/kubeconfig.yml
    localpath: /home/user/.polycrate/workspaces/acme/acme-production-1/artifacts/secrets/kubeconfig.yml
    containerpath: /workspace/artifacts/secrets/kubeconfig.yml

block:
  name: postgres
  kind: k8sapp
  version: 1.8.0
  from: cargo.ayedo.cloud/ayedo/k8s/cloudnative-pg:1.8.0
  config:
    namespace: databases
    instances: 3

action:
  name: install
  playbook: install.yml

env:
  POLYCRATE_WORKSPACE: /workspace
  POLYCRATE_WORKSPACE_SNAPSHOT_YAML: /tmp/polycrate-snapshot.yml
  KUBECONFIG: /workspace/artifacts/secrets/kubeconfig.yml
  K8S_AUTH_KUBECONFIG: /workspace/artifacts/secrets/kubeconfig.yml
  ANSIBLE_INVENTORY: /workspace/inventory.yml

Inspecting a Snapshot

# Print the workspace snapshot
polycrate workspace snapshot

# Print the action snapshot (without executing the action)
polycrate run postgres install --snapshot

# Write to a file for analysis or filter with yq
polycrate run postgres install --snapshot | yq '.block.config'

Using the Snapshot in Ansible Playbooks

The Ansible vars plugin bundled in the Polycrate container loads the snapshot file automatically from POLYCRATE_WORKSPACE_SNAPSHOT_YAML and exposes workspace, block, action, and transaction directly as top-level variables:

- name: Deploy application
  hosts: localhost
  gather_facts: false
  tasks:
    - name: Display resolved parameters
      ansible.builtin.debug:
        msg: "Deploying {{ block.name }} into namespace {{ block.config.namespace }} (workspace {{ workspace.name }})"

Debugging Checklist

When an action behaves unexpectedly, polycrate run <block> <action> --snapshot gives immediate clarity:

  • Were all values from block.poly, workspace.poly, and secrets.poly merged as expected?
  • Do workspace.inventory.containerpath and workspace.kubeconfig.containerpath point to the expected files?
  • Did --set overrides land correctly under action.config?

See Also