Python for DevOps: First Steps
Build a Python server status card from the Linux terminal.
Introduction
30 Second Summary
Keeping track of a machine gets messy when its name, purpose, and storage numbers live in separate notes. Recalculating the same numbers by hand makes every update slower.
In this project, you will build a terminal-based server status card with Python. You will use Xed to change the card before running it in the standard Linux terminal.
What You'll Build
Your finished file prints a four-line status card whose disk result recalculates whenever you change its values.
By the end of this project, you'll have:
- A saved Python file you can run from the standard Linux terminal to print the same status card whenever you need it.
- A formatted server label that turns web-01 into WEB-01 while keeping production lowercase.
- A disk calculation that changes from 32 GB free to 28 GB free when used space rises from 68 to 72.
- Secret Mission: A combined report that adds main disk usage to backup disk usage. It also flags whether total usage exceeds 150 GB.
Are there any prerequisites?
Basic Linux terminal commands plus a little Bash are enough. No programming experience or software installation is required.
Before We Start
Before the hands-on work begins, this is your moment to lock in what you are building. You are turning a blank text file into a terminal-based Python server status card for DevOps-style practice.
Create and Run Your First Python File
A saved Python file keeps your instructions in one place. You can rerun the same check whenever you need it.
In this step, you’ll create the project folder with the standard Linux terminal. You’ll write your first instruction in Xed.
In this step, get ready to:
- Create the ~/python-devops/project1 project folder.
- Confirm that Python 3 runs from the standard Linux terminal.
- Save and run server_status.py with visible output.
Prepare the project folder
A Python file is a plain text file with a .py extension. The instructions inside the file are called code.
Output is what a program shows after it runs. Your first test produces output before you create the file.
- Press Ctrl+Alt+T to open the standard Linux terminal.
- Create the project folder by running these commands:
mkdir -p ~/python-devops/project1
cd ~/python-devops/project1
python3 -c 'print("Python 3 is ready")'
What do these commands do?
- The mkdir command creates the project folder. The -p option also creates the missing parent folder.
- The cd command moves the terminal into ~/python-devops/project1.
- The python3 command asks Python 3 to run a short instruction. The -c option supplies that instruction directly.
You’ll see Python 3 is ready in the terminal. That confirms your project folder is ready for a Python file.
- Open server_status.py in Xed by running this command:
xed server_status.py
What does this command do?
The xed command starts Xed with the named file. You’ll see a blank editing area for server_status.py.
Add your first Python instruction
The print() function is a named tool that displays a value. It gives you visible proof that Python ran your instruction.
- Enter this line in the blank server_status.py file:
print("Python is running")
What does this code do?
- The print() function sends a value to the terminal as output.
- The text inside the quotes is a string. Python displays the string without its quotes.
- Save server_status.py by pressing Ctrl+S in Xed.
- Return to the standard Linux terminal.
Before you run the file, predict which message the terminal will display.
- Run your saved Python file with this command:
python3 server_status.py
What does this command do?
The python3 command runs the instructions saved in server_status.py. The terminal shows each value passed to print().
You’ll see Python is running in the terminal. Your first saved Python program now runs successfully.
Practice small changes and restore the file
Each practice edit changes the output you can observe. Saving before each run ensures that Python reads your newest instruction.
- Replace Python is running with Hello from Python in Xed.
- Save server_status.py.
- Return to the standard Linux terminal.
- Run the file with the same terminal command.
You’ll see Hello from Python in the terminal.
- Replace the existing line with two print() lines that show Starting check followed by Check complete.
- Save server_status.py.
- Return to the standard Linux terminal.
- Run the file with the same terminal command.
You’ll see Starting check on the first line. You’ll see Check complete on the second line.
- Replace the file contents with one print() line that shows web-01.
- Save server_status.py.
- Return to the standard Linux terminal.
- Run the file with the same terminal command.
You’ll see web-01 in the terminal.
- Restore server_status.py with this final line:
print("Python is running")
Why restore this line?
The practice changes were temporary checks. Restoring this line gives the next lesson a known starting point.
✔️ Awesome, I've got everything!
Great. Double check that you saved server_status.py before the final run.
ⓧ I'd like to double check the full code
Compare your complete server_status.py file with this version.
print("Python is running")
- Save server_status.py by pressing Ctrl+S in Xed.
- Return to the standard Linux terminal.
Before the final check, predict whether the terminal will show the restored message or the last practice message.
- Verify the finished file by running:
python3 server_status.py
What proves the file works?
The command runs the saved file from ~/python-devops/project1. Fresh output proves that Python read the restored instruction.
You’ll see Python is running in the standard Linux terminal. That is your first complete edit, save, and run loop.
Seeing old output or a quote problem?
- Save server_status.py in Xed before running it again. Unsaved changes leave the terminal showing older output.
- Check that the opening quote has a matching closing quote before the parenthesis. A missing quote prevents Python from finding the end of the message.
- Confirm that the standard Linux terminal is still inside ~/python-devops/project1. Running from another folder can point Python at the wrong file.
Ask for help: Help me find why my saved Python file shows old output or reports a quote problem.
You learned that a Python file stores reusable instructions. You also used print() to produce visible output.
Your first Python file is saved and runnable. Next, you’ll give the server status card labeled places to store its values.
Store Values with Variables
Your first Python file runs the same instruction each time. A server report becomes easier to update when every important value has a clear label.
In this step, you'll use variables to store text plus a whole number. A planned terminal check exposes the problem with joining those value types directly.
In this step, get ready to:
- Store server details in named variables.
- Practise updating stored values through terminal checks.
- Inspect a planned TypeError from a mixed-value expression.
Store values in labeled variables
A variable is a labeled place that stores one value. Quotes make text a string. A whole number appears without quotes.
- Return to server_status.py in Xed.
- Replace the existing print() call by copying this code:
server_name = "web-01"
environment = "production"
used_space = 68
print(server_name)
print(environment)
print(used_space)
How Do Variables Help?
- The = symbol assigns a value to a variable.
- The server_name variable stores the text web-01.
- The environment variable stores the text production.
- The used_space variable stores 68 as an integer.
- Save server_status.py.
- Switch back to the standard Linux terminal from earlier.
- Run the saved file by using this command:
python3 server_status.py
What Does This Command Do?
The command asks Python to run the instructions saved in server_status.py. Each print() call displays the current value from one variable.
You'll see web-01, production, and 68 on separate lines.
Seeing the Previous Message?
- Return to Xed to confirm that you saved server_status.py after replacing the old code.
- Check every variable spelling if Python reports that it cannot find a name.
Ask for help: Why is my Python file showing old output or reporting an unknown variable?
Practise changing stored values
A variable keeps the same label when its stored value changes. Running the file after each edit lets you connect the code to the output.
- Return to server_status.py in Xed.
- Change the value stored in server_name to db-02.
- Save server_status.py.
- Switch back to the standard Linux terminal.
- Run the same Python command from the previous check.
You'll see db-02 on the first output line. The other stored values remain unchanged.
- Return to server_status.py in Xed.
- Replace the file contents with a variable named port that stores the whole number 8080.
- Add a print() call that displays port.
- Save server_status.py.
- Switch back to the standard Linux terminal.
- Run the same Python command from the previous check.
You'll see 8080 in the terminal.
- Return to server_status.py in Xed.
- Replace the file contents with cache-01 stored in server_name.
- Store the whole number 40 in used_space.
- Add one print() call that passes server_name plus used_space as separate arguments.
- Save server_status.py.
- Switch back to the standard Linux terminal.
- Run the same Python command from the previous check.
You'll see cache-01 40 on one line. Python places a space between separate print() arguments.
Practice Output Looks Different?
- Check that every value is assigned with one = symbol.
- Keep quotes around text values such as cache-01.
- Leave quotes off whole numbers such as 40.
Ask for help: Can you help me check the variable assignments in my practice code?
Trigger the planned type error
The last practice gave print() two separate arguments. This check asks the + operator to join a text label directly with a whole-number variable.
- Return to server_status.py in Xed.
- Replace the practice code by copying this planned test:
used_space = 68
print("Used space: " + used_space)
What Is This Code Testing?
- The first line stores the whole number 68 in used_space.
- The second line asks + to combine the text label with the stored number.
- Save server_status.py.
- Switch back to the standard Linux terminal.
Before you run this, do you think Python can combine these two value types with +?
- Reveal only the final result line by running this command:
python3 server_status.py 2>&1 | tail -n 1
What Does This Command Check?
- The python3 server_status.py part runs your saved file.
- The 2>&1 part routes the error output into a Bash pipeline.
- The tail -n 1 part keeps only the final error line.
You'll see TypeError: can only concatenate str (not "int") to str.
Why Did Python Stop?
The used_space variable holds an integer. The label inside quotes is a string.
The + expression receives two different value types. Python raises a TypeError because that operation cannot combine them directly.
🙋♀️ Seeing Different Output?
- Confirm that 68 has no quotes around it.
- Confirm that the second line uses + between the string and used_space.
- Save server_status.py before running the terminal command again.
Ask for help: Why am I not seeing the planned TypeError from server_status.py?
✔️ Awesome, I've got everything!
Great. Keep the planned error saved in server_status.py for the next lesson.
ⓧ I'd like to double check the full code
Compare your complete server_status.py file with this version.
used_space = 68
print("Used space: " + used_space)
What Are You Checking?
Your saved file should contain one integer variable plus one print() call. Running this exact file produces the planned TypeError.
You found the exact boundary this lesson was designed to reveal. Your file now proves that variables can store different kinds of values.
The planned error gives the next lesson a clear target. Next, you'll build readable messages that include text plus numbers safely.
Build Messages with Strings
The last run proved that + cannot combine a string with the integer in used_space. The resulting TypeError stops the status report before it can print.
This lesson uses an f-string to place values inside messages. Python string methods then control how names appear in the report.
In this step, get ready to:
- Replace the broken text-plus-number expression with f-strings.
- Format server details with upper() and lower().
- Practise building messages before restoring the main report.
Turn values into readable messages
A string holds text inside quotes. An f-string starts with f before placing values inside braces.
A method is a built-in action attached with a dot. The upper() and lower() methods return text with consistent letter case.
- Return to server_status.py in Xed.
- Replace the broken two-line example with this report:
server_name = "web-01"
environment = "PRODUCTION"
used_space = 68
print(f"Server: {server_name.upper()}")
print(f"Environment: {environment.lower()}")
print(f"Used space: {used_space} GB")
What Does This Code Do?
- The first three lines store the server name, environment, and used disk space under clear variable names.
- Each f-string places a value inside braces. This lets used_space appear beside text without using +.
- The upper() method formats the server name in uppercase. The lower() method formats the environment in lowercase.
- Save server_status.py.
- Switch back to the standard Linux terminal.
Before you run the updated file, do you think the number in used_space can now appear beside text without a TypeError?
- Run the updated report with this command:
python3 server_status.py
You'll see Server: WEB-01, Environment: production, and Used space: 68 GB on separate lines. That is the earlier error resolved.
Still Seeing the TypeError?
- Check that you removed the line containing "Used space: " + used_space.
- Check that each formatted message starts with f directly before the opening quote.
- Save server_status.py before running it again.
Ask for help: Why does my Python report still show a TypeError after I added f-strings?
Practise string formatting
These temporary examples isolate one string skill at a time. Each run gives you an immediate result to compare.
- Switch back to Xed.
- Replace all code with a two-line example that stores db-02 in server_name before printing it with upper().
- Save server_status.py.
- Switch back to the standard Linux terminal.
- Run the practice example with this command:
python3 server_status.py
You'll see DB-02. The method changed every cased letter to uppercase.
- Switch back to Xed.
- Replace all code with a two-line example that stores STAGING in environment before printing it with lower().
- Save server_status.py.
- Switch back to the standard Linux terminal.
- Run the next practice example with this command:
python3 server_status.py
You'll see staging. The method returned the value in lowercase.
Your final practice target is Server cache-01 is in staging.
- Switch back to Xed.
- Replace all code with a three-line f-string example for a cache-01 server in staging.
- Save server_status.py.
- Switch back to the standard Linux terminal.
- Run the final practice example with this command:
python3 server_status.py
You'll see Server cache-01 is in staging. Your f-string placed both variables inside one readable message.
You have now tested case methods and an f-string with three sets of values.
- Switch back to Xed.
- Restore server_status.py to the three-variable report from the first substep.
- Choose the tab that matches your restored file:
✔️ I restored the main example
- Save server_status.py.
ⓧ I'd like to double check the full code
- Compare your restored server_status.py with this complete version:
server_name = "web-01"
environment = "PRODUCTION"
used_space = 68
print(f"Server: {server_name.upper()}")
print(f"Environment: {environment.lower()}")
print(f"Used space: {used_space} GB")
- Save server_status.py after correcting any differences.
Read mistakes and verify the report
String mistakes usually point to one missing character. The error or unexpected output helps you narrow down where to look.
Seeing Braces or a Syntax Problem?
- Add f directly before the opening quote if Python prints {server_name} as plain text.
- Match every opening brace with a closing brace if Python cannot read the value inside the message.
- Match every opening quote with a closing quote if Python cannot find the end of the string.
Ask for help: Can you help me find the missing f, brace, or quote in my Python string?
- Switch back to the standard Linux terminal.
Before you run the report, do you expect 68 to appear inside the final message without another TypeError?
- Verify the restored report with this command:
python3 server_status.py
You'll see this three-line report:
Server: WEB-01
Environment: production
Used space: 68 GB
What Did This Run Prove?
- Strings hold the labels that make the report readable.
- F-strings place text values and whole numbers inside messages.
- The upper() and lower() methods make the letter case consistent.
Your status report now formats text and numbers in readable messages. Next up, you'll calculate free disk space and compare number values.
Calculate and Compare Disk Space
Your Python report already turns stored values into readable messages. A useful disk check also needs to calculate an answer from those values.
In this step, you'll subtract used space from total space. You'll also compare usage with a threshold.
In this step, get ready to:
- Calculate free disk space from total space.
- Compare used disk space with a threshold.
- Print both results with f-strings.
Calculate free disk space
An integer is a whole number without a decimal point. An operator is a symbol that tells Python to calculate or compare values.
A comparison asks a yes-or-no question. Python represents the answer as a Boolean value such as True or False.
- In Xed from earlier, replace all content in server_status.py by copying the code below:
total_space = 100
used_space = 68
free_space = total_space - used_space
more_than_half_used = used_space > 50
print(f"Free space: {free_space} GB")
print(f"More than half used: {more_than_half_used}")
What does this code do?
- The total_space variable holds the complete disk capacity of 100 GB.
- The used_space variable holds the occupied amount of 68 GB.
- The free_space calculation uses - to subtract used space from total space.
- The more_than_half_used comparison uses > to check whether used space is greater than 50.
- The f-strings place both calculated results inside readable messages.
- Save server_status.py.
Before you run the file, do you expect the free-space calculation to produce a number above or below 50?
- Run the calculation in the standard Linux terminal by using this command:
python3 server_status.py
You'll see Free space: 32 GB on the first line. You'll see More than half used: True on the second line.
That is your first calculated status check working.
Seeing the wrong result?
- Check that 100 has no quotes. Quoted values are strings.
- Check that 68 has no quotes. Python needs an integer for this calculation.
- Check that every variable name matches its earlier spelling.
Ask for help: Help me debug my disk-space calculation.
Practice with different numbers
Changing an operator changes the question your program answers. These short experiments let you see addition, subtraction, and comparison produce different results.
- In Xed, replace the expression after free_space = with 12 + 8.
- Save server_status.py.
Before you run the file, what result do you expect from 12 + 8?
- Run the addition practice by using this command:
python3 server_status.py
The first line reads Free space: 20 GB. This confirms that + adds the two integers.
- Replace the expression after free_space = with 100 - 45.
- Save server_status.py.
Before you run the file, what result do you expect from 100 - 45?
- Run the subtraction practice by using this command:
python3 server_status.py
The first line reads Free space: 55 GB. This confirms that - subtracts the second integer from the first.
- Restore the expression after free_space = to total_space - used_space.
- Save server_status.py.
- Confirm the original free-space calculation by running:
python3 server_status.py
The first line returns to Free space: 32 GB. Your lesson calculation is back in place.
- Replace the expression after more_than_half_used = with 75 > 80.
- Save server_status.py.
Before you run the file, do you expect 75 > 80 to produce True or False?
- Run the comparison practice by using this command:
python3 server_status.py
The second line reads More than half used: False. The comparison is false because 75 is below 80.
Practice output not changing?
- Save server_status.py before each run.
- Check that you changed the expression on the correct assignment line.
- Check the terminal output again after each saved change.
Ask for help: Help me find why my practice result is not changing.
Restore the lesson example
The temporary comparison has served its purpose. Your saved file now needs the original threshold check for the final verification.
- Replace the expression after more_than_half_used = with used_space > 50.
- Save server_status.py.
✔️ Awesome, I've got everything!
Your saved file now matches the lesson version.
ⓧ I'd like to double check the full code
- Compare your saved server_status.py file with this exact lesson version:
total_space = 100
used_space = 68
free_space = total_space - used_space
more_than_half_used = used_space > 50
print(f"Free space: {free_space} GB")
print(f"More than half used: {more_than_half_used}")
This reference keeps the two integer inputs at 100 and 68. It also restores the threshold to 50.
Before you run the lesson one last time, what two results should the saved values produce?
- Verify the restored lesson by running this command:
python3 server_status.py
You'll see Free space: 32 GB on the first line. You'll see More than half used: True on the second line.
You've turned raw disk values into a repeatable status check.
Avoid two common mix-ups
- Remove quotes from disk numbers before calculating with them. A value such as "100" is a string.
- Use = to store a value. Use == when you want to check whether two values are equal.
- Save the file before rerunning it if the terminal shows an earlier result.
Ask for help: Help me check my number types or comparison operator.
You now know how to calculate with whole numbers. You can also turn a comparison into a Boolean result.
Your program now calculates disk values. Next, you'll turn that calculation into the finished server status card.
Finish the Server Status Card
Your last version proved that Python can calculate free disk space. It also showed a comparison result.
Those separate examples still look like lesson exercises. This step gives them one clean finish that you can run as a small DevOps status card.
In this step, get ready to:
- Add the server identity values to server_status.py.
- Format the saved values as a four-line status card.
- Change used_space to prove that free_space recalculates.
Bring the values together
The card combines text values with numbers that Python can calculate. Keeping the calculation above the output makes free_space refresh whenever used_space changes.
- Treat server_name as the server label shown on the card.
- Treat environment as the deployment label shown on the card.
- Keep total_space plus used_space as whole numbers for the disk calculation.
Why calculate before printing?
The free_space variable stores the result of subtracting used_space from total_space. The final disk line can reuse that result without storing a second answer by hand.
Build and run the finished file
- In server_status.py in Xed, replace all existing code with the finished status card below:
server_name = "web-01"
environment = "production"
total_space = 100
used_space = 68
free_space = total_space - used_space
print("SERVER STATUS")
print(f"Server: {server_name.upper()}")
print(f"Environment: {environment.lower()}")
print(f"Disk: {used_space} GB used, {free_space} GB free")
What does this code do?
- The server_name variable gives the card its server identity.
- The environment variable stores the deployment environment.
- The free_space calculation updates the available disk space from the two disk numbers.
- The server_name.upper() method displays the server name in uppercase.
- The environment.lower() method displays the environment in lowercase.
- The f-strings place the saved values inside readable output lines.
- Save server_status.py.
Before you run the card, predict how the saved values will appear after the letter-case methods format them.
- Run the saved status card in the standard Linux terminal from earlier by using this command:
python3 server_status.py
What should you see?
- The heading SERVER STATUS appears at the top.
- The server line reads Server: WEB-01.
- The environment line reads Environment: production.
- The disk line reads Disk: 68 GB used, 32 GB free.
🙋♀️ Seeing the old two-line output?
- Save server_status.py in Xed before running it again.
- Check that each variable name matches the finished code exactly.
Ask for help: Help me debug why my finished server status card is showing old or unexpected output.
You have turned the separate lessons into one working status card. The next check proves that its disk line comes from arithmetic.
Check that the card really calculates
A useful status card updates when its source values change. A temporary edit reveals whether free_space is calculated each time the program runs.
- In Xed, replace 68 in the used_space assignment with 72.
- Save server_status.py.
Before you run it, predict the free-space value Python will calculate after the edit.
- Run the updated card by using the same command:
python3 server_status.py
What changed?
Python recalculates free_space as 100 - 72 each time the file runs. The disk line now reads Disk: 72 GB used, 28 GB free.
🙋♀️ Does the disk line still show 32 GB free?
- Save the edited file before running the command again.
- Confirm that free_space still subtracts used_space from total_space.
Ask for help: Help me find why changing used_space does not update free_space in my status card.
- In Xed, restore used_space from 72 to 68.
- Save server_status.py.
Before the final run, predict which used-space value and free-space value the restored disk line will show.
- Verify the finished status card by running:
python3 server_status.py
What confirms the card is finished?
You should see the four-line card with 68 GB used plus 32 GB free. That confirms the saved card has returned to its finished state.
🙋♀️ Is the final card different?
- Restore the used_space value to 68 if the disk line still shows the temporary numbers.
- Compare your file with the complete reference below if any line differs.
Ask for help: Help me compare my server status card with the finished version and find the differing line.
✔️ Awesome, I've got everything!
Your saved file now prints the finished server status card with calculated free space.
ⓧ I'd like to double check the full code
Compare your saved server_status.py with this finished version.
server_name = "web-01"
environment = "production"
total_space = 100
used_space = 68
free_space = total_space - used_space
print("SERVER STATUS")
print(f"Server: {server_name.upper()}")
print(f"Environment: {environment.lower()}")
print(f"Disk: {used_space} GB used, {free_space} GB free")
What does this reference show?
This reference is the exact finished state of server_status.py after the temporary calculation check has been restored.
Secret mission
Combine Two Disk Reports
Your one-disk card already calculates free space. Expand it into a combined report for main storage and backup storage. The finished card will total both disks and show whether used space passes 150 GB.
Clean Up Your Resources
Clean Up Your Resources
Choose whether to keep the project, pause your work, or delete the local files.
This project runs entirely in a standard Linux environment. It has no ongoing costs or cloud resources.
Resources you used:
- Local project1 directory at ~/python-devops/project1, including server_status.py.
Keep everything running
No cleanup is needed while you still want the project for practice. The combined-disk status card remains ready in its current folder.
- Save server_status.py in Xed.
- Leave ~/python-devops/project1 in place for future experiments.
Pause - I'll come back to this later
The Python program ends as soon as the card prints. Pausing this local project means closing the tools while preserving the files.
- Save server_status.py in Xed.
- Close Xed.
- Close the standard Linux terminal.
Delete - I don't want to use this again
Remove the local project when you are finished with every exercise.
Deleting the folder is permanent. Only ~/python-devops/project1 is removed.
- Return to the standard Linux terminal.
- Remove the project1 directory by running these commands:
cd ~
rm -rf ~/python-devops/project1
What does this cleanup do?
The first line moves the standard Linux terminal out of the project directory before deletion.
The second line permanently removes the project1 directory. The standard Linux terminal returns to its next prompt without printing a message when the command succeeds.
That cleanup is complete: the project1 folder is removed from your machine.
🙋♀️ Seeing a Cleanup Error?
If XFCE Terminal reports a permission problem, check that you copied ~/python-devops/project1 exactly. Run the same cleanup code again after correcting the path.
Help me troubleshoot deleting ~/python-devops/project1 safely.
Nice Work!
Nice Work!
Excellent work! Your Python server status card now calculates disk space from saved values. It presents the results as a terminal report you can rerun whenever those values change.
You learned how to:
- Created a saved Python file that produces repeatable terminal output.
- Stored text plus whole numbers in variables. Diagnosed a text-plus-number error. Built readable messages with f-strings plus string methods.
- Calculated free disk space with arithmetic. Used a Boolean comparison to show when disk use passes a limit.
- Secret Mission: Combined main disk values with backup disk values in one larger report. The card shows 165 GB used. It shows 135 GB free. Its limit check returns True.
Ready to quiz yourself?