Skip to main content
Career Paths
Concepts
Scripting Devops
The Simplified Tech

Role-based learning paths to help you master cloud engineering with clarity and confidence.

Product

  • Career Paths
  • Interview Prep
  • Scenarios
  • AI Features
  • Cloud Comparison
  • Resume Builder
  • Pricing

Community

  • Join Discord

Account

  • Dashboard
  • Credits
  • Updates
  • Sign in
  • Sign up
  • Contact Support

Stay updated

Get the latest learning tips and updates. No spam, ever.

Terms of ServicePrivacy Policy

© 2026 TheSimplifiedTech. All rights reserved.

BackBack
Interactive Explainer

Scripting for DevOps

Python and Bash scripts that eliminate toil, glue tools together, and form the building blocks of CI/CD pipelines. The difference between a hero who does things manually and a system that runs itself.

🎯Key Takeaways
Scripts convert toil (manual, repetitive work) into automation — they run consistently, tirelessly, and at 3am without human error.
Bash is for gluing CLI commands and system administration. Python is for complex logic, API calls, and cloud SDK automation.
Production scripts must have: proper exit codes, idempotency, parameterization, logging, and secret-safe handling.
Always use `set -euo pipefail` in Bash scripts — silent failures are more dangerous than loud ones.
The automation ladder goes: manual → runbook → script → scheduled → CI/CD pipeline → self-healing. Every level multiplies reliability.
Scripts are the building blocks of CI/CD pipelines. A pipeline is just well-organized, version-controlled scripts running automatically.

Scripting for DevOps

Python and Bash scripts that eliminate toil, glue tools together, and form the building blocks of CI/CD pipelines. The difference between a hero who does things manually and a system that runs itself.

~8 min read
Be the first to complete!
What you'll learn
  • Scripts convert toil (manual, repetitive work) into automation — they run consistently, tirelessly, and at 3am without human error.
  • Bash is for gluing CLI commands and system administration. Python is for complex logic, API calls, and cloud SDK automation.
  • Production scripts must have: proper exit codes, idempotency, parameterization, logging, and secret-safe handling.
  • Always use `set -euo pipefail` in Bash scripts — silent failures are more dangerous than loud ones.
  • The automation ladder goes: manual → runbook → script → scheduled → CI/CD pipeline → self-healing. Every level multiplies reliability.
  • Scripts are the building blocks of CI/CD pipelines. A pipeline is just well-organized, version-controlled scripts running automatically.

Lesson outline

Why scripting is the foundation of DevOps automation

In The DevOps Handbook, every place in the value stream where a human copies commands from a wiki, re-types the same sequence of CLI commands, or manually clicks through a web console is a candidate for automation. Scripts are the first step: they capture what a human does and make it repeatable, parameterized, and auditable.

Toil vs engineering work

Google SRE defines toil as manual, repetitive, automatable work that scales linearly with service growth. Restarting a service manually every time it crashes is toil. Writing a script that detects the crash and restarts it automatically is engineering work. The script runs forever; the manual restart is forgotten the moment you close the terminal.

DevOps engineers are glue — they connect CLIs, APIs, config files, cloud SDKs, and monitoring systems. Scripts are the connective tissue. A deploy script that pulls the latest image, runs health checks, flips the load balancer, and sends a Slack notification is more reliable than any engineer doing it manually at 2am.

Bash vs Python: choosing the right tool

Both Bash and Python are essential in a DevOps engineer's toolkit, but they excel at different tasks:

When to use Bash

  • Gluing CLI commands — Bash is the shell — calling aws, kubectl, docker, git, curl is idiomatic. No imports needed.
  • CI/CD pipeline steps — Most CI systems run Bash natively. Short pipeline steps (build, test, push) fit well in Bash.
  • System administration — File manipulation, service management (systemctl), log rotation — Bash is the native language of Linux.
  • Simple conditionals — Check if a file exists, if a service is running, if an environment variable is set.

When to use Python

  • API calls and JSON parsing — requests library + json parsing makes REST API integration trivial. Bash + curl + jq gets unwieldy fast.
  • Complex logic — Loops with business logic, error handling with retries, data transformation — Python is far more readable.
  • Cloud SDK automation — boto3 (AWS), google-cloud Python SDK, and Azure SDK are Python-first. Much richer than CLI wrappers.
  • Cross-platform scripts — Python runs identically on Linux, macOS, and Windows. Bash scripts need shebang hacks to run on Windows.

Good scripting practices for production

Scripts in production are code. They should be treated with the same engineering discipline as application code: version controlled, tested, reviewed, and documented.

Production scripting standards

  • Exit codes — Always exit 0 on success, non-zero on failure. CI/CD pipelines use exit codes to stop on errors. A script that swallows errors is worse than no script.
  • Idempotency — Running a script twice should produce the same result as running it once. Check before creating: "if this S3 bucket already exists, skip." This makes scripts safe to retry.
  • Parameterization — No hardcoded environment names, account IDs, or URLs. Accept them as arguments or environment variables. The same script should work in staging and production.
  • Logging — Print what you are about to do, what you did, and any errors. Include timestamps. Logs are your audit trail when something goes wrong at 3am.
  • Error handling — In Bash: set -euo pipefail at the top — stops on any error, treats unset variables as errors, and propagates pipe failures. In Python: use try/except with specific exception types.
  • Secrets handling — Never hardcode secrets. Read from environment variables or a secrets manager. Never print secrets to logs (even accidentally via print(config)).

From ad-hoc to pipeline: the automation ladder

Scripts do not exist in isolation — they are the building blocks that get assembled into CI/CD pipelines. The automation ladder describes how a manual task evolves:

Automation maturity ladder

  • Level 0: Pure manual — Engineer SSHes to server, runs commands from memory or a wiki page. Every run is slightly different.
  • Level 1: Runbook — Steps documented in a wiki or Confluence. Still manual, but at least consistent. Still toil.
  • Level 2: Script — Runbook converted to a Bash or Python script. Repeatable, parameterized, in version control. Engineer still runs it manually.
  • Level 3: Scheduled automation — Script runs on a cron schedule or triggered by a webhook. No human required for routine execution.
  • Level 4: CI/CD pipeline step — Script is a step in a pipeline that runs on every commit or merge. Peer-reviewed, tested, automatically rolled back on failure.
  • Level 5: Self-healing system — Automation detects and responds to events without any human trigger. Alert fires → Lambda runs remediation script → incident auto-resolved.

Most teams operate between Level 1 and Level 3. Elite teams push toward Level 4 and Level 5. Every time you write a runbook, ask: can this be a script? Every time you run a script manually, ask: can this run on a schedule or trigger?

Real DevOps scripting patterns

High-value scripting targets in DevOps

  • Blue/green deploy orchestration — Script that: deploys to inactive environment, runs smoke tests, updates load balancer target group, waits for health, marks old environment standby.
  • Database migration safety — Script that: takes RDS snapshot, applies migration, verifies row counts, rolls back if counts diverge by more than 1%.
  • Cloud resource cleanup — Script that finds untagged EC2 instances, S3 buckets older than 30 days with no activity, or EBS volumes not attached to running instances — and deletes or alerts.
  • Certificate rotation — Script that checks certificate expiry dates across all domains, rotates those expiring within 30 days via ACM or Let's Encrypt, and updates load balancers.
  • Incident triage automation — Script triggered by PagerDuty webhook that collects recent logs, deployment history, and error rates — and posts a triage summary to the incident Slack channel before on-call engineer even opens their laptop.
How this might come up in interviews

Scripting questions in DevOps interviews often include a live coding challenge: write a health check script, or fix a broken Bash script. Know `set -euo pipefail` cold — it comes up constantly. Be ready to explain idempotency with a concrete example (check before create). Understand the difference between exit codes 0 and non-zero and how pipelines use them. Have a story about automating a painful manual process and the measurable impact (time saved, error reduction). Bonus: understand Python subprocess vs shell — when to use `subprocess.run` vs os.system vs shell=True (never use shell=True with user input).

Quick check · Scripting for DevOps

1 / 4

A Bash script deploys a new application version. At step 5 of 12 steps, a command fails. The script continues and finishes without error. What is wrong and how do you fix it?

Key takeaways

  • Scripts convert toil (manual, repetitive work) into automation — they run consistently, tirelessly, and at 3am without human error.
  • Bash is for gluing CLI commands and system administration. Python is for complex logic, API calls, and cloud SDK automation.
  • Production scripts must have: proper exit codes, idempotency, parameterization, logging, and secret-safe handling.
  • Always use `set -euo pipefail` in Bash scripts — silent failures are more dangerous than loud ones.
  • The automation ladder goes: manual → runbook → script → scheduled → CI/CD pipeline → self-healing. Every level multiplies reliability.
  • Scripts are the building blocks of CI/CD pipelines. A pipeline is just well-organized, version-controlled scripts running automatically.
🧠Mental Model

💡 Analogy

Scripting in DevOps is like building a factory assembly line vs handcrafting each product. A craftsman (hero engineer) can make one item at a time, perfectly. But a factory (script + CI/CD pipeline) makes thousands of identical items with consistent quality, no fatigue, and no sick days. The first factory is hard to build. But once running, it runs forever. Every time you replace a manual process with a script, you are building a factory. Every time you wire a script into CI/CD, you are making the factory run itself.

⚡ Core Idea

Scripting transforms toil (manual, repetitive, error-prone work) into automation (consistent, auditable, tireless execution). The key properties are: idempotency (safe to run multiple times), parameterization (works in any environment), proper exit codes (integrates with pipelines), and version control (auditable, reviewable, rollback-able).

🎯 Why It Matters

The engineering value of a script compounds over time. A 2-hour task done manually every week costs 100 hours per year. A 4-hour script that automates it saves 96 hours in year one and 104 hours every subsequent year. More importantly, scripts eliminate the risk of human error on the 47th repetition, at 3am, during an incident. The best DevOps engineers are prolific automators — they are always asking 'how do I make sure I never have to do this manually again?'

Ready to see how this works in the cloud?

Switch to Career Paths for structured paths (e.g. Developer, DevOps) and provider-specific lessons.

View role-based paths

Sign in to track your progress and mark lessons complete.

Discussion

Questions? Discuss in the community or start a thread below.

Join Discord

In-app Q&A

Sign in to start or join a thread.