Ansible Interview Questions: Real DevOps Practice Quiz

Reviewed by Mark Dickie · Last updated

13 questions on this page you can answer and see marked on the spot. Go to the first one

Ansible is an open-source configuration management and automation tool that uses declarative YAML playbooks to define the desired state of systems across one or many hosts. For an interview, you should know how playbooks, roles, and modules fit together, how inventory grouping resolves variables per host, and how Jinja2 templating turns those variables into config files. Interviewers also test whether you understand idempotency, the difference between check mode and a live run, and when to pick Ansible over Terraform or a plain shell script.

What topics does an Ansible interview cover?

ConceptWhat to know
PlaybooksYAML files defining ordered task lists; understand handlers, tags, and conditionals
RolesReusable units bundling tasks, handlers, vars, and files; know the default directory layout
InventoryStatic or dynamic host lists; know how group vars and host vars resolve
ModulesThe building blocks of tasks; be able to describe common ones like copy, template, apt, service
VariablesDefined at multiple precedence levels; know how Jinja2 pulls them into templates

How should you prepare for an Ansible interview?

  1. Write a role from scratch that installs and configures a web server, then run it with ansible-playbook --check to confirm idempotency.
  2. Study variable precedence: know the order from host vars up through extra vars passed on the command line.
  3. Practice reading and debugging failed task output, because interviewers often hand you a broken playbook and ask you to fix it.
  4. Learn when Ansible is the wrong tool: provisioning fresh cloud infrastructure is usually Terraform territory, while configuring what already exists is where Ansible is strongest.
  5. Review dynamic inventory plugins for AWS or VMware, since real environments rarely rely on a static hosts file.

Key facts

  • Tarmac has 191 Ansible interview questions on this topic, 25 of them on this page, at difficulty 1–5 of 5.
  • Tarmac tracked 369 job postings asking for Ansible in November 2026.
  • Roles asking for Ansible advertise a median base salary of £80,000, across 92 job postings as of November 2026.
  • Tarmac last reviewed these Ansible interview questions on 20 October 2026.

At a glance

Questions25 shown · 191 in the bank
Difficulty1–5 of 5
FormatsTrue / false, Multiple choice, Short answer, Ordering, Fill in the blank, Multiple answer, Flashcard, Design exercise

What you'll review

  1. ansible vault secrets
  2. ad hoc commands ansible
  3. ansible tower awx concepts
  4. error handling and idempotent retries
  5. dynamic inventory ansible

Practice questions

Try one before you open the answer. Pick an option and press Check; it's marked on the spot.

Ansible Vault is an Ansible feature that encrypts sensitive data such as passwords, certificates, and SSH keys so that the data can be safely committed to version control.#

Options

Show answer

True. Ansible Vault is a built-in feature that encrypts sensitive data — passwords, certificates, SSH keys, and other secrets — so those values can be safely stored in files checked into version control. The encrypted content is decrypted at runtime using the vault password.

Why:

Ansible Vault is a built-in Ansible tool designed to encrypt and decrypt sensitive files and variables, allowing teams to store secrets in playbooks or variable files that are checked into version control without exposing the plaintext values.

Ansible Vault uses asymmetric encryption with a public/private key pair to encrypt and decrypt secret data.#

Options

Show answer

False. Ansible Vault uses symmetric AES-256 encryption driven by a single shared password — the same password both encrypts and decrypts the data. It does not use a public/private key pair, which is the hallmark of asymmetric encryption schemes like RSA or SSH keys.

Why:

Ansible Vault uses symmetric encryption (AES256) with a single shared password — the same password encrypts and decrypts the data. It does not use a public/private key pair, which is the hallmark of asymmetric encryption.

You want to run an Ansible ad-hoc command that invokes the ping module against every host listed in your default inventory. Which of the following is the correct syntax?#

Options

Show answer

The correct syntax is ansible all -m ping. Ad-hoc commands use the ansible CLI, all targets every host in the inventory, and the -m flag specifies the module to run — in this case, ping. ansible-playbook is for running playbook files, and -a is for passing arguments to a module, not for selecting one.

Why:

Ansible ad-hoc commands are executed with the ansible CLI (not ansible-playbook, which runs playbooks). The target group or pattern follows the command — all matches every host in the inventory. The -m flag specifies the module to run, so -m ping invokes the ping module. ansible-playbook all -m ping uses the wrong tool; ansible-playbook expects a playbook file, not a module argument. ansible all -a ping uses -a, which passes arguments to a module, not the module name itself. ansible ping --all uses a non-existent flag.

What is the relationship between AWX and Ansible Tower (now part of Red Hat Ansible Automation Platform)?#

Options

Show answer

AWX is the open-source upstream community project, while Ansible Tower (now Red Hat Ansible Automation Platform) is the commercially supported downstream product built from the AWX codebase. AWX releases first as the rapid-iteration community edition, and Tower/AAP packages a stabilized, enterprise-supported version of that same project.

Why:

AWX is the open-source community project that functions as the upstream for Ansible Tower. Ansible Tower (now part of Red Hat Ansible Automation Platform, or AAP) is the commercially supported, enterprise-hardened downstream product derived from AWX. They share the same code lineage — AWX releases first, and Tower/AAP stabilizes and supports a version of that codebase.

A playbook references ansible-vault-encrypted content. Name the ansible-playbook flag that makes Ansible interactively prompt you for the vault password at runtime. Give the long-form flag name.#

Show answer

--ask-vault-pass. Passing this flag makes ansible-playbook prompt on the terminal for the vault password, which it then uses to decrypt vault-encrypted content. The equivalent long form --ask-vault-password is also accepted.

Why:

The --ask-vault-pass flag (with --ask-vault-password as the equivalent long-form spelling) tells ansible-playbook to prompt on the terminal for the vault password, instead of reading it from a password file or environment. Ansible then uses that password whenever it needs to decrypt vault-encrypted content, such as an encrypted vars file. Either long-form spelling is accepted because both name the same prompt option.

Which ansible-vault subcommand changes the decryption password of an already-encrypted file without requiring you to first decrypt it to plaintext?#

Show answer

Use ansible-vault rekey <file>. It decrypts the file with the old password and re-encrypts it with a new password in one step, so the file never needs to be stored in plaintext on disk.

Why:

The ansible-vault rekey subcommand takes a vault-encrypted file, decrypts it with the current password, and immediately re-encrypts it with a new password — all in memory. This avoids the security risk of writing the plaintext to disk, which is what you'd have to do if you manually decrypted and then re-encrypted with ansible-vault encrypt.

Which ansible-vault subcommand encrypts a single variable value inline so the resulting ciphertext can be pasted directly into a YAML file, instead of encrypting an entire file?#

Show answer

Use ansible-vault encrypt_string. It encrypts a single string value and outputs YAML with a !vault tag and the ciphertext, which you can paste directly into a variables file or group_vars.

Why:

The ansible-vault encrypt_string subcommand encrypts one value at a time and emits YAML containing the !vault-tagged ciphertext. Unlike ansible-vault encrypt, which encrypts a whole file, encrypt_string lets you keep most of a variables file human-readable while protecting only sensitive values, and the ciphertext integrates seamlessly into existing YAML structures.

An Ansible task polls a service health endpoint with retries: 3, delay: 2, register: result, and until: result.stdout == "HEALTHY". The task also sets changed_when: false so that polling never registers as a configuration change. The service never returns HEALTHY. What is the final outcome?#

Options

Show answer

With retries: 3 and an until condition that never becomes true, an Ansible task makes 4 attempts in total: the first plus 3 retries. It is then marked failed, and play execution stops for that host unless ignore_errors or a rescue block handles the failure. changed_when: false only affects the changed/ok status, not failure.

Why:

retries: 3 means 3 retries after the first attempt, so the task makes 4 attempts in total. After each attempt Ansible evaluates the until condition against the registered result. Because the condition is never satisfied and the retry budget is used up, the task is reported as failed. changed_when: false controls only the changed/ok status and does not suppress this failure. Without ignore_errors: yes or a block/rescue handler, Ansible halts the play for that host. The option claiming the task is marked changed is wrong because changed_when: false prevents the changed status. The option claiming the task is marked ok after one attempt is wrong because changed_when does not affect failure semantics. The option claiming indefinite retries is wrong because retries bounds the attempts; Ansible does not loop forever.

Order the steps below to show how Ansible turns a dynamic inventory source into target hosts for a play, from the point where the inventory source is specified to the point where the play's tasks run on those hosts.#

Put these in order

Show answer

The order is: the inventory source is specified, an inventory plugin accepts it and populates the in-memory inventory, the play's host pattern is matched against that inventory, and then the play's tasks run on the matched hosts. Each step needs the output of the previous one, so the inventory must be populated before any host pattern can be resolved.

Why:

The inventory source must be known before Ansible can choose an inventory plugin for it. The accepting plugin then populates the in-memory inventory with hosts and groups, since a host pattern can only be resolved against inventory that already exists. Only after the pattern resolves to concrete hosts can the play's tasks run on them. Each step consumes the output of the one before it, so this order is a strict dependency chain. The sequence deliberately stops at the start of the play's tasks and does not specify which task runs first, because that depends on settings such as gather_facts and pre_tasks.

Order the steps to create and run a custom dynamic inventory script that Ansible's script inventory plugin will execute (ansible-core 2.x, invoked with -i dynamic_inv.py). Each step needs the one before it.#

Put these in order

Show answer

Write, make executable, test, then run. A dynamic inventory script must first exist as a file, then get the executable bit so Ansible or a direct ./dynamic_inv.py --list call can launch it. Checking its JSON output before running a playbook confirms the host data is valid.

Why:

The script has to exist before anything else, so writing it comes first. The executable bit must be set before the file can be launched as ./dynamic_inv.py --list or by Ansible's script inventory plugin, so making it executable comes next. Running --list directly and inspecting the JSON verifies the output format (groups plus _meta hostvars) before any playbook depends on it. The playbook run, passed -i dynamic_inv.py, is last because it consumes the script's output and needs all previous steps to have succeeded.

Place these steps in the order Ansible performs them when loading inventory from a dynamic inventory source, from source verification through to the playbook using the hosts.#

Put these in order

Show answer

Ansible first calls verify_file() on enabled inventory plugins to find one that accepts the source, then calls that plugin's parse() method. Inside parse(), the plugin fills InventoryData with hosts, groups, and variables, and only after that does the playbook use the inventory. Each step depends on the output of the one before it.

Why:

The order follows the data dependencies of the inventory framework. InventoryManager.parse_source checks each enabled plugin with verify_file() before anything else, so verification comes first for the source. Only a plugin that accepts the source has parse() called on it, so the call follows verification. The population of InventoryData is work done inside parse(), so it cannot happen before the call and is part of its output. The playbook can use the inventory only after parsing has filled it, so availability comes last. This avoids claiming any fixed plugin-selection mechanism such as reading a plugin key, which is specific to the auto plugin rather than the general framework.

In Ansible, the command ansible-_____ --list is used to display the complete inventory tree — all groups, hosts, host variables, and group variables — exactly as resolved from a dynamic inventory source. It is the recommended tool for debugging and verifying the output of an inventory plugin or a legacy inventory script before running a playbook.#

Show answer

In Ansible, the command ansible-**inventory** --list is used to display the complete inventory tree — all groups, hosts, host variables, and group variables — exactly as resolved from a dynamic inventory source. It is the recommended tool for debugging and verifying the output of an inventory plugin or a legacy inventory script before running a playbook.

Why:

The ansible-inventory command (introduced in Ansible 2.4) is the standard tool for inspecting inventory. With the --list flag it outputs the fully-resolved inventory as JSON, including all groups, hosts, and variables — regardless of whether the source is a static file, an inventory plugin, or a legacy executable script. This makes it the go-to debugging tool for dynamic inventory at scale.

To control which inventory plugins Ansible may use, set the enable______ directive in the [inventory] section of ansible.cfg. This directive gives the ordered list of inventory plugins Ansible attempts when parsing inventory sources. A plugin that is not covered by an enabled plugin such as auto (for example, a non-YAML source, or a plugin that auto cannot match) must be listed there before Ansible will use it, even if the plugin code is installed on the controller.#

Show answer

To control which inventory plugins Ansible may use, set the enable_**plugins** directive in the [inventory] section of ansible.cfg. This directive gives the ordered list of inventory plugins Ansible attempts when parsing inventory sources. A plugin that is not covered by an enabled plugin such as auto (for example, a non-YAML source, or a plugin that auto cannot match) must be listed there before Ansible will use it, even if the plugin code is installed on the controller.

Why:

The enable_plugins key in the [inventory] section of ansible.cfg sets the ordered list of inventory plugins Ansible tries when parsing inventory sources. The auto plugin is enabled by default and can load collection plugins such as aws_ec2 or gcp_compute from a YAML inventory file that uses the fully qualified plugin name, so those do not need a separate entry. Plugins that are not covered by an enabled plugin like auto do need to appear in this list before Ansible will use them, even when the code is installed.

When a legacy dynamic inventory script is called with the --list argument, it can include a top-level key named _____ containing a sub-key called hostvars with all per-host variables pre-populated. When this key is present, Ansible skips calling --host <hostname> for each individual host, avoiding N+1 script invocations and dramatically improving performance at scale when managing thousands of hosts.#

Show answer

When a legacy dynamic inventory script is called with the --list argument, it can include a top-level key named **_meta** containing a sub-key called hostvars with all per-host variables pre-populated. When this key is present, Ansible skips calling --host <hostname> for each individual host, avoiding N+1 script invocations and dramatically improving performance at scale when managing thousands of hosts.

Why:

The _meta top-level key with its hostvars sub-key is an optimization in the dynamic inventory script contract. Without it, Ansible must call --host <hostname> for every host to gather that host's variables, resulting in one invocation per host. By embedding all host variables under _meta.hostvars in the --list output, Ansible can read everything in a single call — critical when the inventory source is a cloud API or CMDB that is slow or rate-limited.

You are designing an Ansible Tower / AWX deployment and reviewing its core building blocks. Which of the following statements about Tower/AWX components are correct?#

Options

Pick every one that applies.

Show answer

Ansible Tower/AWX Job Templates bind a playbook (from a Project) to an Inventory and a Credential; Workflow Templates chain Job Templates with success/failure branching; and Surveys collect extra_vars at launch. Credentials are encrypted at rest, not plaintext, and dynamic inventories can be scheduled or synced on project update—not only manually.

Why:

A Job Template is the Tower/AWX resource that binds a playbook (from a Project) to an Inventory and a Credential, plus other launch-time settings. Workflow Templates orchestrate multiple Job Templates as a directed graph with success/failure branching. Surveys are launch-time forms that collect extra_vars. c is incorrect: Tower encrypts credentials at rest (AES-256). e is incorrect: dynamic inventory sources in Tower can be synced on a schedule, on Project update, or via the API—not only by manual admin sync.

When running a playbook against a large fleet of hosts, which of the following configuration choices genuinely help reduce overall playbook runtime or improve control?#

Options

Pick every one that applies.

Show answer

Free strategy, serial batching, and smart fact gathering with a cache genuinely help. strategy: free removes per-task waiting on slower hosts, serial enables rolling updates that limit failure blast radius, and gathering = smart with a fact cache skips re-gathering facts for cached hosts. Pipelining does not replace SSH connection reuse, and forks do not scale throughput linearly.

Why:

Three choices are genuinely beneficial. Using the free strategy removes the per-task synchronization barrier, so faster hosts are not held back by slower ones. Using serial batches hosts for rolling updates and limits how many hosts a single failed task can affect, which is a control benefit. Setting gathering to smart with a fact cache lets Ansible skip fact collection for hosts whose facts are already cached; under the default implicit mode, facts are gathered on every run and the cache is only refreshed, so the smart setting is required. The claim that pipelining removes the need for ControlMaster/ControlPersist is wrong because pipelining reduces the number of SSH operations per task but does not replace those connection-reuse settings; they are independent mechanisms. The claim that adding forks beyond the host count scales throughput linearly is wrong because throughput is bounded by control-node CPU, network, and SSH session limits, so gains are sub-linear and eventually flatten.

You are configuring role-based access control (RBAC) in Ansible Tower/AWX. Which of the following statements about Tower/AWX RBAC are correct?#

Options

Pick every one that applies.

Show answer

In Tower/AWX, the correct statements are that every Inventory belongs to exactly one Organization, that granting the Use role on a credential to a Team lets its members attach that credential to a Job Template they can edit, and that a direct Admin grant on one Inventory does not extend to other Inventories. Auditors are read-only, and credentials are not shared automatically within an Organization.

Why:

Inventories are organization-scoped, so each one belongs to exactly one Organization. The Use role on a credential is what permits a user, directly or through Team membership, to attach it to a Job Template; the user must also have rights to edit that template. Assigning Admin on a single Inventory is a per-object grant that does not extend to other Inventory objects, though broader Organization-level roles are separate grants. The Auditor role is read-only across the deployment and cannot launch or modify jobs. Credentials are not automatically shared within an Organization; they require an explicit Use or Admin grant.

What cryptographic scheme does Ansible Vault use to protect secrets, and how is the vault password strengthened against brute-force attacks?#

Show answer

Ansible Vault encrypts with AES-256 in CTR mode and authenticates with HMAC-SHA256. The vault password is stretched with PBKDF2-HMAC-SHA256 using 10,000 iterations and a random per-file salt. PBKDF2 derives 80 bytes, split into a 32-byte AES key, a 32-byte HMAC key, and a 16-byte CTR IV. The file starts with a header such as $ANSIBLE_VAULT;1.1;AES256 (or ;1.2;AES256;<vault-id> for vault-ID files). The body is hex-encoded twice: the salt, HMAC and ciphertext are each hexlified, and the whole blob is hexlified again and wrapped at 80 columns.

Why:

Ansible Vault's format uses AES-256 in CTR mode for confidentiality and HMAC-SHA256 for integrity, so the scheme is encrypt-then-MAC. The password is never used directly as a key. It goes through PBKDF2-HMAC-SHA256 with 10,000 iterations and a random salt stored in the file, which slows offline guessing and prevents precomputed attacks across files. PBKDF2 produces 80 bytes that are split into the AES key, the HMAC key and the CTR IV. The file header (format 1.1, or 1.2 when a vault ID is present) identifies the format. The body is hexlified twice, and each component is hexlified before the combined blob is hexlified again and wrapped at 80 columns.

When multiple --vault-id flags are supplied (e.g., --vault-id dev@dev_pw --vault-id prod@prod_pw), how does Ansible decide which password to try when decrypting a vault-encrypted file, and what configuration changes this behavior?#

Show answer

Each vault-encrypted file carries a vault ID label in its header (e.g., dev, prod). On decrypt, Ansible first tries the password whose label matches the file's vault ID, then falls back to trying every other supplied vault password. Setting DEFAULT_VAULT_ID_MATCH = True in ansible.cfg disables the fallback so only the matching label's password is attempted—preventing accidental cross-environment decryption when many vault passwords are in play.

Why:

This flashcard covers the vault ID matching mechanism that becomes critical at scale when many vault passwords coexist. The vault ID label is embedded in the encrypted file header. By default Ansible tries the matching label first, then falls back to all other passwords. DEFAULT_VAULT_ID_MATCH = True restricts decryption to only the matching vault ID, which prevents a developer's vault password from silently decrypting production secrets.

When you run ansible-vault rekey on a vault-encrypted file, what happens to the file's ciphertext and the secret values, and what does it leave unprotected?#

Show answer

It decrypts the file with the old vault password and re-encrypts the same plaintext with the new password, using a new salt and key derived from it, so the ciphertext in the file changes while the secret values stay the same. It does not remove earlier ciphertext from version-control history, so any secret that was exposed before the rekey must also be rotated at its source.

Why:

ansible-vault rekey is a decrypt-then-re-encrypt operation: it uses the old password to decrypt each named file and writes it back encrypted under the new password, which generates a new salt and derived key, so the stored bytes change. The plaintext values are unchanged, so the rekey does not alter the secrets themselves. Old commits still contain ciphertext that the old password can decrypt, so rekeying does not protect secrets already exposed; those credentials must be rotated in the systems that issue them.

In Ansible Automation Platform 2 (and AWX 19+), execution environments — OCI-compliant container images built with ansible-builder that bundle ansible-core, collections, and system-level dependencies — replaced the older custom-virtualenv mechanism as the sole mechanism for playbook execution isolation; virtualenvs are no longer supported for job execution in this platform generation.#

Options

Show answer

True. Ansible Automation Platform 2 (AWX 19+) replaced the legacy custom-virtualenv isolation model with execution environments — OCI-compatible container images built with ansible-builder that bundle ansible-core, collections, Python, and system-level dependencies. Virtualenvs are no longer supported for job execution isolation in AAP 2; EEs are the sole mechanism.

Why:

Prior to AAP 2 / AWX 19, Tower/AWX relied on custom Python virtualenvs on the control node to isolate dependencies for different job templates. AAP 2 introduced execution environments (EEs): OCI-compatible container images (built with ansible-builder, runnable via Podman or Docker) that encapsulate ansible-core, required collections, Python packages, and system-level OS dependencies. In AAP 2, virtualenvs are no longer a supported mechanism for execution isolation — EEs are the sole mechanism. This is a definitive, documented architectural change, not a configuration choice.

In AWX, when a job template has job slicing set to N, each slice job runs the same playbook against a different subset of the inventory's hosts.#

Options

Show answer

True. In AWX job slicing, the controller divides the inventory's hosts into disjoint subsets, and each slice job runs the job template's playbook against only its own subset. The slices are tracked under a parent workflow job, and each slice keeps its own output and status.

Why:

The statement is true: job slicing partitions the hosts of the inventory, and each slice job runs the same playbook limited to its assigned host subset. The statement makes no claim about concurrency, which depends on available capacity, and it makes no claim that results are merged. The parent is a workflow job whose nodes are the slice jobs, and each slice reports its own status and output. The number of slices is also capped by the host count, so the claim is about the per-slice host subsets rather than a fixed count of N partitions.

You are the platform lead for an organization running 50,000+ hosts across AWS, GCP, and an on-prem VMware vSphere estate, spread over 12 business units (tenants). The current setup uses hand-maintained static YAML inventory files and ad-hoc shell scripts for inventory generation. Changes take days to propagate, group membership is frequently stale, and ansible-inventory --list against the full fleet takes over 20 minutes.#

Show answer

I would replace the static YAML and ad-hoc scripts with native Ansible inventory plugins — one per cloud: awsec2 for AWS, gcp_compute for GCP, and vmware_vm_inventory for the vSphere estate. Each is configured via a per-tenant YAML inventory source file. Plugins run in-process, so they can use the Ansible cache framework directly and populate host_vars/_meta natively without the JSON re-parse overhead of an external script. They also support constructed features like keyed_groups and compose for tag-to-group mapping without a second pass.

For caching, I would enable cache_plugin: redis (or jsonfile on smaller tenants) on every inventory plugin with a 5-minute TTL. The cache key is scoped per tenant + region + source so a refresh for tenant Acme does not invalidate tenant Globex's cache. In CI, where freshness is critical, I set cache: false or pass --flush-cache to force a live API fetch; for interactive operator use, the cached data keeps ansible-inventory --list under 30 seconds instead of 20 minutes. The cache_connection points to a shared Redis instance reachable from all control nodes.

The parse-time bottleneck is serial pagination across three cloud APIs for 50k hosts. I would shard the inventory by region/account: each region in each cloud is its own inventory source file/plugin instance with a scoped regions or instance_filters parameter. In CI, the inventory refresh is a parallelized pipeline stage — one ansible-inventory --list --export per source, all writing to the shared Redis cache simultaneously. The vmware_vm_inventory and gcp_compute plugins support batch fetching natively; for awsec2, setting regions explicitly and using instance_filters limits each instance's scope.

For grouping, I'd use keyed_groups in each plugin's constructed section: keyed_groups: [{prefix: tenant, key: tags.tenant}, {prefix: env, key: tags.env}, {prefix: role, key: tags.role}, {prefix: region, key: placement.region}, {prefix: lifecycle, key: tags.lifecycle}]. This produces groups like tenant_acme, env_prod, role_web, region_us_east_1, lifecycle_in_service. Playbooks then use --limit 'tenant_acme:env_prod:role_web:lifecycle_in_service' to target the intersection. The lifecycle tag (ready, in_service, draining, decommissioned) is maintained by the provisioning pipeline and reflected live by the inventory plugin on each refresh.

For CI safety, all pipeline runs pass --limit to scope to the changed tenant and --check for dry-run validation, with ansible-inventory --graph --vars as a pre-flight step to catch stale or malformed inventory before any playbook executes. Destructive playbooks are gated behind AWX/AAP approval workflows. Write access to the inventory source configuration is restricted to the platform team via Git branch protection on the inventory repository, so tenants can tag their resources but cannot alter the inventory plugin configuration.

Why:

This is a staff-level design question because the candidate must reason about the interaction between Ansible's inventory plugin framework, its cache subsystem, cloud API pagination costs, and organizational multi-tenancy — none of which has a single canonical answer. The rubric rewards the specific, verifiable architectural decisions (plugin over script, Redis cache with TTL, keyed_groups from tags, sharded parallel refresh, CI gating) rather than vague scalability platitudes.

Your team manages fleet-wide OS patching and configuration enforcement for 10,000+ Linux hosts using Ansible. A single control node runs nightly playbooks in serial batches of 50 with the default forks: 5, and the full job takes 8+ hours. SSH connection setup is the dominant per-host cost, and many hosts are behind bastion/jump hosts. The dynamic inventory is correct and current, but the execution model is the bottleneck.#

Show answer

I would move from a single control node to AAP/AWX with distributed execution environments, routing jobs to multiple isolated nodes or containerized runners via capacity-based job routing. The fleet is sharded across N execution nodes by inventory group — each node is assigned one or more region/tenant groups from the dynamic inventory, and the job template's --limit ensures each node only operates on its shard with no overlap. This distributes both the control-plane load and the SSH fan-out. With 10 nodes, each handles ~1,000 hosts, bringing the total wall-clock from 8 hours to under 30 minutes.

On each execution node, I'd set forks: 200 (up from the default 5) with serial: "10%" for ordered patching. serial: "10%" means each batch processes 10% of the in-service hosts concurrently, with up to 200 forks available per batch. For patching where order does not matter (e.g., security baseline enforcement), I'd use strategy: free for maximum parallelism — each host runs through all tasks as fast as its own SSH allows without waiting for the rest of the batch. The trade-off: forks: 200 consumes memory on the control node (roughly 30-50 MB per fork with complex module sets), so I'd monitor RSS and tune down if the node approaches 80% memory utilization, with a fallback of forks: 100 + serial: "5%".

For SSH, I'd enable pipelining: true in ansible.cfg — this eliminates the per-task SCP of the module file by piping the module over the existing SSH stdin, cutting per-task overhead from ~200ms to near zero. I'd add ssh_args: '-o ControlMaster=auto -o ControlPersist=60s' for connection multiplexing so the SSH handshake happens once per host per playbook run, not once per task. For bastion hosts, ansible_ssh_common_args: '-J [email protected]' (ProxyJump) routes all SSH through the bastion without a separate config. I'd also set transport = ssh (openssh), not paramiko, which is deprecated, slower, and does not support pipelining.

The dynamic inventory would expose a serial_batch host var computed from the group size (e.g., 10% of the in-service count for the current role) and a patch_window group that defines the rollout order. Playbooks would use serial: "{{ serial_batch | int }}%" so the batch size is data-driven. Hosts with lifecycle: draining or decommissioned are excluded automatically via group membership. Playbooks use idempotent modules (package, template, lineinfile) with a --check pre-flight pass against the full inventory to validate what would change before the live run.

For visibility, I'd deploy a custom callback_plugin that emits per-host task results to Datadog/ELK in real time, alongside AAP job events for operator tracking. For rollback, each batch is wrapped in block/rescue: before the change, the playbook snapshots the current package set (e.g., rpm -qa output) to a temp file; on failure in the rescue block, it reinstalls the previous package versions and re-syncs configs from the last-known-good Git commit tag. max_fail_percentage: 5 on the playbook halts the entire rollout if more than 5% of the in-service fleet fails, preventing a bad change from propagating across the full estate.

Why:

This is a staff-level question because the candidate must reason about the interplay of Ansible's fork model, SSH transport internals (pipelining, multiplexing), distributed control-plane design, and data-driven batching — all under a hard latency budget. The rubric rewards concrete, verifiable architectural decisions (AAP isolated nodes, forks=200, pipelining, serial from inventory vars, callback + block/rescue) rather than generic 'use more parallelism' advice.

You run a large microservices platform with a mix of Kubernetes workloads and bare-metal VMs behind hardware and cloud load balancers. Each service instance moves through lifecycle states: provisioning → ready → in_service → draining → decommissioned. You need to orchestrate a rolling configuration change across 800+ in-service instances using Ansible, where a dynamic inventory reflects the current lifecycle state of each instance in real time.#

Show answer

I'd configure the dynamic inventory plugin to expose each instance's lifecycle state as a host fact (lifecycle: in_service) and use keyed_groups to create Ansible groups per state: lifecycle_ready, lifecycle_in_service, lifecycle_draining, lifecycle_decommissioned. The inventory plugin — either a custom Python plugin or the constructed inventory applied on top of a cloud/CMDB plugin — queries the CMDB or cloud API for current state on each run, so the inventory reflects real-time lifecycle truth. Playbooks target the lifecycle_in_service group for the rolling change, with when: lifecycle == 'in_service' as a per-host guard. Hosts in draining or decommissioned are automatically excluded from the change by group membership — they are not in lifecycle_in_service.

For the rolling update, I'd set serial: "25%" on the lifecycle_in_service group in the playbook. This means Ansible processes at most 25% of the current in-service instances per batch, with forks high enough to run all hosts in each batch concurrently. The N% cap is relative to the in-service count because serial is applied to the lifecycle_in_service group — not the full inventory — so if 800 instances are in-service, each batch is 200 hosts. If the fleet shrinks to 400 in-service, the batch automatically shrinks to 100.

For load balancer integration, the playbook per batch is structured as a sequential series of plays/tasks:

  1. Drain: Set the instance to draining in the LB API — for AWS, community.aws.elb_target with state: draining on the target group; for K8s, kubectl cordon the node or scale the Deployment; for F5, the f5networks.f5_modules module to set the pool member to disabled. Then wait_for with a loop checking active connection count to drain to zero before proceeding.
  2. Change: Apply the config change with an idempotent module (template, k8s, copy) — the actual rolling config update.
  3. Health check: uri module against the instance's health endpoint with status_code: 200 and retries: 10 — wait for the service to report healthy before re-adding.
  4. Re-add: Set the instance back to in_service in the LB — community.aws.elb_target with state: present, or kubectl uncordon, or F5 pool member enabled.

For rollback, each batch is wrapped in block/rescue: if the health check in step 3 fails, the rescue block reverts the config change (re-applies the previous template version from the last-known-good Git tag), re-adds the instance to the LB in its previous state, and marks the host as failed in a hostvars-based tracking var. max_fail_percentage: 5 on the playbook means that if more than 5% of the in-service fleet fails health checks, the entire playbook halts — no further batches run — preventing a bad change from rolling across the full estate.

For idempotency, the playbook uses when: "'lifecycle_in_service' in group_names and not (config_version | default('none')) == target_version" to skip hosts that have already been successfully updated to the target config version. A per-host fact (written to a fact cache or a state file on the host) records the applied config_version. On re-run against the dynamic inventory, hosts already at the target version are skipped entirely — no drain, no change, no re-add — so the playbook reconciles drift without touching healthy, already-updated hosts.

Why:

This is a staff-level question because it requires the candidate to integrate three systems — dynamic inventory lifecycle state, Ansible's serial/strategy execution model, and external load balancer drain/health APIs — into a single coherent orchestration with rollback safety. The rubric rewards the specific, verifiable design decisions (keyed_groups from lifecycle, serial as percentage on in_service group, explicit drain→change→health→re-add sequence with named modules, block/rescue with max_fail_percentage, idempotent skip via per-host config_version fact) rather than vague 'orchestrate a rolling deploy' advice.

Related interview questions

Job market

See ansible salaries and hiring demand from live job postings.

The other 166 questions

This page shows 25 and marks what you pick. That's as far as a page can go. A free account opens the other 166 and keeps every answer. What you miss comes back until it's right: after a day, then at longer gaps.

Start with this topic

Free · the whole bank · 100 answers per 30 days, each marked with written feedback

Interview booked? Practise the job ad instead

What moved, monthly

One email a month when the bulletin comes out: what moved in the markets we track, and the new question topics we published. Confirm your address to join. Unsubscribe any time.