Snapshot

Der Polycrate Workspace-Snapshot fasst die aufgelöste Workspace-, Block- und Action-Konfiguration für Ansible und Debugging zusammen – über workspace snapshot und run --snapshot.

Vor jeder Action-Ausführung erzeugt Polycrate einen Workspace-Snapshot — eine vollständige, aufgelöste YAML-Momentaufnahme der Workspace-, Block- und Action-Konfiguration. Dieser Snapshot macht Läufe deterministisch nachvollziehbar und liefert die Top-Level-Variablen für Ansible-Playbooks.

Wie der Snapshot funktioniert

graph TB
    Start[polycrate run block action] --> Load[Workspace + secrets.poly laden]
    Load --> Merge[Vererbung & Deep-Merge auflösen]
    Merge --> Snap[Snapshot-YAML erzeugen]
    Snap --> Mount[Mount in Container via POLYCRATE_WORKSPACE_SNAPSHOT_YAML]
    Mount --> Vars[Ansible Vars-Plugin stellt workspace / block / action bereit]
    Vars --> Exec[Ansible-Playbook läuft]

Inhalt eines Snapshots

  1. workspace: Vollständige Workspace-Konfiguration (name, organization, config), alle aufgelösten Blöcke sowie die Dateipfade zu inventory.yml und artifacts/secrets/kubeconfig.yml (nicht deren Inhalt).
  2. block: Der aktuell ausgeführte Block nach Vererbung und Merge mit secrets.poly inklusive artifacts- und secrets-Pfaden.
  3. action: Metadaten und action.config (inklusive etwaiger --set-Overrides) der gestarteten Action.
  4. env & mounts: Alle an den Container übergebenen Umgebungsvariablen (u. a. POLYCRATE_WORKSPACE, POLYCRATE_WORKSPACE_SNAPSHOT_YAML, KUBECONFIG, K8S_AUTH_KUBECONFIG, ANSIBLE_INVENTORY) sowie Host-zu-Container-Mounts.

Beispiel-Snapshot (gekürzt)

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

Snapshot inspizieren

# Workspace-Snapshot ausgeben
polycrate workspace snapshot

# Action-Snapshot ausgeben (ohne Action auszuführen)
polycrate run postgres install --snapshot

# Zur Analyse in eine Datei schreiben oder mit yq filtern
polycrate run postgres install --snapshot | yq '.block.config'

Snapshot in Ansible-Playbooks nutzen

Das im Polycrate-Container enthaltene Ansible-Vars-Plugin lädt die Snapshot-Datei automatisch aus POLYCRATE_WORKSPACE_SNAPSHOT_YAML und stellt workspace, block, action und transaction direkt als Top-Level-Variablen bereit:

- name: Anwendung deployen
  hosts: localhost
  gather_facts: false
  tasks:
    - name: Aufgelöste Parameter anzeigen
      ansible.builtin.debug:
        msg: "Deploye {{ block.name }} in Namespace {{ block.config.namespace }} (Workspace {{ workspace.name }})"

Debugging-Checkliste

Wenn eine Action sich unerwartet verhält, liefert polycrate run <block> <action> --snapshot in Sekunden Klarheit:

  • Wurden alle Werte aus block.poly, workspace.poly und secrets.poly wie erwartet zusammengeführt?
  • Zeigen workspace.inventory.containerpath und workspace.kubeconfig.containerpath auf die erwarteten Dateien?
  • Sind --set-Overrides korrekt unter action.config angekommen?

Siehe auch