YAML recipes in. One plain /bin/sh script out.

Write down what a box should look like in YAML, compile it to one plain POSIX shell script, and read the whole thing in a pull request before it touches a server. The target only needs /bin/sh.

homelab.yml

YAML
strapped:
  name: homelab
  target: linux

packages:
  - curl
  - git
  - smartmontools
  - name: nfs-kernel-server
    dnf: nfs-utils
    pacman: nfs-utils

dirs:
  - path: /srv/media
    mode: "0755"

lines:
  - path: /etc/exports
    line: "/srv/media 192.168.1.0/24(ro)"
    notify: reload-exports

symlinks:
  - src: /srv/media
    dest: /home/media

services:
  - name: smartd
    state: enabled

handlers:
  reload-exports:
    apply: exportfs -ra

setup.sh

#!/bin/sh
# Generated by strapped 2.0.0 from homelab.yml
set -eu
# … flags, linux target guard, helpers, steps 1–3

step_check_4() {
    pkg_detect
    case "$PKG_MGR" in
        dnf) _p='nfs-utils' ;;
        pacman) _p='nfs-utils' ;;
        *) _p='nfs-kernel-server' ;;
    esac
    pkg_has "$_p"
}
step_check_5() {
    [ -d '/srv/media' ] || return 1
    [ "$(path_mode '/srv/media')" = '755' ]
}
step_apply_5() {
    mkdir -p '/srv/media'
    chmod '0755' '/srv/media'
}

if step_select 'line:/etc/exports'; then
    if step_check_6 >/dev/null; then
        printf '[ok] %s\n' 'line:/etc/exports'
    elif step_should_apply 'line:/etc/exports'; then
        step_begin 'line:/etc/exports'
        step_apply_6
        step_finish 'changed' 'line:/etc/exports'
        NOTIFY_RELOAD_EXPORTS=1
    fi
fi

if [ "$MODE" = 'apply' ]; then run_handlers; fi
if [ "$DRIFT" -ne 0 ]; then exit 2; fi
exit 0
Lines
458
eval
none
shellcheck -s sh
0 warnings

Real strapped compile output, trimmed at # … to keep the steps on screen. Every full script passes sh -n and shellcheck -s sh cleanly. The Alpine transcript is from a fresh alpine:3 container; the other two show what drift looks like before applying.

Eight primitives cover most of a machine

Every entry compiles to a named step with a check and an apply. The script checks first and only changes what has drifted, so a second run leaves a converged box untouched.

PrimitiveWhat it setsHow it checks
packagesInstalls packages with apt-get, apk, dnf, pacman, or brew, with per-manager name overrides when distros disagree.Queries the package database directly: dpkg-query, apk info -e, rpm -q, pacman -Qi, brew list.
dirsCreates directories and sets their mode and owner.[ -d ], then compares octal mode and owner.
filesWrites whole files atomically from inline content or a local src read at compile time. Always literal; preserves existing mode or uses 0666 & ~umask when mode is omitted.Compares bytes with cmp -s against a single-quoted heredoc in the script.
linesEnsures one exact literal line is present in a file, creating parent directories and appending it if missing.grep -Fqx
symlinksPoints a symlink at a target path, replacing any existing link.readlink
gitClones a repository to a path, optionally pinned to a branch, tag, or commit.Checks for the checkout and compares HEAD against ref.
servicesSets a systemd or OpenRC service to running, stopped, enabled, or disabled.systemctl is-active / is-enabled, or rc-service / rc-update.
stepsAnything else, written as your own POSIX shell check and apply.Your check command, verbatim.

Local straps, compiled in

Drop a reusable step template into straps/ beside your recipes and call it by filename. strapped substitutes each parameter with POSIX quoting in a single pass at compile time; nothing is pulled from a registry when the script runs.

# straps/sysctl.yml
name: sysctl
params: [key, value]
check: |
  [ "$(sysctl -n {{key}})" = {{value}} ]
apply: |
  sysctl -w {{key}}={{value}}

# ssh-box.yml
sysctl:
  - key: vm.swappiness
    value: "10"

Handlers run once, at the end

Steps can notify named handlers. A changed step flips a static shell flag; after the last step finishes, each flagged handler runs once in definition order. Every handler is a plain shell function, never looked up through eval.

lines:
  - path: /etc/exports
    line: "/srv/media 10.0.0.0/24(ro)"
    notify: reload-exports

handlers:
  reload-exports:
    apply: exportfs -ra

Secrets stay out of recipes

Declare secret names under env_required and reference ${VAR:?missing} in steps, handlers, or strap parameters; files and lines stay literal. The script exits before step one if a variable is unset, and strapped refuses hardcoded tokens or private keys.

strapped:
  env_required: [REGISTRY_TOKEN]

steps:
  - name: registry-auth
    check: test -s ~/.auth
    apply: |
      printf '%s\n' \
        "${REGISTRY_TOKEN:?missing}" \
        > ~/.auth

Where it fits

Use strapped.sh for machines you want to rebuild from one reviewed file: homelab servers, small VPSes, throwaway VMs, containers, or a repository's setup script. Keep your daily workstation on dotfiles and package managers built for it.

ToolReach for it whenTarget needsWhat you review
strapped.shYou want a reproducible box and want to read every line that will run on it./bin/sh and the host's own package manager.One compiled script, diffable in a pull request.
mise and chezmoiYou are configuring your daily workstation: tool versions, dotfiles, per-machine templates.mise and chezmoi installed.Your dotfiles repository and mise.toml. strapped.sh does not try to replace them.
AnsibleYou run a fleet: inventories, cross-host orchestration, and a large module library.Python on each host and Ansible on the controller.Playbooks and roles; the actual commands are resolved at run time.
A hand-written scriptYou have a one-off with five commands./bin/sh.Whatever you wrote. Checking before changing, --check, and safe reruns are on you.

Install

Install strapped on your workstation or CI runner. Compilation needs /bin/sh and YAML.sh (ysh); the target machine only runs the compiled script.

  • With Homebrew

    brew install azohra/tools/strapped
  • With the install script

    curl -fsSL https://strapped.azohra.com/install | sh

Quickstart

  1. Write a recipe.

    strapped:
      name: box
      target: linux
    
    packages:
      - curl
      - htop
    
    lines:
      - path: /etc/hosts
        line: "192.168.1.20 nas.lan nas"
  2. Compile it, then read the output.

    strapped compile box.yml -o setup.sh
  3. Copy it over and check for drift without changing anything.

    scp setup.sh box: && ssh box sh setup.sh --check
  4. Apply it. Run it again anytime; converged steps print [ok] and skip work.

    ssh -t box sudo sh setup.sh