docs/tutorials/using-templates-with-variables
Intermediate10 min

Using templates with variables

Stop copy-pasting commands with different arguments. Templates let you define a command once and fill in variables at runtime.

The problem

You probably have commands like these that you run constantly with different values:

kubectl logs my-app-7d9f8c -n production --tail 100kubectl logs auth-service-abc -n staging --tail 50kubectl logs frontend-xyz -n production --tail 200

Same command, different values every time. Templates solve this.

01Create a template

recall template save kube-logs "kubectl logs {pod} -n {namespace} --tail {lines}"✔ Template "kube-logs" saved Variables: {pod}, {namespace}, {lines}

02Run the template

recall template run kube-logs? pod: my-app-7d9f8c? namespace: production? lines: 100 Rendered: kubectl logs my-app-7d9f8c -n production --tail 100? Run this command? Yes

More examples

docker-run
docker run -it --rm -v $(pwd):/app {image} bash
vars: image
pg-dump
pg_dump -U {user} -h {host} {database} > {output}.sql
vars: user, host, database, output
ssh-tunnel
ssh -L {local_port}:localhost:{remote_port} {user}@{host}
vars: local_port, remote_port, user, host
aws-s3-sync
aws s3 sync {local_dir} s3://{bucket}/{prefix} --delete
vars: local_dir, bucket, prefix

Preview without running

recall template run kube-logs --dry-run
// what's next
Share templates with your team using org vaults Import commands from your existing dotfiles