Courseiva

XK0-006 · domain

Automation, Orchestration, and Scripting

This domain covers Bash scripting, conditionals, quoting, and orchestration tooling on Linux. Questions test reading and writing shell logic, file tests, variable handling, and using kubectl to inspect Kubernetes workloads. You must recognize correct syntax and pick the right command for a given operational task.

112 questions30 easy53 medium29 hard

Focused practice

Practice Automation, Orchestration, and Scripting questions

Scored sessions drawing only from this domain — pick a length below.

Start 20-question practice test →

What this domain covers

What to know about Automation, Orchestration, and Scripting

Write and debug Bash conditionals, quoting, and file tests, and run kubectl commands to inspect pods. The most important thing is matching the correct test operator and quoting style to the intended string or file check.

Bash test expressions with [ ], [[ ]], -f, -r, and string comparisons like -n and =

Single vs double quote behavior for variable expansion and literal strings

kubectl logs to retrieve stdout from a pod's main container

Shell control flow, exit codes, and command substitution in automation scripts

Watch out for

Common Automation, Orchestration, and Scripting exam traps

  • ▸Using = inside [[ ]] versus -eq for numeric tests, or forgetting spaces around [ and ]
  • ▸Assuming single quotes expand variables; they do not, so $NAME stays literal
  • ▸Running kubectl logs without -c when a pod has multiple containers, getting an error

Question index

All Automation, Orchestration, and Scripting questions (112)

Click any question to see the full explanation, or start a practice session above.

1

An administrator is managing a Kubernetes cluster. A pod is running but not responding as expected. The administrator wants to view the standard output logs from the pod's main container. Which kubectl command should be used?

Hard
2

A Linux administrator needs a cron job that runs /usr/local/bin/collect.sh at 02:30 every Monday, Wednesday, and Friday. The job must be added for the root user without editing the global /etc/crontab file. Which command should the administrator run to open the correct crontab for editing?

Easy
3

A Linux administrator needs to extract the value of the 'version' field from a JSON file named config.json. The file contains a top-level key 'version' with a string value. Which command should be used to retrieve just the value?

Easy
4

A system administrator is writing a Bash script that must check if a file exists and is readable. Which two test expressions can be used to achieve this? (Choose two.)

Medium
5

An Ansible playbook includes a handler that restarts a service when a configuration file is changed. Which directive in a task triggers the handler?

Medium
6

A Linux administrator schedules a maintenance script with cron using the entry `30 2 * * 1 /usr/local/bin/backup.sh`. The script runs but produces no output and fails silently when executed by cron, though it works when run interactively. Which action best addresses the silent failure?

Easy
7

A container is running a web server on port 8080 internally, and the administrator wants to access it on the host on port 80. Which Docker run option accomplishes this?

Medium
8

A system administrator wants to create a bind mount in Docker to share a host directory `/data` with a container at `/mnt/data`. Which of the following docker run options should be used?

Hard
9

A user wants to run a Docker container in detached mode, remove it automatically after it stops, and map host port 8080 to container port 80. Which command accomplishes this?

Easy
10

A Linux administrator wants to ensure a bash script stops execution immediately if any command fails. Which line should be added to the script?

Easy
11

A Linux administrator is packaging an internal automation tool as a container image and must ensure the resulting image is minimal, reproducible, and does not include a shell or package manager. Which TWO practices best support that goal? (Choose two.)

Medium
12

A Linux administrator is configuring a systemd timer to run a maintenance script daily. The administrator creates maint.service and maint.timer unit files, then runs systemctl start maint.timer. The script does not run at the expected time. Which command should the administrator run to enable the timer so it starts automatically at boot and triggers on schedule?

Easy
13

Which of the following is a key difference between Docker and Podman?

Easy
14

An administrator wants to use Ansible to ensure a service is running on a remote host. Which Ansible module should be used in a playbook?

Medium
15

An administrator needs to create a Docker image from a Dockerfile located in the current directory and tag it as 'myapp:v1'. Which command should be used?

Medium
16

A Linux administrator uses Ansible to manage a fleet of servers and needs to ensure a configuration file is present with specific contents on all web servers, restarting the service only when the file changes. Which Ansible module and handler pattern accomplishes this?

Medium
17

A bash script uses a loop to iterate over files in a directory. Which TWO of the following loop constructs will correctly iterate over each .txt file in the current directory? (Select TWO).

Medium
18

A Linux administrator needs to parse a structured configuration file and extract the value of a specific key. The file format is JSON, and the administrator wants to use a command-line tool that is commonly preinstalled on modern Linux distributions. Which command should the administrator use?

Hard
19

A Bash script contains the following line: set -e. What is the effect of this command?

Medium
20

In bash, what is the difference between single quotes and double quotes?

Easy
21

An administrator is troubleshooting a Pod in a Kubernetes cluster that is not starting. Which TWO kubectl commands are most useful for diagnosing the issue? (Choose TWO.)

Medium
22

A Linux administrator is writing a Bash script that must parse command-line options, accept a required input file argument, and provide a help message when invoked with -h. The script will be run on several distributions. Which TWO practices should the administrator follow? (Choose two.)

Hard
23

A Linux administrator needs to write a Bash script that runs a series of commands and stops immediately if any command fails. Which directive should be included at the beginning of the script?

Easy
24

A Kubernetes administrator needs to expose a deployment named 'web-app' running on port 80 internally within the cluster. Which kubectl command creates a service of type ClusterIP that maps port 80 to the target port 8080 on the pods?

Hard
25

A Docker container is running in the background. Which command allows the administrator to execute an interactive bash shell inside the running container named 'webapp'?

Easy
26

An administrator is troubleshooting a Kubernetes deployment that is not receiving traffic. The deployment has one replica and the pod is running. The service is of type ClusterIP. Which command would help verify that the service endpoints are correctly associated with the pod?

Hard
27

A Linux administrator writes a bash script that needs to exit immediately if any command fails. Which of the following should be included at the beginning of the script?

Easy
28

A Linux administrator is writing a Bash script that must continue running even if an unset variable is referenced, but must still abort on a failed command. Currently the script has only `#!/bin/bash` at the top. Which line should be added to meet these requirements?

Medium
29

A Linux administrator is writing a Bash script that processes a list of hostnames stored one per line in /etc/app/hosts.list. The script must read each line into the variable host and run a command against it, and the loop must not consume standard input from the terminal so that interactive commands inside the loop can still read from the keyboard. Which construct satisfies these requirements?

Hard
30

A DevOps engineer needs to debug a bash script that unexpectedly fails when processing files. Which of the following should be added to the script to print each command before execution?

Medium
31

A Linux administrator wants to ensure a Bash script exits immediately if any command fails. Which directive should be included at the beginning of the script?

Easy
32

A configuration-management script must take a YAML inventory file and convert it into JSON so a downstream API can consume it, preserving all nested structure. Which command accomplishes this most directly?

Medium
33

A Linux administrator is writing a Bash script that must run a cleanup routine when the script exits, whether it exits normally or is interrupted by a signal. The script defines a function named cleanup. Which command should the administrator use to ensure cleanup runs on exit?

Medium
34

A DevOps engineer is writing a Bash script that checks if a file exists and is readable. Which test condition should be used inside an if statement?

Medium
35

A Linux administrator is writing a Bash script that uses a function. Which two statements about Bash functions are correct? (Choose TWO.)

Medium
36

In a Kubernetes cluster, a developer needs to create a Deployment that runs three replicas of a container image 'myapp:1.0' and exposes port 8080. Which YAML snippet correctly defines this Deployment?

Medium
37

A Kubernetes YAML manifest defines a Deployment. Which field specifies the number of pod replicas to run?

Easy
38

In a Bash script, what is the purpose of the shebang '#!/bin/bash'?

Easy
39

A Linux administrator needs to run a Docker container in detached mode with port mapping from host port 8080 to container port 80, and mount a host directory /data to /app/data inside the container. Which command achieves this?

Medium
40

In a Bash script, what is the correct way to check if a file named '/etc/passwd' exists and is a regular file?

Easy
41

A Linux administrator is writing a Bash script that processes a list of filenames stored one per line in a file. Some filenames contain spaces. The administrator wants the loop to treat each full line as a single item without word-splitting, and also wants to strip the trailing newline from each item. Which construct accomplishes this?

Hard
42

A Linux administrator is writing a Bash script that accepts a filename as its first argument. The script should print an error and exit if the argument is missing. Which construct should the administrator use to reference the first positional parameter and test whether it is empty?

Easy
43

A developer wants to run a containerized application using Podman in a rootless environment. Which of the following is a key difference between Podman and Docker that the developer should be aware of?

Medium
44

A Linux administrator needs to schedule a maintenance script to run every Monday at 03:15 on a systemd-based server. The script must persist across reboots and must not depend on a user being logged in. Which of the following is the BEST approach?

Medium
45

A Linux administrator needs to schedule a script to run every Monday at 3:00 AM. The script is located at /opt/scripts/weekly_report.sh. Which entry should be added to the crontab to accomplish this?

Hard
46

A Linux administrator needs to schedule a recurring backup script to run every Monday at 02:30 using the system-wide cron facility on a systemd-based distribution. Which entry correctly achieves this when placed in /etc/cron.d/backup?

Hard
47

In a Bash script, the administrator wants to capture the output of a command into a variable. Which syntax should be used?

Hard
48

A Linux administrator is automating container builds and needs to reduce image size and ensure reproducibility. Which TWO practices should be applied when writing the Dockerfile? (Choose two.)

Medium
49

In a Bash script, what is the difference between single quotes and double quotes?

Easy
50

A DevOps engineer is creating a Dockerfile for a Node.js application. Which THREE of the following instructions are valid and commonly used in a Dockerfile? (Choose THREE.)

Hard
51

A Docker container needs to persistently store data that should survive container removal and be accessible by other containers. Which storage method should be used?

Medium
52

An automation engineer uses Ansible to configure a fleet of Linux servers. A playbook task installs a package and then starts a service, but the service fails to start because the package installs a configuration file only on the first run. The engineer wants the handler to notify only when the package actually changes state. Which Ansible construct ensures the service restart handler fires only when the package task reports a change?

Hard
53

A Linux administrator needs to automate the deployment of a Kubernetes application from a manifest file and verify that the rollout completes successfully within a script. Which pair of actions should the script perform to apply the manifest and block until the Deployment's rollout finishes?

Hard
54

A team uses Ansible for configuration management. They want to ensure a service is running on all managed nodes. Which Ansible module should be used in the playbook?

Medium
55

In a bash script, a developer needs to parse command-line options such as -f filename and -v (verbose). Which built-in command is best suited for this task?

Medium
56

A Linux administrator is troubleshooting a Bash script that must parse each line of a file named `servers.txt` and process fields separated by colons. The script currently uses `for line in $(cat servers.txt)` and breaks on lines containing spaces. Which construct should replace the loop to correctly iterate over lines while preserving whitespace?

Hard
57

A Linux administrator is automating container lifecycle tasks with a script and needs to ensure a specific container, named webapp, is stopped cleanly and removed, while also removing its anonymous volumes. Which TWO docker commands should be used to accomplish this? (Choose two.)

Medium
58

A Linux administrator writes a Bash script that processes a list of hostnames read from a file and must continue processing remaining hosts even if an SSH command to one host fails. The script currently uses set -e and exits on the first failure. Which change allows the loop to keep running while still exiting on other unhandled errors?

Hard
59

A Linux administrator is writing a bash script that must exit immediately if any command fails. Which of the following should be included at the beginning of the script?

Easy
60

A Bash script contains the following function: ```bash myfunc() { local result="$(( $1 + $2 ))" echo "$result" } ``` If the script calls `myfunc 5 10`, what is the output?

Medium
61

In a bash script, a function is defined to calculate a value. Which TWO of the following are valid ways to return a value from the function to the caller? (Select TWO).

Medium
62

A Linux administrator needs a scheduled task to run a backup script at 02:30 every day of the week. The system uses cron, and the administrator is editing the crontab for the `backup` user. Which crontab entry accomplishes this?

Easy
63

An administrator is creating an Ansible playbook to configure multiple web servers. Which of the following are valid ways to define variables for different groups of hosts? (Choose TWO.)

Medium
64

A Linux administrator is using Git to manage a configuration repository. They need to undo a commit that has already been pushed to a shared remote repository, without rewriting history. Which command should they use?

Hard
65

In an Ansible playbook, which THREE of the following are valid modules for managing files and packages? (Select THREE).

Medium
66

A Bash script uses getopts to parse command-line options. The script is invoked as: ./script -a -b value. Which getopts string should be used to correctly parse -a (no argument) and -b (requires an argument)?

Hard
67

A Linux administrator writes a Bash script and includes the line `#!/bin/bash` at the top. What is the purpose of this line?

Easy
68

An administrator is building a container image and needs to reduce its final size while keeping the build reproducible. Which TWO practices improve image efficiency and build reliability? (Choose two.)

Medium
69

A developer is writing a Dockerfile. The application requires a configuration file that should be copied from the build context and the container should expose port 8080. Which combination of Dockerfile instructions is correct?

Medium
70

In a Bash script, which THREE of the following are valid ways to define a function? (Select THREE.)

Medium
71

In a Bash script, a variable is assigned the output of a command using: result=$(ls -l). What is the purpose of the $() syntax?

Medium
72

A system administrator needs to update a configuration file on multiple servers using Ansible. The playbook must ensure the line 'MaxAuthTries 3' is present in /etc/ssh/sshd_config. Which Ansible module is most appropriate?

Medium
73

In a bash script, a variable is set as follows: myvar='Hello World'. Which of the following correctly prints the first 5 characters of the variable?

Hard
74

An administrator is debugging a Docker container that exits immediately after starting. Which THREE commands can help diagnose the issue? (Select THREE).

Hard
75

A Linux administrator is troubleshooting a Bash script that unexpectedly terminates when a command fails. The script uses `#!/bin/bash`. Which of the following commands, if placed at the beginning of the script, would cause it to exit on any command failure?

Hard
76

A Linux administrator is writing a Bash script that must safely process a list of filenames, some of which may contain spaces or special characters. The script reads each line from a file into a variable and then iterates over the entries. Which TWO practices should the administrator follow to avoid word-splitting and globbing issues? (Choose two.)

Medium
77

A Linux administrator is reviewing an Ansible playbook that manages a fleet of servers. The playbook must run a task only on hosts in the group webservers and must notify a handler when a configuration file changes. Which TWO of the following are valid Ansible constructs that the administrator should use? (Choose two.)

Hard
78

A Linux administrator is writing a bash script that accepts command-line options: -a for all, -f for file, and -o for output. Which of the following correctly uses getopts to parse these options?

Medium
79

A Linux administrator is debugging a Bash script that uses a function to set a global counter. The function increments the variable, but after the function returns, the counter retains its original value. The script does not use subshells or pipelines around the function call. Which of the following is the MOST likely cause?

Hard
80

A container is running and a technician needs to execute an interactive shell inside it. The container was started with 'docker run -d --name myapp myimage'. Which command will achieve this?

Medium
81

An administrator is writing a Bash script that must run a cleanup function when the script exits, whether it finishes normally or is interrupted. Which construct guarantees the function runs in both cases?

Medium
82

A Linux administrator is writing a Bash automation script that must continue processing the remaining entries in a loop even when an individual command returns a non-zero exit status. The script currently starts with `#!/bin/bash` and uses `set -e` for safety elsewhere. Which construct should the administrator use to run a command whose failure must be tolerated inside the loop?

Medium
83

A Linux administrator is writing a Bash script that must read a file line by line and preserve leading whitespace in each line. The script currently uses `for line in $(cat file.txt)`. Which construct should replace the current loop to preserve whitespace and avoid word splitting?

Medium
84

A Linux administrator is writing a systemd unit file at /etc/systemd/system/backup.service that must execute /usr/local/bin/backup.sh only after the network is fully reachable and the /mnt/archive mount is active. The unit currently has no ordering directives. Which directive should be added to the [Unit] section to satisfy this requirement?

Medium
85

A Linux administrator needs to schedule a script at /opt/scripts/report.sh to run every Monday at 02:30 for the user svcacct, without editing the system-wide /etc/crontab. Which cron entry correctly accomplishes this when placed in svcacct's crontab via crontab -e?

Medium
86

A DevOps engineer needs to run a Docker container in the background with port mapping from host port 8080 to container port 80, and name the container 'webapp'. Which command accomplishes this?

Easy
87

A cloud engineer is using Ansible to manage configuration across multiple servers. The engineer needs to store variable data that is specific to each host and sensitive database passwords. Which two Ansible features should be used for these purposes? (Choose two.)

Medium
88

A Linux administrator is writing a Bash script to back up a directory. The script must continue running even if a particular command fails, but the administrator wants to log the error and take corrective action. Which of the following should be used to handle the error condition?

Medium
89

A Bash script contains the following code: if [[ $# -eq 0 ]]; then echo 'No arguments'; fi. What does this code check?

Easy
90

A Linux administrator needs a scheduled job on a production server to run the backup script /usr/local/bin/backup.sh every day at 02:30, and the job must run as the root user regardless of who is logged in. Which single entry in /etc/crontab accomplishes this?

Easy
91

A Linux administrator needs to run a recurring backup script located at /usr/local/bin/backup.sh every day at 02:30. The system uses systemd and the administrator wants the job scheduled through a systemd timer rather than cron. Which combination of unit files must be created and enabled?

Easy
92

An Ansible playbook is being written to install the Nginx web server on a group of Ubuntu servers. Which module should be used in the playbook to install the package?

Medium
93

A developer wants to view the logs from a running Docker container named 'myapp'. Which docker command should be used?

Easy
94

A Kubernetes administrator needs to expose a deployment named 'webapp' as a service accessible externally on port 80. Which kubectl command should be used?

Medium
95

An administrator needs to deploy a set of microservices using Docker Compose. The services require configuration values that vary between development and production environments. Which approach allows the administrator to override values without modifying the docker-compose.yml file?

Hard
96

A Linux administrator uses Ansible to configure a fleet of web servers. A playbook task must copy a template file and then restart the nginx service only when the template content actually changes, avoiding needless restarts on every run. Which task construct enforces that behavior?

Hard
97

A developer is writing a Bash script that needs to parse command-line options with arguments, such as -f filename and -v. Which built-in command should be used to handle these options?

Medium
98

Which Dockerfile instruction sets the command to run when the container starts, but allows the user to override it when using docker run?

Easy
99

A Docker container needs persistent storage that survives container restarts. Which of the following is the recommended method to achieve this?

Easy
100

A Linux administrator needs to automate the deployment of a configuration file to fifty servers. The administrator wants to run a single command from a control node that copies the file to all servers in parallel and reports any failures. Which of the following tools is designed specifically for this task?

Easy
101

A configuration-management playbook run by an administrator must install the nginx package only on hosts whose inventory group is webservers, and must restart the nginx service whenever the package installation changes the system. The administrator is using Ansible. Which pair of task attributes achieves both the conditional execution and the conditional restart?

Medium
102

A Linux administrator is automating user account creation. The script reads a list of usernames from a file and creates each account. The administrator wants the script to continue processing remaining users even if one useradd command fails due to a duplicate username. Which Bash construct should be used to run useradd and handle the failure without aborting the script?

Medium
103

An administrator wants to run a script on multiple remote servers using Ansible. The script requires a variable that differs per host. Where should the administrator define this variable to follow best practices?

Hard
104

Which Kubernetes resource is used to store non-sensitive configuration data as key-value pairs that can be consumed by pods?

Easy
105

An Ansible playbook is being written to manage web servers. Which TWO modules can be used to ensure a package is installed? (Select TWO.)

Medium
106

A user wants to execute a command inside a running Docker container named 'db'. Which command should be used?

Easy
107

A Linux administrator maintains a Bash deployment script that runs unattended from cron. The script currently contains `set -e` and `set -u`, but it silently continues past a failing command inside a pipeline such as `tar -czf backup.tgz /srv | tee /var/log/backup.log`. The administrator wants the script to abort whenever any element of that pipeline returns a non-zero status. Which line should be added to the top of the script?

Medium
108

A system administrator is writing an Ansible playbook to manage a web server. Which three of the following are valid Ansible modules for system administration? (Choose THREE.)

Medium
109

A Bash script uses getopts to parse command-line options. The options are -a (requires an argument) and -b (flag). Which code correctly implements this and stores the argument for -a in $optarg?

Hard
110

A bash script needs to test whether a string variable $NAME is non-empty and equals 'admin'. Which of the following conditionals is correct?

Medium
111

An administrator is writing a Dockerfile. They need to set a default command that can be overridden when running the container. Which instruction should be used?

Hard
112

A DevOps team uses Podman to run containers rootlessly. Which TWO of the following characteristics apply to rootless Podman compared to Docker? (Select TWO).

Hard

Frequently asked questions

What does the Automation, Orchestration, and Scripting domain cover on the XK0-006 exam?
Write and debug Bash conditionals, quoting, and file tests, and run kubectl commands to inspect pods. The most important thing is matching the correct test operator and quoting style to the intended string or file check.
How many questions are in this domain?
This page lists all 112 Automation, Orchestration, and Scripting questions in the XK0-006 question bank. The actual exam draws from this domain proportionally to its weighting in the official exam blueprint.
What is the best way to practise this domain?
Start with a short focused session (10 questions) to identify gaps, then work through explanations. Repeat with a longer session once the weak areas feel solid.
Can I practise only Automation, Orchestration, and Scripting questions?
Yes — the session launcher on this page filters questions to this domain only. Choose any session length for inline explanations and scoring.
linux-plus LINUX-PLUS lxp scripting containers Practice Questions