Skip to content
TryHired.
Interview prep · Technical · checked against the official docs

Ansible interview questions: answers checked against the docs

The configuration management questions DevOps and system administration roles get, answered in plain words and checked against the Ansible documentation.

Updated Nov 16, 2026 · Facts checked against the official documentation · questions: TryHired
Quick answer

Ansible interviews cover the agentless architecture, inventory and playbooks, idempotency, handlers, roles, variable precedence, Vault, facts, check mode, include versus import, rolling updates with serial, privilege escalation, templates, collections, loops and conditionals. Below are 13 questions; each answer lists the Ansible documentation pages it was checked against.

Basic

Basic Ansible interview questions

Advice

Basic1. What is Ansible, and what does agentless mean?

Ansible is an automation tool for configuration management, application deployment and orchestration. Agentless means nothing has to be installed on the managed machines: Ansible connects from a control node over SSH (or WinRM for Windows), pushes small modules, runs them and removes them. Compare that with tools that need an agent on every server.

Checked against: Ansible docs: basic concepts, Ansible docs: introduction

Basic2. What are the inventory, playbooks, plays, tasks and modules?

The inventory lists the managed hosts, organized into groups that can carry variables. A playbook is a YAML file of plays; each play targets hosts and runs tasks in order; each task calls a module, the unit of work, such as package, copy or service. Roles and collections package these for reuse.

INI inventory snippet · illustrative, not run on this page
[web]
web1.example.internal
web2.example.internal

[db]
db1.example.internal

Checked against: Ansible docs: building an inventory, Ansible docs: Ansible playbooks

Basic3. What is idempotency, and why does it matter in Ansible?

Running a playbook once or many times should give the same end state: if the system already matches what the playbook describes, Ansible changes nothing and reports ok rather than changed. Modules are designed to check the current state before acting. The shell and command modules cannot know that, so use them sparingly, and add creates or changed_when to keep them idempotent.

YAML snippet · illustrative, not run on this page
- name: Ensure nginx is installed
  ansible.builtin.package:
    name: nginx
    state: present

Checked against: Ansible docs: introduction, Ansible docs: Ansible playbooks

Intermediate

Intermediate Ansible interview questions

Advice

Intermediate4. What are handlers, and when do they run?

Handlers are tasks that run only when another task notifies them and reports a change, such as restarting a service after its configuration file changes. By default they run after the tasks in the play, and a handler notified several times runs only once.

YAML snippet · illustrative, not run on this page
tasks:
  - name: Deploy nginx config
    ansible.builtin.template:
      src: nginx.conf.j2
      dest: /etc/nginx/nginx.conf
    notify: Restart nginx

handlers:
  - name: Restart nginx
    ansible.builtin.service:
      name: nginx
      state: restarted

Checked against: Ansible docs: handlers

Intermediate5. What is a role, and how is it structured?

A role packages tasks, handlers, templates, files and variables in a standard directory layout (tasks/main.yml, handlers/, templates/, defaults/, vars/ and so on), so it can be reused across playbooks and shared. Put values users are expected to change in defaults/, which has the lowest precedence of all variable sources.

Checked against: Ansible docs: roles

Intermediate6. How does variable precedence work?

Ansible collects every definition of a variable and applies a fixed precedence order, from role defaults (lowest) up to extra vars passed with -e (highest, they always win). In between come inventory variables, play variables, role vars and set_fact, among others. The practical advice from the docs is to define each variable in one place.

Shell snippet · illustrative, not run on this page
ansible-playbook site.yml -e "app_version=2.4.1"

Checked against: Ansible docs: using variables

Intermediate7. What is Ansible Vault?

Vault encrypts sensitive data, such as passwords and keys, inside variable files or whole files, so they can be committed to version control. Playbooks decrypt them at run time when given the vault password, for example from a file or a prompt.

Shell snippet · illustrative, not run on this page
ansible-vault encrypt group_vars/prod/secrets.yml
ansible-playbook site.yml --ask-vault-pass

Checked against: Ansible docs: Ansible Vault

Intermediate8. What are facts?

Facts are information Ansible gathers about each managed host at the start of a play, such as the operating system, IP addresses, memory and disks. Use them in conditions and templates, for example to pick the right package name per distribution. Turning fact gathering off speeds up plays that do not need them.

YAML snippet · illustrative, not run on this page
- name: Install on Debian family only
  ansible.builtin.apt:
    name: htop
  when: ansible_facts['os_family'] == 'Debian'

Checked against: Ansible docs: conditionals, Ansible docs: facts and magic variables

Advanced

Advanced Ansible interview questions

Advice

Advanced9. How do you test a playbook safely before running it for real?

Run it in check mode (--check), often with --diff to show file changes: Ansible reports what it would change without changing anything. Modules that do not support check mode skip themselves, so a clean check run is not complete proof. Add ansible-lint, a staging environment and, for roles, automated tests.

Shell snippet · illustrative, not run on this page
ansible-playbook site.yml --check --diff --limit web

Checked against: Ansible docs: check mode and diff mode

Advanced10. What is the difference between include_tasks and import_tasks?

Imports are static: Ansible processes them before the play runs, so tags and conditions apply to every imported task and the task list is known in advance. Includes are dynamic: they are processed when execution reaches them, so they can use variables set during the run and work in loops. Use import for fixed structure and include for decisions made at run time.

YAML snippet · illustrative, not run on this page
- ansible.builtin.import_tasks: common.yml
- ansible.builtin.include_tasks: "{{ ansible_facts['os_family'] | lower }}.yml"

Checked against: Ansible docs: re-using Ansible artifacts

Advanced11. How do you do a rolling update with Ansible?

Use serial to run a play on a batch of hosts at a time, for example one server or 25 percent, before moving to the next batch, combined with taking each host out of the load balancer and health checks. By default Ansible uses the linear strategy across all targeted hosts in parallel, limited by forks.

YAML snippet · illustrative, not run on this page
- hosts: web
  serial: "25%"
  tasks:
    - name: Deploy the new release
      ansible.builtin.include_role:
        name: app_deploy

Checked against: Ansible docs: controlling playbook execution

Advanced12. What are become, templates and collections?

become runs tasks with escalated privileges, using sudo or another method, as a different user. The template module renders Jinja2 templates on the control node and copies the result to the host, which is the usual way to manage configuration files. Collections package roles, modules and plugins for distribution, and modules are referenced by their fully qualified collection names, such as ansible.builtin.copy.

YAML snippet · illustrative, not run on this page
- name: Render app config as root
  ansible.builtin.template:
    src: app.conf.j2
    dest: /etc/app/app.conf
  become: true

Checked against: Ansible docs: privilege escalation, Ansible docs: using collections, Ansible docs: templating (Jinja2)

Advanced13. How do loops and conditionals work?

loop repeats a task for each item in a list (the older with_* lookups still work, but cannot be combined with loop). when adds a condition, written as a Jinja2 expression without curly braces, and it is evaluated for each loop item.

YAML snippet · illustrative, not run on this page
- name: Create users
  ansible.builtin.user:
    name: "{{ item }}"
  loop: [ava, ben, chen]
  when: create_users | bool

Checked against: Ansible docs: conditionals, Ansible docs: loops

Practice

How to practice with this page

Advice
  • Write a role that installs and configures one service, then run it twice and explain why nothing changes.
  • Explain where you would put each variable and why.
  • Practice a rolling update with serial and a health check.
  • Know how Ansible and Terraform divide the work.
Next

Related interview prep and tools

Disclosure: TryHired makes HIRED, a paid job-search program, so we have a conflict of interest when we mention it. This question bank is free, with no TryHired signup.

FAQ

Questions people ask

What Ansible topics come up often in DevOps interviews?
Agentless architecture, inventory and groups, playbooks and modules, idempotency, handlers, roles, variables and precedence, Vault, facts, check mode, rolling updates, and how Ansible compares with Terraform (Terraform provisions infrastructure; Ansible configures it).
Is Ansible the same as Ansible Automation Platform?
No. Ansible (ansible-core plus community collections) is the open-source command-line tool. Red Hat Ansible Automation Platform is a commercial product built on it, adding a web interface, access control and scheduling. Interviews usually test the core concepts on this page.
Were these snippets run?
No. Ansible is not installed on the build machine, so the playbooks and commands are illustrations and no output is shown. Host names are examples.
Method

How this page is built

TryHired wrote these questions and answers. Statements about the technology were checked against the official documentation pages listed below, saved when the page was built (2026-11-16). The code snippets are short illustrations and were not run on this page. The question list is general practice: it does not predict what a particular employer will ask.

What this page can't tell you
  • Interviewers ask different questions for different roles and levels.
  • Answers are short explanations, not complete references.
  • No Ansible run was made; module names use fully qualified collection names as in the current documentation.
Sources
  1. Ansible docs: privilege escalation (read 2026-11-15)
  2. Ansible docs: check mode and diff mode (read 2026-11-15)
  3. Ansible docs: using collections (read 2026-11-15)
  4. Ansible docs: basic concepts (read 2026-11-15)
  5. Ansible docs: conditionals (read 2026-11-15)
  6. Ansible docs: facts and magic variables (read 2026-11-15)
  7. Ansible docs: handlers (read 2026-11-15)
  8. Ansible docs: introduction (read 2026-11-15)
  9. Ansible docs: building an inventory (read 2026-11-15)
  10. Ansible docs: loops (read 2026-11-15)
  11. Ansible docs: Ansible playbooks (read 2026-11-15)
  12. Ansible docs: re-using Ansible artifacts (read 2026-11-15)
  13. Ansible docs: roles (read 2026-11-15)
  14. Ansible docs: controlling playbook execution (read 2026-11-15)
  15. Ansible docs: templating (Jinja2) (read 2026-11-15)
  16. Ansible docs: using variables (read 2026-11-15)
  17. Ansible docs: Ansible Vault (read 2026-11-15)