DevOps Interview Coding Questions: Linux, Shell, Python, Terraform, Ansible

💻 Coding Questions Asked in DevOps/SRE Interviews (Linux, Shell, Python, Terraform, Ansible) Many DevOps interviews now include hands-on coding or scripting rounds to test real problem-solving skills 👇 Here are some commonly asked coding questions across different areas 👇 --- 🐧 Linux / Shell Scripting 🔹 Write a script to find top 5 CPU-consuming processes 🔹 Script to monitor disk usage and send alert if > 80% 🔹 Find and delete files older than 7 days 🔹 Count number of lines, words, characters in a file 🔹 Script to check if a service is running, if not restart it 💡 Example: ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%cpu | head -5 --- 🧾 Shell Scripting (Logic-Based) 🔹 Reverse a string using shell 🔹 Check if a number is prime 🔹 Print fibonacci series 🔹 Find duplicate lines in a file --- 🐍 Python (Very Common Now) 🔹 Script to read a log file and find ERROR lines 🔹 Parse a JSON file and extract specific fields 🔹 Call an API and print response 🔹 Write a script to monitor a website (uptime check) 💡 Example: with open("app.log") as f: for line in f: if "ERROR" in line: print(line) --- 🌍 Terraform (Logic + Understanding) 🔹 Write a Terraform config to: - Create EC2 instance - Attach security group 🔹 Use count or for_each to create multiple resources 🔹 Write a module and reuse it 🔹 Handle dependency using "depends_on" --- ⚙️ Ansible (Automation Tasks) 🔹 Write a playbook to: - Install nginx - Start service 🔹 Use variables for different environments 🔹 Create a role for reusable configuration 🔹 Use handlers to restart service only when config changes --- 🧠 General Coding / Logic Questions 🔹 Reverse a string (any language) 🔹 Find second largest number in array 🔹 Remove duplicates from list 🔹 Count frequency of characters 🔹 Check if string is palindrome --- 🚨 Real-World DevOps Tasks 🔹 Write script to: - Automate backup - Check server health - Deploy application 🔹 Parse logs and generate summary 🔹 Automate cleanup of unused files/resources --- 💡 Pro Tip Interviewers are not expecting perfect coding ❌ They look for: 👉 Logic 👉 Approach 👉 Clean explanation --- 💬 Which type of coding questions have you faced in interviews? #DevOps #SRE #Python #ShellScripting #Linux #Terraform #Ansible #CodingInterview #TechInterviews

To view or add a comment, sign in

Explore content categories