- Home
- Skills
- Workflow Automation
- Manual Step To Bash Wizard
Works with the AI Agents you already use
Manual Step To Bash Wizard
Reads a runbook, checklist or manual procedure and returns one runnable bash script that walks a person through it
$5
/moSubscription · cancel anytime
Secure checkout via Stripe
- Always the latest version
- Delivered live to your agent via MCP
- Cancel anytime, access ends at period end
Manual Step To Bash Wizard
Example session with this skill installed
We rotate the prod database password by hand every quarter and someone always skips a step. Here's the runbook - turn it into something I can actually run:
- Generate a new 32-character password.
- In psql as the admin user: ALTER ROLE app_user WITH PASSWORD '<new>';
- aws secretsmanager put-secret-value --secret-id prod/app/db-password --secret-string '<new>'
- kubectl -n prod rollout restart deploy/api and wait for it to finish.
- Watch the API error rate in Grafana for 10 minutes. If it climbs, roll back by repeating step 2 with the old password.
- Update the "Prod DB app_user" entry in 1Password.
- Post in #ops that the rotation is done.
- Read your context and instructions
- Compiled the manual step to
What this wizard does
It runs the quarterly rotation of the prod app_user Postgres password from start to finish: it generates the password, changes the role, updates the secret, restarts the API, watches it, updates 1Password and posts to #ops. If a run is interrupted, running it again carries on from where it stopped. A successful run leaves the new password in Postgres, Secrets Manager and 1Password, and deletes its own state directory. A rollback puts the old password back in Postgres and in the secret, then restarts the API.
Step triage
| # | step | automate / ask / check | why |
|---|---|---|---|
| 0a | Confirm AWS account and kubectl context | ask | Nothing in the runbook says which cluster or account is prod. The script shows sts get-caller-identity and current-context and you confirm (default No). This stops a rotation against the wrong environment. |
| 0b | Postgres host, port, database, admin role | ask | The runbook only says "in psql as the admin user". Each answer is checked against a pattern, tested with select 1, and saved so a resumed run doesn't ask again. |
| 1 | Generate a 32-char password | automate | Uses openssl rand with alphanumerics only, so there are no quoting problems in SQL, the shell or JSON. Before changing anything it saves the current secret as the rollback value. It checks that the secret is a bare string and not JSON, and that app_user can log in with it. If either fails, the secret and the DB already disagree and the rotation stops. |
| 2 | ALTER ROLE app_user ... | automate after confirm, then check | This is where the outage window opens. New connections that still use the old password start failing at this point. The script shows the statement and defaults to No. It sends the password to psql on stdin, not in argv. It counts the step as done when app_user can log in with the new password. |
| 3 | put-secret-value | automate + check | No confirm here, because the previous version stays in Secrets Manager and step 2 already committed you. The script reads the secret from file:// so it never appears in argv, and skips the step if the secret already holds the new value. |
| 4 | rollout restart and wait | automate + check | Runs rollout status --timeout, which can fail. A marker file stops a resumed run from restarting a second time. |
| 5 | Watch Grafana for 10 min | ask | The runbook has no Grafana URL, query or threshold, so you judge the graph. The script times the 10 minutes and then asks you to type healthy or rollback (no default). |
| 5r | Rollback | automate | The runbook's rollback is incomplete. By step 5 the pods hold the new password, so reverting only Postgres breaks every new connection. The script reverts Postgres, puts the old value back into the secret and restarts again. |
| 6 | Update 1Password | automate if op is signed in, else ask | Uses op item edit and then checks the result with op item get --reveal. If op isn't available, you do it by hand and type updated. |
| 7 | Post in #ops | ask | Uses a webhook if OPS_SLACK_WEBHOOK_URL is set, after you confirm (default No, because a message can't be unsent). Otherwise it prints the message for you to paste and you type posted. |
The script
#!/usr/bin/env bash
# rotate-prod-db-password.sh - quarterly rotation of the prod app_user Postgres password.
# Usage: rotate-prod-db-password.sh [--dry-run] [--rollback]
#
# Safe to re-run: each step checks whether it is already done and skips it.
# Working state (new + old password, connection details) is kept mode 0600 in
# $STATE_DIR until the rotation finishes or is rolled back, then removed.
set -euo pipefail
umask 077
SECRET_ID="prod/app/db-password"
DB_ROLE="app_user"
K8S_NAMESPACE="prod"
K8S_DEPLOYMENT="deploy/api"
OP_ITEM="Prod DB app_user"
OP_FIELD="${OP_FIELD:-password}" # label of the password field in the 1Password item
WATCH_MINUTES=10
ROLLOUT_TIMEOUT="${ROLLOUT_TIMEOUT:-10m}"
STATE_DIR="${XDG_STATE_HOME:-$HOME/.local/state}/rotate-prod-db-password"
DRY_RUN=0
MODE=rotate
usage() { echo "Usage: $0 [--dry-run] [--rollback]" >&2; exit 2; }
for arg in "$@"; do
case $arg in
--dry-run) DRY_RUN=1 ;;
--rollback) MODE=rollback ;;
*) usage ;;
esac
done
# ---------- helpers ----------
say() { printf '\n==> %s\n' "$*"; }
info() { printf ' %s\n' "$*"; }
die() { printf '\nERROR: %s\n' "$*" >&2; exit 1; }
# Print a command, then run it (only print under --dry-run). Never pass secrets through this.
run() {
printf ' $ %s\n' "$*"
if [[ $DRY_RUN -eq 1 ]]; then return 0; fi
"$@"
}
# confirm "question" -> 0 for yes. Default: No.
confirm() {
local answer
if [[ $DRY_RUN -eq 1 ]]; then info "[dry-run] would ask: $1 [y/N]"; return 0; fi
while true; do
read -r -p " $1 [y/N] " answer
case $answer in
[yY]|[yY][eE][sS]) return 0 ;;
""|[nN]|[nN][oO]) return 1 ;;
*) info "Answer y or n." ;;
esac
done
}
# choose "question" opt... -> prints the option typed. No default: one must be typed exactly.
choose() {
local question=$1 answer opt; shift
if [[ $DRY_RUN -eq 1 ]]; then printf ' [dry-run] would ask: %s (%s)\n' "$question" "$*" >&2; printf '%s' "$1"; return 0; fi
while true; do
read -r -p " $question ($(IFS=/; echo "$*"), no default): " answer
for opt in "$@"; do
if [[ $answer == "$opt" ]]; then printf '%s' "$opt"; return 0; fi
done
printf ' Type exactly one of: %s\n' "$*" >&2
done
}
# ask_value "question" "default" "regex" -> prints the validated answer. Re-asks on bad input.
ask_value() {
local question=$1 default=$2 pattern=$3 answer
if [[ $DRY_RUN -eq 1 ]]; then printf '%s' "${default:-<$question>}"; return 0; fi
while true; do
read -r -p " $question [${default:-no default}]: " answer
answer=${answer:-$default}
if [[ $answer =~ $pattern ]]; then printf '%s' "$answer"; return 0; fi
printf ' "%s" is not valid (expected %s). Try again.\n' "$answer" "$pattern" >&2
done
}
mark_done() { if [[ $DRY_RUN -eq 0 ]]; then : > "$STATE_DIR/done.$1"; fi; }
is_done() { [[ -f $STATE_DIR/done.$1 ]]; }
# saved_password new|old
saved_password() {
if [[ $DRY_RUN -eq 1 ]]; then printf '<%s password>' "$1"; return 0; fi
[[ -f $STATE_DIR/$1.pw ]] || die "No saved $1 password in $STATE_DIR - no rotation in progress."
printf '%s' "$(<"$STATE_DIR/$1.pw")"
}
current_secret() {
aws secretsmanager get-secret-value --secret-id "$SECRET_ID" --query SecretString --output text
}
psql_admin() { PGUSER=$DB_ADMIN psql -X -q -At -v ON_ERROR_STOP=1 "$@"; }
app_user_can_login() {
if [[ $DRY_RUN -eq 1 ]]; then return 1; fi
PGUSER=$DB_ROLE PGPASSWORD=$1 psql -X -q -At -w -c 'select 1' >/dev/null 2>&1
}
# Password goes to psql on stdin, never in argv. Passwords are alphanumeric, so \set is safe.
set_role_password() {
info "\$ psql: ALTER ROLE $DB_ROLE WITH PASSWORD '<redacted>';"
if [[ $DRY_RUN -eq 1 ]]; then return 0; fi
printf '\\set pw %s\nALTER ROLE %s WITH PASSWORD :'"'"'pw'"'"';\n' "$1" "$DB_ROLE" | psql_admin
}
restart_and_wait() {
run kubectl -n "$K8S_NAMESPACE" rollout restart "$K8S_DEPLOYMENT"
run kubectl -n "$K8S_NAMESPACE" rollout status "$K8S_DEPLOYMENT" --timeout="$ROLLOUT_TIMEOUT"
}
cleanup_state() {
if [[ $DRY_RUN -eq 1 ]]; then return 0; fi
rm -f "$STATE_DIR"/new.pw "$STATE_DIR"/old.pw "$STATE_DIR"/db.env "$STATE_DIR"/rolling_back "$STATE_DIR"/done.*
rmdir "$STATE_DIR" 2>/dev/null || true
}
# ---------- steps ----------
preflight() {
say "Preflight"
local tool account context
for tool in openssl psql aws kubectl; do
command -v "$tool" >/dev/null || die "$tool is not on PATH."
done
if [[ $DRY_RUN -eq 1 ]]; then
info "[dry-run] would show AWS account and kubectl context and ask to confirm."
return 0
fi
mkdir -p "$STATE_DIR"
account=$(aws sts get-caller-identity --query Account --output text) || die "AWS credentials are not working."
context=$(kubectl config current-context) || die "No current kubectl context."
kubectl -n "$K8S_NAMESPACE" get "$K8S_DEPLOYMENT" >/dev/null || die "$K8S_DEPLOYMENT not found in namespace $K8S_NAMESPACE."
info "AWS account: $account"
info "kubectl context: $context"
info "Secret: $SECRET_ID"
info "Deployment: $K8S_DEPLOYMENT (namespace $K8S_NAMESPACE)"
info "Mode: $MODE"
confirm "Is this production, and do you want to continue?" || die "Stopped at preflight; nothing changed."
}
configure_db_connection() {
say "Postgres connection"
if [[ -f $STATE_DIR/db.env ]]; then
# shellcheck disable=SC1091
source "$STATE_DIR/db.env"
info "Reusing $DB_ADMIN@$PGHOST:$PGPORT/$PGDATABASE from the earlier run."
else
PGHOST=${PGHOST:-$(ask_value "Prod Postgres host" "" '^[A-Za-z0-9.-]+$')}
PGPORT=${PGPORT:-$(ask_value "Postgres port" "5432" '^[0-9]{1,5}$')}
PGDATABASE=${PGDATABASE:-$(ask_value "Database $DB_ROLE connects to" "" '^[A-Za-z0-9_-]+$')}
DB_ADMIN=${DB_ADMIN:-$(ask_value "Admin role you run ALTER ROLE as" "" '^[A-Za-z0-9_-]+$')}
if [[ $DRY_RUN -eq 0 ]]; then
printf 'PGHOST=%q\nPGPORT=%q\nPGDATABASE=%q\nDB_ADMIN=%q\n' \
"$PGHOST" "$PGPORT" "$PGDATABASE" "$DB_ADMIN" > "$STATE_DIR/db.env"
fi
fi
export PGHOST PGPORT PGDATABASE
if [[ $DRY_RUN -eq 0 ]]; then
psql_admin -c 'select 1' >/dev/null \
|| die "Cannot connect as $DB_ADMIN to $PGHOST:$PGPORT/$PGDATABASE. Check VPN and ~/.pgpass."
fi
}
generate_password() {
say "Step 1/7: generate a new 32-character password"
if [[ -f $STATE_DIR/new.pw ]]; then info "Generated in an earlier run; reusing it."; return 0; fi
if [[ $DRY_RUN -eq 1 ]]; then
info "[dry-run] would save the current value of $SECRET_ID as the rollback password and generate a new one."
return 0
fi
local current pw=""
current=$(current_secret)
[[ -n $current ]] || die "$SECRET_ID is empty."
if [[ $current == \{* ]]; then
die "$SECRET_ID holds JSON, not a bare password; the runbook's put-secret-value would overwrite every key. Fix the runbook first."
fi
app_user_can_login "$current" || die "$DB_ROLE cannot log in with the password in $SECRET_ID from this machine.
Either the secret and the database already disagree (investigate before rotating), or this
machine cannot reach Postgres as $DB_ROLE (run from one that can - every step is verified that way)."
while [[ ${#pw} -lt 32 ]]; do
pw+=$(openssl rand -base64 48 | tr -dc 'A-Za-z0-9')
done
printf '%s' "$current" > "$STATE_DIR/old.pw"
printf '%s' "${pw:0:32}" > "$STATE_DIR/new.pw"
info "Saved under $STATE_DIR (mode 0600). The old password is kept for rollback."
}
set_db_password() {
say "Step 2/7: set the new password on $DB_ROLE in Postgres"
local new
new=$(saved_password new)
if app_user_can_login "$new"; then info "$DB_ROLE already logs in with the new password; skipping."; return 0; fi
info "About to run as $DB_ADMIN on ${PGHOST}/${PGDATABASE}:"
info " ALTER ROLE $DB_ROLE WITH PASSWORD '<new password>';"
info "From this moment, NEW connections using the old password fail. Running pods keep their open"
info "connections, but any pod that starts or reconnects before step 4 finishes will error."
info "Undo: $0 --rollback"
confirm "Change the password now?" || die "Stopped before step 2; nothing changed."
set_role_password "$new"
if [[ $DRY_RUN -eq 0 ]]; then
app_user_can_login "$new" || die "ALTER ROLE ran but $DB_ROLE cannot log in with the new password. Run: $0 --rollback"
fi
}
update_secret() {
say "Step 3/7: store the new password in Secrets Manager ($SECRET_ID)"
if [[ $DRY_RUN -eq 0 ]]; then
local new current
new=$(saved_password new)
current=$(current_secret)
if [[ $current == "$new" ]]; then info "Secret already holds the new password; skipping."; return 0; fi
fi
run aws secretsmanager put-secret-value --secret-id "$SECRET_ID" \
--secret-string "file://$STATE_DIR/new.pw" --query VersionId --output text
}
restart_api() {
say "Step 4/7: restart $K8S_DEPLOYMENT so pods load the new secret"
if is_done restart; then
info "Restart already triggered in an earlier run; waiting for it."
run kubectl -n "$K8S_NAMESPACE" rollout status "$K8S_DEPLOYMENT" --timeout="$ROLLOUT_TIMEOUT" \
|| die "Rollout did not finish within $ROLLOUT_TIMEOUT. Investigate, or run: $0 --rollback"
return 0
fi
run kubectl -n "$K8S_NAMESPACE" rollout restart "$K8S_DEPLOYMENT"
mark_done restart
run kubectl -n "$K8S_NAMESPACE" rollout status "$K8S_DEPLOYMENT" --timeout="$ROLLOUT_TIMEOUT" \
|| die "Rollout did not finish within $ROLLOUT_TIMEOUT. Investigate, or run: $0 --rollback"
}
watch_error_rate() {
say "Step 5/7: watch the API error rate in Grafana for $WATCH_MINUTES minutes"
if is_done watch; then info "Already watched and confirmed healthy; skipping."; return 0; fi
if [[ -n ${GRAFANA_URL:-} ]]; then info "Dashboard: $GRAFANA_URL"; fi
info "Open the API error-rate panel now. If it climbs before the timer ends, press Ctrl-C and run: $0 --rollback"
if [[ $DRY_RUN -eq 0 ]]; then
local m
for (( m = WATCH_MINUTES; m > 0; m-- )); do
printf '\r %2d minute(s) left ' "$m"
sleep 60
done
printf '\r Time is up. \n'
fi
case $(choose "Error rate over the last $WATCH_MINUTES minutes" healthy rollback) in
healthy) mark_done watch ;;
rollback) rollback ;;
esac
}
update_1password() {
say "Step 6/7: update \"$OP_ITEM\" in 1Password"
if is_done onepassword; then info "Already updated; skipping."; return 0; fi
local new
new=$(saved_password new)
if command -v op >/dev/null && op whoami >/dev/null 2>&1; then
if [[ $DRY_RUN -eq 0 && $(op item get "$OP_ITEM" --fields "label=$OP_FIELD" --reveal 2>/dev/null) == "$new" ]]; then
info "1Password already holds the new password; skipping."
mark_done onepassword
return 0
fi
info "\$ op item edit \"$OP_ITEM\" \"$OP_FIELD=<new password>\""
if [[ $DRY_RUN -eq 0 ]]; then
op item edit "$OP_ITEM" "$OP_FIELD=$new" >/dev/null
[[ $(op item get "$OP_ITEM" --fields "label=$OP_FIELD" --reveal) == "$new" ]] \
|| die "1Password field \"$OP_FIELD\" does not hold the new password after editing. Check the field label (OP_FIELD)."
fi
mark_done onepassword
return 0
fi
info "The 1Password CLI (op) is not installed or not signed in, so this step is manual."
if confirm "Show the new password on screen so you can paste it?"; then printf ' %s\n' "$new"; fi
choose "Type 'updated' once \"$OP_ITEM\" holds the new password" updated >/dev/null
mark_done onepassword
}
announce_in_ops() {
say "Step 7/7: post in #ops"
if is_done announce; then info "Already posted; skipping."; return 0; fi
local msg
msg="Prod DB password rotation done: $DB_ROLE password changed, $SECRET_ID updated, $K8S_DEPLOYMENT restarted, error rate flat for ${WATCH_MINUTES}m, 1Password \"$OP_ITEM\" updated. ($(date -u +%Y-%m-%dT%H:%MZ))"
info "Message: $msg"
if [[ -n ${OPS_SLACK_WEBHOOK_URL:-} ]] && confirm "Post this to #ops via the webhook? It cannot be unsent."; then
info "\$ curl -fsS -X POST -H 'Content-type: application/json' --data <message> <OPS_SLACK_WEBHOOK_URL>"
if [[ $DRY_RUN -eq 0 ]]; then
curl -fsS -X POST -H 'Content-type: application/json' \
--data "{\"text\":\"${msg//\"/\\\"}\"}" "$OPS_SLACK_WEBHOOK_URL" >/dev/null
fi
else
info "Paste the message above into #ops."
choose "Type 'posted' once it is in #ops" posted >/dev/null
fi
mark_done announce
}
# The runbook's rollback reverts only Postgres. By step 4 the pods hold the NEW password,
# so the secret is reverted and the API restarted too, leaving everything on the old password.
rollback() {
say "ROLLBACK: restoring the old password in Postgres and Secrets Manager"
local old current
old=$(saved_password old)
if [[ $DRY_RUN -eq 0 ]]; then : > "$STATE_DIR/rolling_back"; fi
if app_user_can_login "$old"; then
info "Postgres already accepts the old password; skipping ALTER ROLE."
else
set_role_password "$old"
fi
if [[ $DRY_RUN -eq 0 ]]; then current=$(current_secret); else current=""; fi
if [[ $current == "$old" ]]; then
info "Secret already holds the old password; skipping."
else
run aws secretsmanager put-secret-value --secret-id "$SECRET_ID" \
--secret-string "file://$STATE_DIR/old.pw" --query VersionId --output text
fi
restart_and_wait || die "Rollback restart did not finish within $ROLLOUT_TIMEOUT. Re-run: $0 --rollback"
cleanup_state
say "Rolled back. Post in #ops that the rotation was rolled back and why."
exit 1
}
main() {
preflight
configure_db_connection
if [[ $MODE == rollback || -f $STATE_DIR/rolling_back ]]; then rollback; fi
generate_password
set_db_password
update_secret
restart_api
watch_error_rate
update_1password
announce_in_ops
cleanup_state
say "Rotation complete."
}
main
Not in the script
Reading the Grafana panel. The runbook doesn't name a dashboard, query or error-rate threshold, so the script can't decide "it climbed". It times the window and you make the call. Set GRAFANA_URL to have the link printed.
How pods get the secret. Nothing in the runbook says whether pods read prod/app/db-password directly at startup or through a sync layer such as External Secrets or the CSI driver. If a sync layer has a refresh interval, step 4 can restart pods onto the old value and step 5 will show errors. Check this before the first run. If there is a sync layer, force a sync between steps 3 and 4.
The outage window between steps 2 and 4. The runbook's order causes this with a single role. The script makes the window short but can't remove it. Removing it needs two alternating roles (app_user_a and app_user_b), which is a change to the procedure itself.
Losing the state directory between steps 2 and 3. If that happens, the new password exists only in Postgres. Recover by running ALTER ROLE by hand with the old password, which is still in Secrets Manager as AWSCURRENT.
Before you run it
- Tools: bash,
openssl,psql,aws,kubectl, andcurl.op(1Password CLI v2, signed in) is optional; without it step 6 is manual. - Access you need:
- AWS credentials with
GetSecretValueandPutSecretValueonprod/app/db-password. - The kubectl context pointed at prod, with rights to restart
deploy/api. - The admin Postgres password in
~/.pgpass. Without it, psql asks for it on every call.
- AWS credentials with
- This machine must be able to log in to Postgres as
app_user. Every DB step is checked that way, and the run stops before changing anything if it can't. - If Postgres has
log_statement = ddlorall, theALTER ROLEpassword goes into the server log in plaintext. This is just as true when you run the step by hand. - Optional settings:
GRAFANA_URL,OPS_SLACK_WEBHOOK_URL,OP_FIELD(defaultpassword),ROLLOUT_TIMEOUT(default10m), andPGHOST/PGPORT/PGDATABASE/DB_ADMIN, which skip the connection prompts. - Try it safely first:
./rotate-prod-db-password.sh --dry-run
Want me to save this as rotate-prod-db-password.sh?
Subscription · always the latest version
- Secure checkout via Stripe
- Cancel anytime
- Delivered live via MCP
About this skill
The release checklist lives on a wiki page nobody quite trusts, because nobody has run it end to end this quarter. This skill turns a procedure you do by hand into one bash script that runs it with you: steps a machine can do are done, steps that genuinely need a person are prompted and validated, and an interrupted run resumes instead of starting over. Nothing irreversible happens without showing you the exact command first.
What it does
Reads a runbook, checklist or manual procedure and returns one runnable bash script that walks a person through it. Every step is triaged first - automate it, ask the person, or verify something they did elsewhere - and the triage table is printed beside the script so you can argue with the decisions before you trust them. The script is resumable, has a --dry-run flag, and shows the exact command before anything irreversible.
Try it first
Open the repo the procedure belongs to, point at the runbook - a wiki export, a README section, a checklist in a text file - and say "turn this into a script that walks me through it". You should get back what the wizard does in two lines, a triage table marking every step automate, ask or check with the reason, the complete script in one block, the steps deliberately left out, and what must be true before you run it.
What it needs
A runbook, checklist or written procedure to convert - this skill reads one, it does not invent one, so point it at the document (a wiki export, a README section, a checklist file) or paste it in. Plus an agent that can read and search the repo - Read, Grep, Glob and Bash. No API keys, no MCP servers, no network access. Bash only: it does not emit PowerShell, Python or Make.
A long procedure produces a long script - a thirteen-step runbook comes back as several hundred lines. The example on this page is a seven-step rotation and its script alone runs to 347 lines, shown in full. It writes code that runs commands on your machine, so read the script before you run it. It defaults every prompt to the safe answer, refuses to build a destructive step without a confirmation gate, and ships a --dry-run flag - but you are the one executing it, and that responsibility does not transfer. It will not run the script, write it to a file unasked, or perform any step of the procedure itself. Its output is bounded by the procedure you give it: a runbook that says "deploy as usual" produces a prompt asking what usual means, not an invented deployment. And it cannot see your organisation's access model, so anything involving a credential or somebody else's console becomes a prompt rather than an automated call - which is correct, and also means a procedure that is mostly permissions will come back mostly prompts.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before any payment.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Free forever
No account required to browse
Trust & safety
Security scan
Security scan passed 1 month ago