Ansible Interview Questions for Freshers (2027)

50 Ansible interview questions for freshers with answers and examples: inventory, modules, playbooks, handlers, roles, variables, facts and Vault.

Sep 11, 2025 - 16:51
Nov 5, 2026 - 02:37
 0  88
Ansible Interview Questions for Freshers (2027)

Ansible interview questions for freshers check whether you understand the basics well enough to write and run a simple playbook: what Ansible is and why it is agentless, how inventory works, what modules, tasks, plays, handlers and roles are, how variables and facts work, and how to keep secrets safe with Ansible Vault. This page has 50 questions with direct answers and short examples, mostly at fresher level, plus a few steps up so you know what comes next.

For a full bank across all levels, use the 80+ Ansible interview questions guide. When you are ready for problem-solving rounds, move to Ansible scenario-based interview questions. To see what real playbooks look like, read 15 Ansible playbooks used in production and automating server configuration with playbooks.

Key takeaways

  • Ansible is agentless: it connects over SSH (or WinRM or SSH for Windows) and runs modules, so managed Linux hosts need only SSH and Python.
  • Learn the vocabulary in order: inventory, module, task, play, playbook, handler, role, collection.
  • Idempotency is the most asked concept. Running a playbook twice should change nothing the second time.
  • Use fully qualified collection names such as ansible.builtin.copy in new playbooks.
  • Practise --check, --diff, --limit and --tags. Interviewers often ask how you would test a playbook safely.

How the questions are organised

SectionQuestionsFocus
Freshers: concepts1 to 16What Ansible is, architecture, inventory
Freshers: writing playbooks17 to 32Modules, variables, handlers, roles, Vault
2 to 5 years (next step)33 to 41Collections, testing, performance, CI
Senior (awareness)42 to 45Platform and scale topics to recognise
Scenarios for freshers46 to 50Simple troubleshooting you talk through

Ansible vocabulary at a glance

TermMeaningExample
Control nodeMachine where Ansible runsYour laptop (Linux, macOS or WSL) or a CI runner
Managed nodeHost Ansible configuresweb01, db01
InventoryList of managed nodes and groupsinventory.ini or inventory.yml
ModuleUnit of work Ansible runsansible.builtin.dnf
TaskOne call to a moduleInstall nginx
PlayTasks mapped to a group of hostsConfigure webservers
PlaybookYAML file with one or more playssite.yml
HandlerTask that runs only when notifiedRestart nginx
RoleReusable folder of tasks, templates, varsroles/nginx
CollectionPackage of modules, plugins and rolescommunity.general

Freshers: concepts and architecture

1. What is Ansible?

Ansible is an open source automation tool for configuration management, application deployment and orchestration. You describe the desired state in YAML playbooks and Ansible makes hosts match it. Red Hat sponsors the project and sells Red Hat Ansible Automation Platform on top of it.

2. What does agentless mean?

No Ansible software runs permanently on managed hosts. Ansible connects over SSH, copies a small module, runs it with Python and removes it. Compare that with tools such as Puppet or Chef that traditionally use agents.

3. What does a managed Linux node need?

SSH access and a Python interpreter for most modules. The raw module works without Python, which is how you can bootstrap Python on a minimal host.

4. Can the control node be Windows?

Not natively. The control node must be a Unix-like system such as Linux or macOS; on Windows you can use WSL. Ansible can still manage Windows hosts, using WinRM or SSH.

5. What is the difference between ansible-core and the ansible package?

ansible-core contains the engine, the CLI tools and the ansible.builtin collection. The ansible community package installs ansible-core plus a curated set of collections. Install either with pip, for example pip install ansible.

6. What is an inventory?

A file or script that lists hosts and groups, plus variables for them. It can be static (INI or YAML) or dynamic (plugins that query AWS, Azure, VMware and others).

[webservers]
web01.example.com
web02.example.com

[dbservers]
db01.example.com ansible_user=admin

[production:children]
webservers
dbservers

7. What are the default groups in every inventory?

all contains every host and ungrouped contains hosts that are in no other group.

8. What is an ad hoc command?

A one-off task run from the command line without a playbook, useful for quick checks.

ansible all -i inventory.ini -m ansible.builtin.ping
ansible webservers -i inventory.ini -m ansible.builtin.command -a "uptime"
ansible dbservers -i inventory.ini -b -m ansible.builtin.dnf -a "name=htop state=present"

9. What does the ping module do?

It checks that Ansible can connect to the host and run Python there, and returns pong. It is not an ICMP ping.

10. What is idempotency?

Running the same task many times produces the same result as running it once. If nginx is already installed, the install task reports ok instead of changed. Most modules are idempotent; command and shell are not unless you add conditions such as creates.

11. Where does Ansible look for ansible.cfg?

In this order, using the first it finds: the path in ANSIBLE_CONFIG, ansible.cfg in the current directory, ~/.ansible.cfg, then /etc/ansible/ansible.cfg.

12. What does become do?

It runs tasks with privilege escalation, by default with sudo as root. Set become: true on a play or task, or pass -b on the command line.

13. What are facts?

Information Ansible gathers about each host at the start of a play (OS, IP addresses, memory, disks), available under ansible_facts. Disable gathering with gather_facts: false when you do not need them, to save time.

14. How do you see the documentation for a module?

Run ansible-doc ansible.builtin.copy, or read the module page on docs.ansible.com. ansible-doc -l lists installed modules.

15. What is the difference between command and shell modules?

command runs a program directly without a shell, so pipes, redirects and variables like $HOME do not work. shell runs through /bin/sh and supports them. Prefer a dedicated module, then command, then shell.

16. Ansible versus Terraform?

Terraform focuses on provisioning infrastructure and tracks it in a state file. Ansible focuses on configuring systems and deploying software, without a state file. Many teams provision with Terraform and configure with Ansible. See infrastructure as code tools compared.

Freshers: writing playbooks

17. What does a basic playbook look like?

---
- name: Configure web servers
  hosts: webservers
  become: true
  tasks:
    - name: Install nginx
      ansible.builtin.dnf:
        name: nginx
        state: present

    - name: Deploy index page
      ansible.builtin.copy:
        src: files/index.html
        dest: /usr/share/nginx/html/index.html
        mode: "0644"
      notify: Restart nginx

    - name: Start and enable nginx
      ansible.builtin.service:
        name: nginx
        state: started
        enabled: true

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

Run it with ansible-playbook -i inventory.ini site.yml.

18. What is a handler and when does it run?

A task that runs only when another task notifies it and reports changed. Handlers run once at the end of the play, even if notified several times. Use them for restarts after config changes.

19. What does a task's status mean: ok, changed, failed, skipped?

ok: already in the desired state. changed: Ansible made a change. failed: the task errored and the host stops (unless errors are ignored). skipped: a when condition was false.

20. How do you define variables?

In the play (vars:), in files (vars_files:), in group_vars/ and host_vars/ folders next to the inventory, in role defaults and vars, or on the command line with -e. Use them with Jinja2: {{ http_port }}.

21. Which variable wins if it is defined in many places?

Ansible has a documented precedence order. Two points to remember: role defaults are the lowest, and extra vars passed with -e are the highest and always win.

22. What is the template module?

It renders a Jinja2 template (.j2 file) with variables and facts, then copies the result to the host. Use it for config files that differ per host or environment.

# templates/nginx.conf.j2
server {
    listen {{ http_port }};
    server_name {{ inventory_hostname }};
}

23. How do you run a task only on certain hosts or conditions?

Use when with a condition, often a fact: when: ansible_facts['os_family'] == "Debian".

24. How do you loop in Ansible?

Use loop with a list. Each item is available as item.

- name: Create users
  ansible.builtin.user:
    name: "{{ item }}"
    state: present
  loop:
    - alice
    - bob

25. What is register?

It saves a task's result in a variable so later tasks can use it, for example to check result.rc or result.stdout.

26. What is a role?

A standard folder structure that groups tasks, handlers, templates, files, variables and metadata so you can reuse them. Create a skeleton with ansible-galaxy role init nginx.

roles/nginx/
  defaults/main.yml
  handlers/main.yml
  meta/main.yml
  tasks/main.yml
  templates/
  files/
  vars/main.yml

27. defaults versus vars in a role?

defaults/main.yml holds values users are expected to override (lowest precedence). vars/main.yml holds values the role needs and that should rarely change (higher precedence).

28. What is Ansible Galaxy?

A public hub for sharing roles and collections, and the ansible-galaxy CLI that installs them, for example ansible-galaxy collection install community.general. List dependencies in a requirements.yml file.

29. What is Ansible Vault?

A feature that encrypts sensitive files or values (passwords, keys) with AES-256 so you can store them in Git. Ansible decrypts them at runtime with a password you supply.

ansible-vault create group_vars/prod/vault.yml
ansible-vault edit group_vars/prod/vault.yml
ansible-playbook site.yml --ask-vault-pass

30. How do you test a playbook before changing anything?

Run ansible-playbook site.yml --check --diff. Check mode predicts changes without making them, and diff shows file content changes. Some modules do not support check mode fully, so treat it as a preview.

31. How do you run a playbook on just one host or just some tasks?

Use --limit web01 for hosts and --tags nginx for tasks tagged nginx. --list-tasks and --list-hosts show what would run.

32. How do you check syntax?

ansible-playbook site.yml --syntax-check parses the playbook. ansible-lint goes further and flags bad practice, such as missing names or using shell where a module exists.

2 to 5 years: what comes next

33. What is a fully qualified collection name and why use it?

The full name namespace.collection.module, such as ansible.builtin.copy or community.general.ufw. It removes ambiguity when two collections have modules with the same short name. ansible-lint recommends it.

34. include_tasks versus import_tasks?

import_tasks is static: processed when the playbook is parsed, so tags and conditions apply to every imported task. include_tasks is dynamic: processed when reached at runtime, so you can loop over it or choose the file with a variable.

35. How do you speed up a slow playbook?

Increase forks (default 5), turn off fact gathering when not needed or cache facts, enable SSH pipelining, and replace loops of package installs with one call that takes a list.

36. What is a dynamic inventory?

An inventory plugin that reads hosts from a source such as AWS EC2 (amazon.aws.aws_ec2), Azure or VMware at run time and groups them by tags. It avoids hand-maintained host lists in the cloud.

37. How do you handle errors in a play?

Use block, rescue and always for try/catch style handling, failed_when and changed_when to define success, and ignore_errors sparingly.

38. How do you test roles?

Use Molecule to create test instances (often containers), apply the role, run it a second time to check idempotency, and verify results. Run it in CI on each change.

39. What are execution environments?

Container images that bundle ansible-core, collections and Python dependencies so playbooks run the same everywhere. Build them with ansible-builder and run them with ansible-navigator.

40. How do you run Ansible from CI/CD?

Run lint and syntax checks on pull requests, then ansible-playbook from a runner with SSH keys and the Vault password injected from the CI secret store. Use --check runs for review before applying to production.

41. What is delegate_to?

It runs a task on a different host than the current one, for example removing a web server from a load balancer before updating it. run_once combined with it runs the task a single time.

Senior topics to recognise

42. What is Red Hat Ansible Automation Platform?

Red Hat's subscription product that adds a web UI and API (automation controller), role-based access, credentials management, scheduling, execution environments and certified content. AWX is the upstream open source project for the controller.

43. What is Event-Driven Ansible?

A way to trigger automation from events (monitoring alerts, webhooks, message queues) using rulebooks that match conditions and run playbooks. It is part of Ansible Automation Platform and has a community version.

44. How do you roll out changes safely to many servers?

Use serial to update hosts in batches, max_fail_percentage to stop when too many fail, and health checks between batches.

45. How do large teams organise Ansible code?

Roles and collections in separate repositories with versions, a project repository per environment or service that pins them in requirements.yml, and code review plus lint and Molecule tests before merge.

Scenarios for freshers

46. ansible ping fails with "Permission denied (publickey)".

Ansible cannot log in with SSH. Check the remote user (ansible_user), that your public key is in that user's authorized_keys, and that the right private key is used (--private-key or ansible_ssh_private_key_file). Test plain ssh first.

47. A task fails with "Missing sudo password".

The task uses become but sudo needs a password. Pass --ask-become-pass (-K) or configure passwordless sudo for the automation user.

48. The second run of your playbook still shows "changed" for a task.

The task is not idempotent, often a command or shell task. Replace it with a module, or add creates, removes or changed_when so it reports changes correctly.

49. A variable shows as undefined.

Check the spelling, the file location (group_vars/<group> must match the group name), and whether the host is in that group. Run ansible-inventory -i inventory.ini --host web01 to see the variables Ansible sees.

50. Your handler did not run after a config change.

The task that notifies it may have reported ok (nothing changed), the handler name in notify may not match exactly, or the play failed before handlers ran. Use --force-handlers or meta: flush_handlers when needed.

How to prepare

  • Set up three small VMs or containers and write a playbook that installs and configures nginx, then turn it into a role.
  • Encrypt one variable file with Vault and run the playbook with it.
  • Run every playbook twice and check that the second run shows no changes.
  • For guided labs, see our Ansible training or the RHCE course, whose exam is built around Ansible, in the Kharadi, Pune classroom or live online.

FAQ

What Ansible questions are asked to freshers?

What Ansible is, why it is agentless, inventory, modules, playbooks, handlers, roles, variables, facts, idempotency and Ansible Vault.

Do I need to know Python for Ansible?

Not to write playbooks, which are YAML with Jinja2. Python helps later if you write custom modules or plugins.

What is the most important Ansible concept for interviews?

Idempotency: running a playbook again should not change a system that is already in the desired state.

Which certification covers Ansible?

The Red Hat Certified Engineer (RHCE) exam focuses on Ansible automation. Check Red Hat's site for the current exam details.

How do I practise Ansible without cloud costs?

Use local VMs or containers as managed nodes from a Linux or WSL control node.

Is Ansible still worth learning?

Yes. It remains widely used for configuration management, patching and deployment, and pairs well with Terraform.

Official references

What's Your Reaction?

Like Like 0
Dislike Dislike 0
Love Love 0
Funny Funny 0
Angry Angry 0
Sad Sad 0
Wow Wow 0
Mridul I am a passionate technology enthusiast with a strong focus on DevOps, Cloud Computing, and Cybersecurity. Through my blogs at DevOps Training Institute, I aim to simplify complex concepts and share practical insights for learners and professionals. My goal is to empower readers with knowledge, hands-on tips, and industry best practices to stay ahead in the ever-evolving world of DevOps.