Skip to content
$ lynuxpro

INTERVIEW PREP

Interview questions

570 questions from real DevOps, SRE, platform engineering and MLOps interviews, with the answer an interviewer wants to hear. Try answering out loud first, then open the model answer.

Showing 106–120 of 217 questions

106.An apply failed halfway. What state are you in?SeniorTerraform

Terraform saves state after each resource, so what succeeded is recorded and what failed is not. Fix the cause (permissions, quota, a bad value, an API timeout) and run plan again: it shows only the remaining work. Resources created but left broken are marked tainted and replaced on the next apply.

107.A plan says your production database will be replaced. What do you do?SeniorTerraform

Stop and don't apply. Find the attribute marked # forces replacement. A rename needs a moved block; a value changed outside Terraform needs the code aligned or ignore_changes; a change that truly needs replacement needs a planned migration (snapshot, new instance, cutover). Add prevent_destroy and the database's own deletion protection so this fails loudly next time.

108.The state file is lost or corrupted. How do you recover?SeniorTerraform

Stop all applies for that stack first. Restore the last good version from backend versioning and run plan, which should show few or no changes. With no backup, rebuild state by writing import blocks for each resource (plan -generate-config-out helps) until the plan is clean.

109.Terraform or Ansible: what is the difference?SeniorTerraform

Terraform provisions infrastructure declaratively and tracks it in state: networks, clusters, databases, IAM. Ansible configures what runs inside machines: packages, files and services. They work together, for example Terraform builds the instance and Ansible or cloud-init sets it up.

110.Your single state has grown huge and slow. What do you do?SeniorTerraform

Split it into smaller stacks by how often things change and who owns them, such as network, data and apps. Move resources with moved blocks or state commands, share values through outputs and terraform_remote_state or a parameter store, and use Terragrunt or pipelines to run stacks in order.

111.Why use OpenTofu or HCP Terraform?SeniorTerraform

OpenTofu is an open-source fork with a community license and extras such as state encryption, and it uses the same HCL for most code. HCP Terraform is a managed service that runs plans and applies, stores and locks state, keeps history and runs policy. The choice depends on license, cost and how much you want to run yourself.

112.What are the signs that a Terraform state is too big?SeniorTerraform

Plans take many minutes, people wait for state locks, one mistake can touch unrelated systems, and teams need different access to different parts. These are the signs to split it into smaller stacks.

113.Someone applied from their laptop and broke prod. How do you stop it happening again?SeniorTerraform

Make CI the only path: the production write role can only be assumed by the pipeline through OIDC, the state bucket is locked down, and every change needs a reviewed merge request with a plan. Add drift detection so manual changes are spotted quickly.

114.How do block, rescue and always work?SeniorAnsible

block holds the normal tasks. If one fails, rescue runs, for example to roll back. always runs in either case, like finally.

115.How would you speed up a slow playbook?SeniorAnsible

Raise forks, turn on SSH pipelining and connection reuse, cache or skip facts, use the free strategy where safe, run long jobs async, and measure with profile_tasks.

116.How do you test a role?SeniorAnsible

With Molecule: start a disposable container, converge the role, run it again to check idempotence, run verify checks, and destroy the container. Run it in CI on every change.

117.How do you run Ansible safely in CI/CD?SeniorAnsible

Lint and dry-run (--check --diff) on merge requests, deploy from the main branch with a manual gate, keep SSH keys and the vault password in protected variables, and pin versions.

118.What is a collection, and why pin versions?SeniorAnsible

A package of modules, roles and plugins named namespace.collection. Pinning versions in requirements.yml keeps runs the same and stops upstream updates from changing behaviour.

119.When would you write a custom module?SeniorAnsible

Only when no existing module or collection can do the job, such as for an internal API. It must be idempotent, support check mode, return correct JSON and be documented.

120.What does AWX or Ansible Automation Platform add?SeniorAnsible

A web page and API with role-based access, stored credentials, job templates, workflows with approvals, schedules, notifications and an audit trail. Jobs run in execution environments, which are container images with a fixed Ansible and libraries.