Automation scripting

Beginner Level

Basic level automation and scripting interview questions covering fundamentals of Bash, Python, YAML, and Groovy.

Beginner Level

This section covers fundamental concepts in automation and scripting, including basic Bash commands, Python scripting, YAML syntax, and introductory Groovy concepts.

What is automation in DevOps?

Automation in DevOps refers to scripting repetitive tasks like provisioning, configuration, deployment, and monitoring to improve efficiency and reduce errors.

What are the benefits of scripting in DevOps?

  • Reduces manual effort
  • Increases consistency and repeatability
  • Improves efficiency and speed
  • Reduces errors and enhances security

What is Bash scripting?

Bash scripting is writing command-line instructions in a script file (.sh) to automate tasks in Unix/Linux environments.

How do you write a basic Bash script?

#!/bin/bash
echo "Hello, DevOps!"

Save the file (script.sh), make it executable (chmod +x script.sh), and run it (./script.sh).

What is the difference between Bash and Shell scripting?

Bash is a type of shell, but shell scripting can also be done in other shells like sh, csh, and zsh. Bash provides more advanced scripting features.

What are variables in Bash?

Variables store values and are defined without a $ sign but accessed using $.

name="DevOps"
echo "Hello, $name"

What is Python scripting used for in DevOps?

  • Infrastructure as Code (IaC)
  • CI/CD automation
  • Log analysis
  • Cloud automation (AWS, Azure, GCP SDKs)

How do you define a function in Python?

def greet():
    print("Hello, DevOps!")
greet()

What is YAML, and where is it used?

YAML (Yet Another Markup Language) is a human-readable format used for Kubernetes configurations, Ansible playbooks, CI/CD pipelines, etc.

What is a YAML file example?

version: '3'
services:
  web:
    image: nginx
    ports:
      - "80:80"

How do you write a simple Groovy script?

println "Hello, DevOps!"

Groovy is used in Jenkins pipelines and automation tasks.

What is the shebang (#!) in a script?

The shebang (#!/bin/bash or #!/usr/bin/python3) specifies the interpreter for executing the script.

What are loops in Bash?

Bash supports for, while, and until loops. Example:

for i in {1..5}; do echo "Iteration $i"; done

What are conditional statements in Bash?

if-else statements execute different code based on conditions.

if [ $USER == "root" ]; then echo "Admin access"; else echo "User access"; fi

How do you read input in Bash?

echo "Enter name: "
read name
echo "Hello, $name"

How do you create a Python virtual environment?

python3 -m venv myenv
source myenv/bin/activate

How do you parse JSON in Python?

import json
data = '{"name": "DevOps"}'
parsed = json.loads(data)
print(parsed["name"])

What is the awk command in Bash?

awk is used for text processing. Example:

awk '{print $1}' file.txt

Extracts the first column from file.txt.

How do you comment in YAML?

Use # for comments.

# This is a comment
name: DevOps

How do you declare variables in Groovy?

def name = "DevOps"
println name

On this page