Artifacts

Persistent workspace artifacts in Polycrate: artifacts/blocks/ and artifacts/secrets/ structure, snapshot path variables, and operational best practices.

Artifacts are files generated, required, or persistently stored in the workspace during action execution. They persist across container runs because the entire workspace is mounted at /workspace.

Directory Structure

acme-production-1/
├── workspace.poly
├── inventory.yml                  # Central Ansible inventory (workspace root)
├── secrets.poly.age               # Encrypted block secrets
├── blocks/
└── artifacts/
    ├── secrets/                   # Sensitive files (automatically encryptable with age)
    │   ├── id_rsa                 # Workspace SSH private key
    │   ├── id_rsa.pub             # Workspace SSH public key
    │   ├── kubeconfig.yml         # Central workspace kubeconfig
    │   └── my-app/                # Block-specific secret files
    │       └── api-key.txt
    └── blocks/                    # Non-sensitive block artifacts
        └── my-app/
            └── generated/
                └── manifests.yml
Path Sensitive Purpose
inventory.yml No Central Ansible inventory (YAML, in workspace root)
artifacts/secrets/ Yes Workspace-wide secrets (id_rsa, kubeconfig.yml)
artifacts/secrets/<block>/ Yes Block-specific secret files
artifacts/blocks/<block>/ No Persistent files generated by the block (manifests, exports)

Artifact Variables in Ansible Playbooks

Polycrate automatically creates the corresponding artifact directory for every block and exposes the paths in the Snapshot:

Variable Meaning Example (in container)
block.artifacts.path Active path (automatically resolved for container or --local) /workspace/artifacts/blocks/my-app
block.artifacts.localpath Absolute host path /home/user/.../artifacts/blocks/my-app
block.artifacts.containerpath Path inside the Polycrate container /workspace/artifacts/blocks/my-app
block.artifacts.secrets.path Active path to the block's secrets /workspace/artifacts/secrets/my-app
workspace.secrets['<file>'] Path to a workspace secret file /workspace/artifacts/secrets/id_rsa
block.secrets['<file>'] Path to a block secret file /workspace/artifacts/secrets/my-app/api-key.txt

Standard Artifacts: Inventory and Kubeconfig

1. Ansible Inventory (inventory.yml)

The inventory resides as a YAML file directly in the workspace root (inventory.yml). Polycrate automatically sets ANSIBLE_INVENTORY to this path.

2. Kubernetes Kubeconfig (artifacts/secrets/kubeconfig.yml)

The central kubeconfig belongs at artifacts/secrets/kubeconfig.yml so that it is automatically protected by polycrate workspace encrypt.

On every polycrate run, the CLI automatically injects KUBECONFIG and K8S_AUTH_KUBECONFIG into the container. Playbooks therefore target the cluster without passing explicit --kubeconfig parameters:

# ✅ Correct: rely on auto-KUBECONFIG / K8S_AUTH_KUBECONFIG
- name: Apply generated manifest
  hosts: localhost
  gather_facts: false
  tasks:
    - name: Apply manifest from block artifacts
      kubernetes.core.k8s:
        state: present
        src: "{{ block.artifacts.path }}/generated/manifests.yml"

Generating and Reading Artifacts

# Example: render and persist configuration
- name: Generate configuration
  hosts: localhost
  gather_facts: false
  tasks:
    - name: Ensure target directory exists
      ansible.builtin.file:
        path: "{{ block.artifacts.path }}/generated"
        state: directory
        mode: "0755"

    - name: Write manifest from Jinja2 template
      ansible.builtin.template:
        src: templates/configmap.yml.j2
        dest: "{{ block.artifacts.path }}/generated/configmap.yml"
        mode: "0644"

Isolation Between Blocks

Artifacts under artifacts/blocks/<block>/ belong exclusively to their respective block. There is no automatic file sharing between blocks or workflow steps. Files needed by multiple blocks (such as inventory.yml or artifacts/secrets/kubeconfig.yml) are stored at the designated workspace-wide standard paths.

Customizing the Artifacts Root

If required, the base directory can be changed in workspace.poly via config.artifactsroot (single word, no underscore):

config:
  artifactsroot: artifacts

Best Practices

  1. Version reproducible artifacts: Non-sensitive files under artifacts/blocks/ can be committed to Git so changes remain traceable.
  2. Keep temporary caches in /tmp: Large downloads, package caches, or temporary build files belong in /tmp inside the container, not in artifacts/.
  3. Always encrypt secrets: All files under artifacts/secrets/ are converted to .age files by polycrate workspace encrypt and should only be committed afterward.

See Also