ops-scripting-standards
/ops-scripting-standards
Use when you write a Bash, PowerShell, or Python automation script. Fail on errors and unset variables, support a dry run, and make a second run change nothing.
- Author
- JayCommit ↗
- Repository
- jstack ↗
- Licence
- MIT
- Last repository change
- 04.11.2026
Assessment and security
- Files in this package
- 2
- Scripts
- 0
- HTML comments
- 0
- URLs in SKILL.md
- 0
No signals detected. Repository changed on 04.11.2026, without references to retired models or APIs.
MIT, open: use and modify while retaining author attribution.
What it does and when to use it
Use when you write a Bash, PowerShell, or Python automation script. Fail on errors and unset variables, support a dry run, and make a second run change nothing.
Original author description
Use when you write a Bash, PowerShell, or Python automation script. Fail on errors and unset variables, support a dry run, and make a second run change nothing.
How it works
- Use when
- Steps
- Safety checks
- Rollback
- Done when
SKILL.md preview
---
name: ops-scripting-standards
description: "Use when you write a Bash, PowerShell, or Python automation script. Fail on errors and unset variables, support a dry run, and make a second run change nothing."
license: MIT
---
# Scripting standards
A script fails loudly, prints what it would change, and a second run with the same inputs changes nothing.
## Use when
- You add or change a Bash, PowerShell, or Python script that touches Azure, AWS, Terraform, or a pipeline.
- A script succeeds the first time and fails the second because the resource exists.
- A destructive script runs as soon as you invoke it, with no dry run.
- A secret is passed as an argument or written to the log.
## Steps
1. Make a second run safe. Read the current object, then create or update it. A create that errors when the resource already exists is unfinished. Names do not include the clock. Follow `principle-idempotent-automation`.
2. Bash starts with `set -euo pipefail`. Quote expansions. Do not parse `ls`. Do not pipe a remote script into a shell. Run shellcheck, and add the file to the shellcheck invocation that CI already runs. In this repo that step lists `scripts/sync` and `tests/sync/*.sh`. A new Bash file is not covered until you add it there.
```bash
#!/usr/bin/env bash
set -euo pipefail
```
3. PowerShell fails closed and supports `-WhatIf`. `Invoke-ScriptAnalyzer` already runs on `scripts/` in CI. Keep that clean. Use approved verbs. A script that changes Azure uses the Az module so `-WhatIf` is real. A one-off `az` command in a skill example is not this script.
```powershell
#Requires -Modules Az.Accounts
[CmdletBinding(SupportsShouldProcess = $true)]
param(
[Parameter(Mandatory = $true)]
[string] $ResourceGroupName
)
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
if ($PSCmdlet.ShouldProcess($ResourceGroupName, 'Create or update the resource')) {
Write-Output "Updating $ResourceGroupName"
}
```
4. Python takes `--apply` and otherwise prints the actions and changes nothing. Exit non-zero on failure. Do not use a bare `except`. Do not put a secret in an argument. It shows up in the process list. Pin the dependencies you import.
```python
import argparse
import sys
def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument("--apply", action="store_true")
args = parser.parse_args()
if not args.apply:
print("dry run: no changes")
return 0
# Read the current object, then create or update it.
return 0
if __name__ == "__main__":
sys.exit(main())
```
5. A script that deletes or replaces defaults to the dry run. `--apply`, or omitting `-WhatIf` on the PowerShell script, is the apply. The dry run prints each object it would change and does not call the cloud. Follow `principle-change-safety` for the radius of that apply.
6. Keep secrets out of the file, the arguments, and the log. Read them from the home in `ops-secrets-handling`. The identity is federated. Follow `principle-no-static-credentials`. Do not catch an error and continue with `|| true` unless the change record says that command is optional.
7. If the script applies Terraform, it applies a saved plan. Follow `terraform-plan-review`. One script, one job. Say which subscription or account it can touch. Follow `ops-blast-radius`.
## Safety checks
- Bash uses `set -euo pipefail`, shellcheck is clean, and the CI shellcheck invocation includes the file.
- PowerShell uses strict mode, stops on errors, and implements `-WhatIf`. PSScriptAnalyzer is clean.
- Python defaults to a dry run, exits non-zero on failure, and has no bare `except`.
- A second run with the same inputs changes nothing.
- No secret is in the file, the arguments, or the output.
- A delete or a replace does not run unless `--apply` was passed, or `-WhatIf` was left off on purpose.
- Stop before an apply, a merge, or a grant. Follow `principle-stop-at-approval`.
## Rollback
A script that changes a resource has a rehearsed way back: a flag, a second script, or the rollback command for that change type. Follow `ops-rollback-plan` and `principle-rollback-first`. Run that path on a non-production resource before production uses the script. If the script fails halfway, a rerun reaches the same end state or stops with the error. It does not create a second copy.
## Done when
- The linter for that language is clean, and the new Bash file is in the shellcheck step when it lives in this repo.
- A dry run prints the change and touches nothing. An apply run, then a second run, leaves no further change.
- The rollback path has been run off production.
Files in this package (2)
- SKILL.md 5 KB
- tests/prompts.md 2 KB
Versions
The database has no other skills named ops-scripting-standards.
Database snapshot: 13.11.2026 · package version 378d5b83e400 (SHA-256 digest of the entire package)
Downloads in the last 30 days: 0 · ranking
Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.
Similar skills
- 100overview
Cross-language CLI and scripting guidance for IT automation, system administration, and DevOps workflows: language selection (Bash vs PowerShell vs Python vs Node.js), pipes, exit codes, environment variables, argument parsing, error handling, and cross-platform scripting best… - 90powershell
在 Windows PowerShell 7 中写可靠的命令和 .ps1 脚本,避开从 bash/Linux 迁移过来的陷阱:引号与参数传递、编码与行尾、JSON 深度、原生命令退出码、路径与字面量、别名差异。当需要在 Windows 上执行 shell 命令、编写或调试 PowerShell 脚本、或 bash 命令在 PowerShell 中行为不符预期时使用。 - 100linux-bash-scripting
Defensive Bash scripting for Linux: safe foundations, argument parsing, production patterns, ShellCheck compliance. Use when writing "bash script", "shell script", "linux automation", "system script", "cron job", "deployment script", "CLI tool in bash", or "automate with bash". - 100scripting-automation
Covers writing operational scripts that survive contact with production — idempotency, real error handling and exit codes, structured logging, a dry-run mode, and recognizing when a script has outgrown scripting. Use this whenever the user is writing a bash or Python script that… - 95bash
Use when writing shell scripts or working with Bash, Zsh, or POSIX-compatible shells on macOS and Linux. Covers scripting fundamentals, variables, control flow, functions, pipes, process management, and common patterns for automation and developer tooling. USE FOR: Bash, Zsh,… - 98powershell-core
Use when writing PowerShell scripts or automating tasks with PowerShell 7+ (the cross-platform edition). Covers cmdlet patterns, pipeline, objects vs text, modules, error handling, remoting, and differences from Windows PowerShell 5.1. USE FOR: PowerShell 7, PowerShell Core,…