Practical Automation Patterns
Dry Run Plan
Preview Before Apply
Automation scripts are safer when they can show the planned action before applying it. A dry-run flag keeps that choice visible.
Program
Play the script to choose preview or apply mode and see the planned deployment action.
dry_run_plan.sh
Replay: real traced execution (multi-file project)
#!/usr/bin/env bash
dry_run=1
target="staging"
if [ "$dry_run" -eq 1 ]; then
action="preview"
else
action="apply"
fi
plan="$action:$target"
echo "$plan"
#!/usr/bin/env bash
dry_run=0
target="staging"
if [ "$dry_run" -eq 1 ]; then
action="preview"
else
action="apply"
fi
plan="$action:$target"
echo "$plan"
dry_run ← 1
3dry_run=14target="staging"values this step1dry_runtarget ← staging
3dry_run=14target="staging"5if [ "$dry_run" -eq 1 ]; thenvalues this stepstagingtargetif [ "$dry_run" -eq 1 ]; then
4target="staging"5if [ "$dry_run" -eq 1 ]; then6 action="preview"values this step1dry_runaction ← preview
5if [ "$dry_run" -eq 1 ]; then6 action="preview"7elsevalues this steppreviewactionplan ← preview:staging
9fi10plan="$action:$target"11echo "$plan"values this steppreview:stagingplanpreviewactionstagingtargetecho "$plan"
10plan="$action:$target"11echo "$plan"outputpreview:stagingvalues this steppreview:stagingplan
dry_run ← 0
3dry_run=04target="staging"values this step0dry_runtarget ← staging
3dry_run=04target="staging"5if [ "$dry_run" -eq 1 ]; thenvalues this stepstagingtargetif [ "$dry_run" -eq 1 ]; then
4target="staging"5if [ "$dry_run" -eq 1 ]; then6 action="preview"values this step0dry_runaction ← apply
7else8 action="apply"9fivalues this stepapplyactionplan ← apply:staging
9fi10plan="$action:$target"11echo "$plan"values this stepapply:stagingplanapplyactionstagingtargetecho "$plan"
10plan="$action:$target"11echo "$plan"outputapply:stagingvalues this stepapply:stagingplan
dry run
A dry run prints or records the action without applying side effects.
target
Keeping the target in a variable makes the plan easy to review.
apply boundary
The branch that would apply changes is explicit and testable.