SAC Automation, Scripting, and Virtualization 2 — Questions and Answers
Question 1: Which PowerShell cmdlet is used to iterate over each item in a collection and execute a script block for each?
- Select-Object
- Where-Object
- ForEach-Object (Correct answer)
- Group-Object
Correct answer: ForEach-Object
ForEach-Object (alias %) pipes each input object to a script block specified with -Process.
Question 2: In a Bash script, what does the special variable '$?' hold?
- The process ID of the current script
- The exit status of the last executed command (Correct answer)
- The number of arguments passed to the script
- The name of the script file
Correct answer: The exit status of the last executed command
$? stores the exit code (0 = success, non-zero = failure) of the most recently executed command.
Question 3: Which Ansible module is best suited for copying a file from the control node to managed hosts?
- fetch
- synchronize
- copy (Correct answer)
- template
Correct answer: copy
The copy module transfers files from the control node (or a remote location) to managed hosts.
Question 4: What is the purpose of a hypervisor's 'snapshot' feature in a virtualized environment?
- To clone a VM to a new host
- To capture the state of a VM at a specific point in time (Correct answer)
- To migrate a VM with zero downtime
- To monitor VM CPU and memory usage
Correct answer: To capture the state of a VM at a specific point in time
A snapshot preserves the VM's disk, memory, and configuration state so it can be restored to that exact moment later.
Question 5: In Python scripting for sysadmin tasks, which module provides functions for interacting with the operating system such as listing directory contents?
- sys
- os (Correct answer)
- subprocess
- shutil
Correct answer: os
The os module exposes OS-level calls like os.listdir(), os.getcwd(), and os.path operations.
Question 6: What does 'idempotency' mean in the context of configuration management tools like Puppet or Ansible?
- Applying the same configuration always changes the system state
- Running the configuration multiple times produces the same result as running it once (Correct answer)
- Configurations are applied only once and never re-run
- Each configuration run creates a new virtual machine
Correct answer: Running the configuration multiple times produces the same result as running it once
An idempotent operation leaves the system in the desired state regardless of how many times it is applied.
Question 7: Which virtualization technology allows multiple isolated Linux systems (containers) to run on a single Linux kernel without a separate hypervisor?
- VMware ESXi
- Microsoft Hyper-V
- Linux Containers (LXC) (Correct answer)
- Oracle VirtualBox
Correct answer: Linux Containers (LXC)
LXC uses kernel namespaces and cgroups to isolate containers on the same kernel, eliminating a full hypervisor layer.
Which PowerShell cmdlet is used to iterate over each item in a collection and execute a script block for each?