Part 1 ยท Exercises

Part 1 Exercises

Prove to yourself that you've got it.

How to use these exercises

  • Do these in your own terminal โ€” a Linux machine, a Mac, WSL on Windows, or any cloud server.
  • Some are tasks to run. Some are questions to answer in writing. Some are scripts to write from scratch.
  • The goal is not to find the answer online and paste it โ€” the goal is to do it, get stuck, figure it out, and remember it forever.
  • There is no automated grader here. Your terminal is your grader.

Chapter 1 โ€” What is DevOps?

Exercise 1.1 โ€” In Your Own Words

Without looking at the chapter, explain DevOps in two or three sentences as if you were telling a non-technical friend what you are studying. Then compare your explanation to the key-term definition in the chapter. What did you miss? What did you capture?

Exercise 1.2 โ€” The Wall

Think of a real-world situation โ€” from any domain, not necessarily software โ€” where two groups had opposite incentives that caused conflict. How was that conflict resolved (or how could it be)? Write a short paragraph comparing it to the Dev vs. Ops conflict described in Chapter 1.

Exercise 1.3 โ€” The Infinity Loop

Draw the DevOps infinity loop from memory on a piece of paper. Label each phase. For each phase, write one sentence describing what happens there. Do not look at the chapter until you are done. Check your answers afterward.

Exercise 1.4 โ€” Research

Look up the DORA (DevOps Research and Assessment) State of DevOps report for the most recent year available. Find the four key metrics DORA uses to measure DevOps performance (they are called the "Four Keys"). What are they? What does a "high-performing" team score on each metric?

Chapter 2 โ€” Linux

Exercise 2.1 โ€” Navigation

Open a terminal and complete the following tasks in order:

  1. Print your current working directory.
  2. Navigate to your home directory using the ~ shortcut.
  3. List all files and folders, including hidden ones, with full details (ls -la).
  4. Find the hidden .bashrc or .zshrc file. What is its size and last modified date?
  5. Navigate to /var/log and list the files there. What are the largest log files?
Exercise 2.2 โ€” Build a Project Structure

Using only the command line (no file manager, no IDE), create the following directory structure in your home directory:

~/my-devops-project/
โ”œโ”€โ”€ src/
โ”‚   โ””โ”€โ”€ app.js
โ”œโ”€โ”€ config/
โ”‚   โ”œโ”€โ”€ production.env
โ”‚   โ””โ”€โ”€ development.env
โ”œโ”€โ”€ scripts/
โ”‚   โ””โ”€โ”€ deploy.sh
โ””โ”€โ”€ README.md

Create the directories with mkdir -p and the files with touch. When done, verify your structure with find ~/my-devops-project.

Exercise 2.3 โ€” Decode the Permissions String

For each of the following permission strings, answer: who can do what? Identify the file type, owner permissions, group permissions, and other permissions.

  • -rw-r--r--
  • drwxr-xr-x
  • -rwx------
  • -rw-------

Then run ls -la /etc/passwd on your system. What are the permissions on that file? Why do you think they are set that way?

Exercise 2.4 โ€” Working with Logs

Create a fake log file with this command:

for i in {1..100}; do
  if [ $((i % 7)) -eq 0 ]; then
    echo "$(date) [ERROR] Database connection failed on attempt $i"
  else
    echo "$(date) [INFO] Request $i processed successfully"
  fi
done > /tmp/app.log

Then answer these questions using only command-line tools:

  1. How many total lines does the file have?
  2. How many ERROR lines are there?
  3. Show only the ERROR lines.
  4. Show the last 5 lines of the file.

Hint: wc -l, grep, tail.

Exercise 2.5 โ€” SSH Key Generation

Generate a new SSH key pair on your machine:

ssh-keygen -t ed25519 -C "devops-practice-key"

Save it as ~/.ssh/id_devops_practice (a different filename than your default key).

Then:

  1. View your public key: cat ~/.ssh/id_devops_practice.pub
  2. Check the permissions: ls -la ~/.ssh/
  3. Why must the private key be mode 600 (not 644)? What would SSH do if the permissions were too open?

Chapter 3 โ€” Networking

Exercise 3.1 โ€” DNS Investigation

Use dig to investigate a domain of your choice. Run these commands and answer the questions:

dig google.com
dig MX gmail.com
dig +trace github.com
  1. What IP address did dig google.com return? Is it always the same?
  2. What mail servers handle email for gmail.com? What does the number in the MX record mean?
  3. Describe in your own words what happened at each step of the +trace output for github.com.
Exercise 3.2 โ€” HTTP in Action

Use curl to make real HTTP requests. Run each command and read the output carefully:

# Basic GET request
curl https://httpbin.org/get

# POST with JSON body
curl -X POST https://httpbin.org/post \
  -H "Content-Type: application/json" \
  -d '{"name": "DevOps Student", "chapter": 3}'

# See the full HTTP response headers
curl -I https://github.com

# Follow redirects and show what happens
curl -L -v http://github.com 2>&1 | grep -E "^[*<>]"

After running these, answer: what status code does http://github.com (HTTP, not HTTPS) return, and where does it redirect to?

Exercise 3.3 โ€” Ports and Processes

Find out what is listening on your machine right now:

ss -tlnp

List at least three services that are listening and identify what each one is. If you have a web server installed (nginx, apache), what port is it on? What about your database?

Then explain: if you wanted to allow a colleague to connect to your PostgreSQL database on port 5432 but block everyone else, how would you configure UFW to do that? Write out the commands, even if you don't run them.

Exercise 3.4 โ€” TCP vs. UDP Reflection

Answer in your own words:

  1. You are building a live video streaming service where a dropped frame is no big deal but latency matters. Should your video data travel over TCP or UDP? Why?
  2. You are building a banking application where every transaction must be recorded and confirmed. Should it use TCP or UDP? Why?
  3. What protocol does DNS primarily use? Why does that make sense for short lookups?

Chapter 4 โ€” Git, Bash & Python

Exercise 4.1 โ€” Git From Scratch

Complete this full Git workflow in your terminal, step by step:

  1. Create a new directory called git-practice and initialize a Git repo.
  2. Create a file called hello.txt with the text "Hello, DevOps!"
  3. Stage and commit the file with a meaningful message.
  4. Create a new branch called feature/goodbye.
  5. On that branch, create a file goodbye.txt with the text "See you in production."
  6. Commit the new file.
  7. Switch back to main and merge your feature branch.
  8. Run git log --oneline --graph --all to see the history.

Copy the output of git log --oneline --graph --all into your notes.

Exercise 4.2 โ€” Write a Bash Script

Write a Bash script called greet.sh that:

  1. Accepts a name as the first argument ($1).
  2. If no argument is provided, prints "Usage: greet.sh <name>" and exits with code 1.
  3. Otherwise, prints "Hello, [name]! Welcome to DevOps." where [name] is replaced with the argument.

Make the script executable with chmod +x greet.sh and test it with: ./greet.sh Ushahemba and ./greet.sh (no argument).

Exercise 4.3 โ€” Automate with Bash

Write a Bash script called backup.sh that:

  1. Takes a source directory as $1 and a backup destination as $2.
  2. Creates the destination directory if it does not exist.
  3. Copies all files from source to destination.
  4. Prints a log line like: [2026-05-06 09:14:22] Backed up /source to /dest
  5. Uses set -e so the script exits immediately if any command fails.

Test it by backing up ~/my-devops-project to /tmp/backup-test.

Exercise 4.4 โ€” Python Line Counter

Write a Python script called count_lines.py that:

  1. Accepts a filename as a command-line argument (sys.argv[1]).
  2. Opens the file and counts the total number of lines.
  3. Also counts how many non-empty lines there are.
  4. Prints both counts in a readable format.
  5. If the file does not exist, prints a helpful error message and exits with code 1.

Test it on the /tmp/app.log file you created in Exercise 2.4.

Exercise 4.5 โ€” Putting It All Together

This is a larger challenge that ties together multiple concepts from Part 1. Build a mini "deployment simulation":

  1. Create a Git repository called my-web-app. Add a file called index.html with any HTML content you like. Commit it with a message "Initial commit".
  2. Create a branch called feature/about-page. Add a file about.html with a short "About Me" page. Commit it. Merge it back into main.
  3. Write a Bash script called deploy-sim.sh that simulates a deployment:
    • Prints "Starting deployment..."
    • Runs git log --oneline -5 to show recent commits
    • Counts the HTML files and prints "Deploying X HTML files"
    • Prints "Deployment complete!"
  4. Write a Python script called check-deploy.py that reads the directory, lists all .html files, and prints their names and sizes.

When you can run ./deploy-sim.sh and python3 check-deploy.py from the same directory and see sensible output, you have completed Part 1.

๐Ÿ’ก After You Finish

If you completed all five exercises in the Chapter 4 section, you have practiced the core skills that will appear in every subsequent chapter: navigating Linux, reading and writing files, using Git for version control, writing Bash automation, and using Python for scripting. These are not just exercises โ€” they are the daily reality of DevOps engineering. Repeat them until the commands feel natural.

Part 1 Complete

  • You understand what DevOps is, where it came from, and why it matters โ€” both culturally and economically.
  • You can navigate a Linux file system, manage files and permissions, and control services with systemctl.
  • You know how data travels across the internet: IP addresses, DNS resolution, TCP/UDP, HTTP requests and responses, and port numbers.
  • You can use Git to version-control your work, create branches, merge changes, and view history.
  • You can write Bash scripts that automate deployment tasks with proper error handling.
  • You can write Python scripts to check application health, parse files, and interact with APIs.
  • You are ready for Part 2: CI/CD and Containers.