DevOps Basic Interview Scripts
1. Shell Script - Service Monitoring
#!/bin/bash
SERVICE="nginx"
if systemctl is-active --quiet $SERVICE
then
echo "$SERVICE is running"
else
echo "$SERVICE is down. Restarting..."
systemctl restart $SERVICE
fi
2. Terraform - EC2 Instance
provider "aws" {
region = "us-east-1"
}
resource "aws_instance" "demo" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "[Link]"
tags = {
Name = "Interview-Instance"
}
}
3. Ansible - Install Nginx
---
- name: Install Nginx
hosts: all
become: yes
tasks:
- name: Install nginx
apt:
name: nginx
state: present
4. Jenkins Declarative Pipeline
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Building Application...'
}
}
stage('Test') {
steps {
echo 'Running Tests...'
}
}
stage('Deploy') {
steps {
echo 'Deploying Application...'
}
}
}
}
5. Dockerfile - Node App
FROM node:18
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD ["npm", "start"]
6. Kubernetes Deployment + Service
apiVersion: apps/v1
kind: Deployment
metadata:
name: demo-app
spec:
replicas: 2
selector:
matchLabels:
app: demo
template:
metadata:
labels:
app: demo
spec:
containers:
- name: demo-container
image: nginx
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: demo-service
spec:
type: NodePort
selector:
app: demo
ports:
- port: 80
targetPort: 80
7. Python - API Health Check
import requests
url = "[Link]
response = [Link](url)
if response.status_code == 200:
print("Application is Healthy")
else:
print("Application is Down")