Interview Q&A · questions with model answers
Ansible Interview Questions
Part of the study plan for: DevOps Engineer
Ordered by how often they're asked. Most-asked answers are free to read in full; members see every answer and can rate their confidence on each.
-
Most asked Explain Ansible's architecture: control node, inventory, modules, playbooks, roles and handlers.
Ansible runs from a control node and connects to managed hosts over SSH (WinRM for Windows) with no agent installed. The inventory lists hosts and groups, modules do the work on each host, playbooks…
-
Most asked What is idempotency in Ansible, and how do you keep your own tasks idempotent?
An idempotent task can run any number of times and leaves the host in the same state, reporting changed only when it actually changed something. Built-in modules (apt, template, service, user) are…
-
Most asked Write an Ansible playbook that installs Nginx, deploys its configuration, enables the service and restarts it only when the configuration changes.
Install the package, template the config with validation, notify a restart handler from the template task, and make sure the service is enabled and started. The handler only runs when the template…
-
Most asked How do you manage secrets with Ansible Vault?
Ansible Vault encrypts files or single variables with AES-256 so secrets can live in the repository encrypted. Keep secrets in dedicated vault files (group_vars/prod/vault.yml), reference them from…
-
How do you structure reusable Ansible roles for several environments?
Put everything that varies by environment into variables, give each role safe defaults in defaults/main.yml, and keep environment values in separate inventories (inventories/dev, inventories/prod)…
-
Explain serial, delegate_to, when and notify in Ansible.
serial limits how many hosts a play changes at once (rolling updates); delegate_to runs a task on a different host than the one being processed (for example, the load balancer); when makes a task…
-
How would you automate TLS certificate installation and renewal with Ansible?
Either let an ACME client on each host renew certificates (Ansible installs and configures certbot or acme.sh and a timer), or let Ansible own the lifecycle with community.crypto.acme_certificate,…
-
How would you configure 100 Linux servers consistently with Ansible?
Describe the desired state once in roles (users, SSH hardening, packages, time sync, logging, monitoring agent), target servers through a dynamic or well-grouped inventory, and roll changes out in…
-
How do Ansible and Terraform work together in one delivery pipeline?
Terraform creates and changes the infrastructure (networks, VMs, load balancers) and records it in state; Ansible configures what runs on the machines. In a pipeline, Terraform applies first and…
-
A playbook run fails halfway through 50 hosts. What do you do?
Stop and assess before re-running: see which hosts failed and why (the recap and -vvv output), whether the failed task left anything half-changed, and whether the hosts that succeeded are healthy.…
-
How do you test Ansible roles before they reach production?
Lint every change with ansible-lint and yamllint, test roles in throwaway containers or VMs with Molecule (converge, verify, then converge again to prove idempotency), run playbooks in --check…
-
What is dynamic inventory, and why use it in the cloud?
A dynamic inventory asks a source of truth (AWS, Azure, GCP, VMware, a CMDB) for the current hosts when the playbook starts, instead of reading a hand-maintained file. In the cloud, where instances…
-
A playbook takes 40 minutes across 300 hosts. How do you speed it up?
Find where the time goes first (callbacks_enabled = profile_tasks, timer), then attack the usual causes: too few forks, SSH overhead, fact gathering, slow package tasks run one item at a time, and…