Skip to content

Beginner Level

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

0 / 20 reviewed (0%)
  1. What is automation in DevOps?

    Automation in DevOps means replacing manual, repetitive work — provisioning servers, applying configuration, deploying applications, running checks — with scripts or tools that execute the same steps reliably every time.

    The goal is not just speed: automated steps are consistent (the same every run), repeatable (safe to run 100 times), and auditable (the script is the documentation). That is why nearly every DevOps practice, from CI/CD to infrastructure as code, is built on scripting.

  2. What are the benefits of scripting in DevOps?

    • Reduces manual effort — a task that took 30 minutes of clicking becomes a one-command run
    • Consistency and repeatability — the same input always produces the same result, with no "works on my machine" drift
    • Fewer human errors — typos and skipped steps are the most common cause of outages; scripts don't get tired
    • Version-controllable — scripts live in Git, so every change is reviewed, tracked, and revertible
    • Faster feedback — automated checks and deployments shorten the loop between making a change and verifying it
  3. What is Bash scripting?

    Bash (Bourne Again Shell) scripting is writing a series of shell commands into a file (.sh) that the Bash interpreter executes top to bottom, so a sequence you would otherwise type manually runs as one automated unit.

    Scripts can use variables, conditionals, loops, and functions, which turns a list of commands into real program logic. It is the default automation tool on Linux servers, which is why it appears in almost every DevOps job description.

  4. How do you write a basic Bash script?

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

    Three steps:

    1. Save the file, e.g. script.sh
    2. Make it executable: chmod +x script.sh
    3. Run it: ./script.sh

    The first line (#!, the "shebang") tells the system which interpreter to use. Running ./script.sh only works after chmod +x — otherwise you would need bash script.sh, which invokes Bash explicitly and skips the execute-permission requirement.

  5. What is the difference between Bash and Shell scripting?

    "Shell scripting" is the general term for writing scripts for any Unix shell; Bash is one specific shell. Other shells include sh (the original Bourne shell), zsh, ksh, and dash.

    Bash is a superset of POSIX sh — it adds arrays, [[ ]] tests, string operations, and more. In interviews, mention the portability angle: a script written with only POSIX features runs everywhere, while Bash-specific features require Bash (which is why system boot scripts often stick to plain sh).

  6. What are variables in Bash?

    Variables store values that scripts can read and reuse. You assign without $ and read with $:

    bash
    name="DevOps"
    echo "Hello, $name"
    echo "Hello, ${name}QA"   # braces make the boundary explicit

    Common gotchas interviewers look for:

    • No spaces around = — name = "DevOps" is an error (Bash thinks you're running a command)
    • Quote the value if it contains spaces: greeting="hello world"
    • Use "${var}" (quoted) when the value may contain spaces or is optional — it prevents unwanted word splitting
  7. What is Python scripting used for in DevOps?

    Python is the general-purpose glue language of DevOps. Typical uses:

    • Cloud automation — the AWS (boto3), Azure, and GCP SDKs are Python-first
    • CI/CD tooling — release scripts, build helpers, API automation
    • Log and data processing — parsing large files, generating reports
    • Infrastructure tooling — Terraform is written in Go but commonly extended with Python; Ansible modules are Python under the hood
    • Webhooks and bots — small Flask/FastAPI services for chat-ops and alerting
  8. How do you define a function in Python?

    python
    def greet(name):
        return f"Hello, {name}!"
    
    print(greet("DevOps"))   # Hello, DevOps!

    Functions are defined with def, can take parameters, and return values with return. Grouping logic into functions makes scripts testable and reusable — the same reason you'd use functions in Bash.

  9. What is YAML, and where is it used?

    YAML ("YAML Ain't Markup Language" — a recursive acronym; it was originally "Yet Another Markup Language") is a human-readable data serialization format built on indentation rather than brackets.

    It is the configuration language of the DevOps ecosystem:

    • Kubernetes — every resource (Pods, Deployments, Services) is YAML
    • Ansible — playbooks are YAML
    • CI/CD — GitHub Actions, GitLab CI, and Docker Compose files are YAML
    • Observability — Prometheus rules and alertmanager configs

    Interview tip: emphasize that indentation is significant — mixing tabs and spaces is the single most common YAML error.

  10. What is a YAML file example?

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

    This Docker Compose file shows the core YAML building blocks: key: value pairs (mappings), indentation to show nesting, and a list item (- "80:80"). The same structure scales up to Kubernetes manifests and Ansible playbooks, which is why learning YAML once pays off everywhere.

  11. What is Groovy, and why does Jenkins use it?

    Groovy is a dynamic language that runs on the Java Virtual Machine (JVM), known for concise syntax and smooth Java interoperability.

    Jenkins uses it because Jenkins itself is Java: pipeline definitions (Jenkinsfile) are written in Groovy, which lets pipelines mix simple DSL steps (sh, echo) with full programming logic — loops, conditionals, functions — inside the build definition.

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

    The shebang is the first line of a script and specifies which interpreter should execute it:

    bash
    #!/bin/bash          # run with Bash
    #!/usr/bin/env python3   # run with the first python3 on PATH

    When you execute ./script.sh, the kernel reads the shebang and invokes that interpreter. The #!/usr/bin/env bash variant is often preferred because it finds the interpreter through PATH instead of hardcoding a location — more portable across Linux distributions and macOS.

  13. What are loops in Bash?

    Bash supports for, while, and until loops:

    bash
    # for: iterate over a list/range
    for i in {1..5}; do echo "Iteration $i"; done
    
    # while: run while a condition holds
    while read -r line; do echo "$line"; done < file.txt
    
    # until: run until a condition becomes true
    until ping -c1 example.com &>/dev/null; do sleep 5; done

    A classic DevOps pattern is the until loop as a retry/wait mechanism — for example, waiting for a service to come up before continuing a deployment script.

  14. What are conditional statements in Bash?

    if/elif/else runs different code depending on a condition:

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

    Key details to mention:

    • Quote variables inside tests ("$USER") to avoid breakage on empty values
    • [[ ]] is the Bash-preferred test (safer than the POSIX [ ]); numeric comparisons use -eq, -lt, -gt, file checks use -f (file exists), -d (directory exists), -z (empty string)
  15. How do you read user input in Bash?

    bash
    read -rp "Enter name: " name
    echo "Hello, $name"

    -p shows the prompt in one line, and -r (always use it) prevents read from mangling backslashes. For scripts that must be non-interactive (CI pipelines), the same read can consume piped input, or you can default with ${1:-"fallback"} arguments instead.

  16. How do you create a Python virtual environment?

    bash
    python3 -m venv myenv
    source myenv/bin/activate    # Windows: myenv\Scripts\activate
    pip install requests
    pip freeze > requirements.txt

    A virtual environment isolates a project's dependencies from the system Python, so different projects can use different versions of the same library. In DevOps pipelines this matters constantly — CI runners create a fresh venv (or use containers) to guarantee builds use pinned, reproducible dependencies from requirements.txt.

  17. How do you parse JSON in Python?

    python
    import json
    
    data = '{"name": "DevOps", "tools": ["docker", "k8s"]}'
    parsed = json.loads(data)          # JSON string -> Python dict
    print(parsed["name"])              # DevOps
    output = json.dumps(parsed, indent=2)  # Python object -> JSON string

    Remember the pair: loads parses a JSON string into Python objects, dumps serializes them back out. (Their file counterparts are json.load() and json.dump().) This is the everyday pattern for handling API responses and cloud CLI output in automation scripts.

  18. What is the awk command in Bash?

    awk is a text-processing tool that splits each line into fields and applies pattern-action rules:

    bash
    awk '{print $1}' file.txt        # print the first column
    awk -F',' '{print $2}' data.csv  # comma-separated: print 2nd field
    awk 'NR>1' file.txt              # skip the header line

    Fields are numbered $1, $2, ... with $0 being the whole line; by default fields split on whitespace, and -F changes the delimiter. In DevOps work it's the go-to for quick column extraction from logs, df/ps output, and CSVs.

  19. How do you comment in YAML?

    Use # — everything after it on that line is ignored:

    yaml
    # Service configuration
    name: DevOps   # inline comment also works

    Unlike Python there is no multi-line comment syntax — each comment line needs its own #. YAML files are usually hand-edited, so good comments explaining why a value is set are genuinely useful documentation.

  20. How do you declare variables in Groovy?

    groovy
    def name = "DevOps"      // dynamic typing — type inferred
    String env = "prod"      // explicit typing also works
    println "Deploying to ${name}"   // string interpolation

    def declares a dynamically-typed variable (the common style), while explicit types are available when you want safety. Groovy also supports single-quoted strings (no interpolation) versus double-quoted (interpolates ${}) — a subtle difference that matters in Jenkinsfiles.