Why Automation Scripting
Most of a DevOps engineer's code is not the product. It is the glue around it: the script that rotates a log, the job that tags a release, the check that a config file is valid before it ships, the tool that asks an API which servers are unhealthy. That glue runs unattended, often as root, often at night, and usually nobody reads it until it breaks. This course is about writing it so that it does not.
Three languages, one job
The roadmap asks for Bash plus Python or Go. You will meet all three, because real teams use all three:
| Language | Where it shines | Where it hurts |
|---|---|---|
| Bash | gluing commands together, CI steps, container entrypoints, anything that is mostly "run this, then that" | data structures, error handling, anything over a few hundred lines |
| Python | parsing JSON/YAML, calling REST APIs, reports, scripts that grow into small programs | packaging and shipping it to machines that lack the right Python version or libraries |
| Go | tools you hand to other people: one static binary, fast, concurrent, no runtime to install | more ceremony for a five-line job |
The last section, Bash vs Python vs Go, turns this table into a decision you can defend in a code review.
What you should already know
This course starts where two others stop:
- Linux & Bash teaches the shell itself: variables, quoting, loops,
functions, script arguments and a first look at
exit codes,
set -euo pipefailandtrap. Here we go further: where strict mode silently fails, how to clean up on every exit path, locking, idempotency and ShellCheck. - Python teaches the language. Here you use it as an operations tool:
argparse,subprocess,pathlib, REST clients, logging. - Go teaches the language; the Go section here builds small command-line tools with the standard library.
If you have not met jq before, the JSON course's jq lesson is a gentle first step.
How the examples run
Three kinds of example appear throughout:
- Real shell sessions (
bashblocks with an output). They ran in a Linux container with GNU Bash 5.2, jq 1.7, yq 4.54.1, ShellCheck 0.9.0, yamllint 1.33.0 and Python 3.12 with PyYAML, as the unprivileged userlearner, with no network. Each session starts in an empty home directory, so it creates every file it needs. - Runnable Python and Go programs. Python runs in your browser (Pyodide, CPython 3.13 compiled to WebAssembly); Go runs on Compiler Explorer. Neither has network access, and Pyodide cannot start processes, so examples that talk to an API talk to a small fake API inside the same program. The client code is written so that swapping the fake for a real HTTP transport is a one-line change, and the real version is shown next to it.
- Sample code (blocks without a Run button) for anything that needs a real network, a real server or a build
you cannot do in a sandbox, such as
go buildfor three platforms.
A taste
Here is the kind of job this course is about: a service list in JSON, and a question ("which services are down, and who owns them?"). In Bash with jq it is a few lines:
cat > services.json <<'JSON'
[
{"name": "api", "owner": "team-core", "status": "up"},
{"name": "worker", "owner": "team-core", "status": "down"},
{"name": "search", "owner": "team-find", "status": "down"},
{"name": "web", "owner": "team-front", "status": "up"}
]
JSON
jq -r '.[] | select(.status == "down") | "\(.name)\t\(.owner)"' services.json
down=$(jq '[.[] | select(.status == "down")] | length' services.json)
echo "$down service(s) down"
[ "$down" -eq 0 ] || exit 1worker team-core
search team-find
2 service(s) down
The same question in Python, which is where you go once the logic needs more than one filter:
import json
services = json.loads("""[
{"name": "api", "owner": "team-core", "status": "up"},
{"name": "worker", "owner": "team-core", "status": "down"},
{"name": "search", "owner": "team-find", "status": "down"},
{"name": "web", "owner": "team-front", "status": "up"}
]""")
down = [s for s in services if s["status"] == "down"]
by_owner = {}
for s in down:
by_owner.setdefault(s["owner"], []).append(s["name"])
for owner, names in sorted(by_owner.items()):
print(f"{owner}: {', '.join(names)}")
print(f"{len(down)} service(s) down; exit status would be {1 if down else 0}")team-core: worker
team-find: search
2 service(s) down; exit status would be 1
Both end the same way: with an exit status that tells the caller (a CI job, cron, a monitoring agent) whether things are fine. Almost every script in this course ends like that.
The course map
| Section | You will be able to |
|---|---|
| Robust Bash | write scripts that stop on errors, clean up after themselves, can be run twice safely and pass ShellCheck |
| JSON & YAML | query and reshape JSON with jq, avoid YAML's traps, edit YAML with yq, lint and validate config |
| Python for Automation | build CLIs, run commands safely, call REST APIs with retries and pagination, log properly |
| Go for Tooling | build a small CLI with flags, JSON and HTTP that ships as one binary |
| Choosing | pick the right language for a task, and know when to rewrite |
| Practice | exercises and a health-report tool written in Python and in Go |
Test yourself
Why do the Python API examples in this course talk to a fake API inside the program?
- Real APIs are too slow
- The browser sandbox has no network access and Pyodide cannot open sockets or start processes
- The
jsonmodule only works offline - Fake APIs are always better than real ones
What does the Bash taste example do when at least one service is down?
- Prints the list and exits with status 0
- Prints the list and exits with a non-zero status, so a CI job or monitor sees a failure
- Restarts the services
- Nothing, jq stops it
Which language is usually the best fit for a tool you will hand to other teams to install on many machines?
- Bash, because every machine has it
- Python, because it has the most libraries
- Go, because it builds one static binary with no runtime to install
- Any of them, packaging never matters