Ansible interview question · Most asked

Explain Ansible's architecture: control node, inventory, modules, playbooks, roles and handlers.

How it works Asked in DevOps Engineer interviews

Members can save this page, take notes and track progress. See membership · Sign in

Summary

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 map groups of hosts to ordered tasks, roles package tasks, templates and defaults for reuse, and handlers are tasks that run only when something notifies them, typically a service restart after a config change.

Longer Answer

For each play, Ansible gathers facts, then runs each task across all targeted hosts in parallel (5 forks by default) before moving to the next task. A task calls a module with arguments; Ansible copies the module to the host, runs it with Python and reads back JSON saying whether anything changed.

  • Inventory: static INI/YAML files or a dynamic inventory plugin (AWS, Azure, GCP) that asks the cloud API. Group variables live in group_vars/, host variables in host_vars/.
  • Modules: apt, dnf, copy, template, service, user, lineinfile, cloud modules and thousands more through collections (ansible-galaxy collection install community.general).
  • Playbooks: YAML; a play sets hosts, become, vars and a list of tasks or roles.
  • Roles: a fixed layout (tasks/, handlers/, templates/, defaults/, vars/, meta/) so the same role works for many playbooks and environments.
  • Handlers: run once at the end of the play (or at meta: flush_handlers), however many tasks notified them.

Example

site.yml                 # playbook: which roles run on which groups
inventories/prod/hosts.yml
inventories/prod/group_vars/web.yml
roles/nginx/
  tasks/main.yml
  handlers/main.yml
  templates/nginx.conf.j2
  defaults/main.yml      # lowest-precedence, overridable variables

Key Points

  • Agentless: SSH plus Python on the host.
  • Inventory says where, playbooks say what, modules do the work.
  • Roles make tasks reusable across playbooks and environments.
  • Handlers run once, only when notified by a task that changed something.

Explanation

What interviewers look for

A clear picture of the moving parts and how a run actually executes (facts, forks, task-by-task across hosts), not just a list of terms.

More Ansible questions

← All Ansible questions

Last reviewed · By the ByteCamel team · How we write content

Was this page helpful?

Report a mistake