Which programming language should you learn for DevOps?
Why DevOps people need to code, an honest comparison of Bash, Python, Go, and JavaScript/TypeScript, the same task written in three languages, and a learning order without dogma.
Development$ python3 check_urls.py▍“Do I need to know how to code to work in DevOps?” Yes, but probably not the way you imagine. Nobody expects you to build a payment system from scratch. What’s expected is that you can automate tasks, read the code of the tools you use, and glue different systems together. In this article, we’ll look at what code is for in day-to-day DevOps work, compare the most popular languages, and write the same task in three of them.
Why DevOps needs to code
If you’re still figuring out what the field is about, start with what is DevOps. In short, the job is about getting software to production quickly and reliably. And almost everything along that path is code:
- Automation: scripts that run backups, free up disk space, rotate logs, or restart services. Everything someone used to do by hand, over and over. That manual, repetitive work has a name: toil, and reducing it is one of the most important goals in the field (see toil automation).
- Internal tooling: small CLIs (command-line programs) the team uses to create environments, check status, or trigger deploys.
- Infrastructure as Code (IaC): describing servers, networks, and databases in versioned files. Tools like Pulumi and AWS CDK use real programming languages for this.
- Glue between systems: taking the response from a REST API, transforming the data, and sending it somewhere else, like a chat or a ticketing system.
An analogy: DevOps tools (Docker, Kubernetes, Terraform) are LEGO bricks. Coding is what lets you snap those bricks together the way your team needs, instead of being limited to what comes in the box.
The main languages, side by side
| Language | Strengths | Typical DevOps use | Learning curve | Distribution |
|---|---|---|---|---|
| Bash | Preinstalled on Linux and macOS; great for chaining commands | Short scripts, CI steps, container entrypoints | Low to start, full of pitfalls later | Runs wherever there’s a compatible shell |
| Python | Readable syntax, huge ecosystem (requests, boto3) | Automation, cloud scripts, AWS Lambda functions, Pulumi/CDK, Ansible | Low | Needs the interpreter and dependencies installed |
| Go | Single binary, fast, simple concurrency | CLIs, Kubernetes operators, Prometheus exporters | Medium | A single binary that can be fully static |
| JavaScript/TypeScript | npm ecosystem, typing with TypeScript | AWS CDK, Pulumi, Lambda functions, JavaScript GitHub Actions | Medium | Needs Node.js (or a bundle) |
| PowerShell | Works with objects instead of text | Windows and Azure automation | Low to medium | Ships with Windows; available for Linux and macOS |
| Rust | Performance and memory safety | High-performance tools (the Vector telemetry agent, for example) | High | Single binary |
A few details that help make sense of the table:
- Python is the language Ansible is written in, and it has official SDKs for virtually every cloud provider. If you need to talk to AWS,
boto3covers almost everything. - Go is the language of Docker, Kubernetes, Terraform, and Prometheus. That means reading the code of those tools, writing an operator, or contributing to them goes through Go. We have a whole article on Go for DevOps.
- TypeScript was the first language of AWS CDK and is widely used with Pulumi. If your team is already strong in front end or Node.js, it makes sense to describe infrastructure in the same language.
- Distribution matters more than it seems: a Python script that depends on five libraries needs them installed on whatever machine runs it. A Go binary you just copy and run.
The same task in Bash, Python, and Go
To compare them in practice, let’s solve a common problem: check whether a list of URLs responds with HTTP 200 (the code that means “it worked”). The program should print the result for each URL and exit with an error if any of them fails, so it can be used in a CI pipeline. We’ll use httpbin.org, a public testing service that returns whatever status you ask for.
Bash
#!/usr/bin/env bash
# check-urls.sh — checks whether each URL responds with HTTP 200
set -uo pipefail
urls=(
"https://httpbin.org/get"
"https://httpbin.org/status/200"
"https://httpbin.org/status/503"
)
failures=0
for url in "${urls[@]}"; do
# -s: silent | -o /dev/null: discard the body | -w: print only the status
code="$(curl -s -o /dev/null -w '%{http_code}' --max-time 5 "$url")"
if [ "$code" = "200" ]; then
echo "OK $code $url"
else
echo "FAIL $code $url"
failures=$((failures + 1))
fi
done
[ "$failures" -eq 0 ] # exit code 0 only if all of them pass
Short and to the point, because curl does the heavy lifting. Notice we don’t use set -e: here we want to keep testing the next URLs even when one fails. If the list turns into JSON coming from another API, though, Bash starts to struggle. The fundamentals are in what is a shell and shell scripting.
Python
#!/usr/bin/env python3
"""check_urls.py — checks whether each URL responds with HTTP 200."""
import sys
import urllib.error
import urllib.request
URLS = [
"https://httpbin.org/get",
"https://httpbin.org/status/200",
"https://httpbin.org/status/503",
]
def status_of(url: str) -> int:
try:
with urllib.request.urlopen(url, timeout=5) as response:
return response.status
except urllib.error.HTTPError as error: # 4xx and 5xx land here
return error.code
except OSError: # DNS, connection refused, timeout...
return 0
failures = 0
for url in URLS:
code = status_of(url)
if code == 200:
print(f"OK {code} {url}")
else:
print(f"FAIL {code} {url}")
failures += 1
sys.exit(1 if failures else 0)
We only use the standard library, so all you need is Python 3: python3 check_urls.py. Error handling is explicit, and the code grows well when new rules show up, like reading URLs from a file or sending an alert.
Go
// main.go — checks whether each URL responds with HTTP 200
package main
import (
"fmt"
"net/http"
"os"
"time"
)
func main() {
urls := []string{
"https://httpbin.org/get",
"https://httpbin.org/status/200",
"https://httpbin.org/status/503",
}
client := &http.Client{Timeout: 5 * time.Second}
failures := 0
for _, url := range urls {
resp, err := client.Get(url)
if err != nil {
fmt.Printf("FAIL 000 %s (%v)\n", url, err)
failures++
continue
}
resp.Body.Close()
if resp.StatusCode == http.StatusOK {
fmt.Printf("OK %d %s\n", resp.StatusCode, url)
} else {
fmt.Printf("FAIL %d %s\n", resp.StatusCode, url)
failures++
}
}
if failures > 0 {
os.Exit(1)
}
}
It’s more verbose, but the result is an executable that runs on any Linux server without installing anything:
go mod init check-urls
go run . # run it directly, for testing
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o check-urls # static binary for Linux
All three programs print the same thing: two OK lines and one FAIL 503, exiting with code 1. The difference lies in what happens afterward: maintaining, growing, and distributing.
A learning order without dogma
There’s no “right” language, only the one that solves the problem in front of you. Even so, one sequence works well for most people:
- Bash basics: variables,
if,for, pipes, exit codes. You’ll read and write shell in every CI pipeline and every Dockerfile, so there’s no escaping it. - Python: once a script grows past a few dozen lines, or needs JSON, API calls, or tests. It’s the language with the best balance between ease and reach.
- Go: when you want to build CLIs for the team, write Kubernetes operators and controllers, or understand cloud native tools from the inside.
If your team uses Pulumi or CDK in TypeScript, swap step 2 or 3 for TypeScript without guilt. If you live in a Windows environment, PowerShell comes in early. The point is to learn one scripting language well before collecting half-learned languages.
Tips to learn faster
- Automate your own toil. That annoying task you do every week is the best possible exercise: the problem is real, you know the rules, and the payoff shows up right away.
- Read the code of the tools you use. Open the repository of a CLI you run every day and look at how it handles arguments or errors. You’ll learn patterns from people who already did this in production.
- Version everything with Git, including small scripts. History and code review apply to automation too.
- Write simple tests for scripts that touch production. In Python,
pytestmakes it easy; in Go,go testcomes built in. - Use linters: ShellCheck for Bash,
rufffor Python,go vetfor Go. They catch mistakes before they become incidents.
Checklist
- I wrote at least one Bash script with
if,for, and a correct exit code - I ran the Python example and understood how HTTP errors are handled
- I compiled the Go example and copied the binary to another machine or container
- I picked a repetitive task from my day-to-day work to automate
- I opened the source code of a tool I use and read how it handles errors
- I set up a linter for the language I use most
The best language for DevOps is the one that takes repetitive work off your plate this week.