50+ Advanced Ansible Interview Questions (2027)

52 advanced Ansible interview questions: strategies, forks, variable precedence, custom modules, plugins, collections, execution environments, Molecule.

Sep 11, 2025 - 17:07
Nov 5, 2026 - 03:49
 0  83
50+ Advanced Ansible Interview Questions (2027)

Advanced Ansible interview questions test how well you understand what happens under a playbook: execution strategies, forks and connection tuning, variable precedence, custom modules and plugins, collections, execution environments, testing with Molecule, secrets handling and scaling with Ansible Automation Platform. This page has 52 questions with direct answers, grouped by level, plus scenarios.

This is the internals and extension guide in our Ansible series. For the full topic list start with the 80+ Ansible interview questions keeper post. Beginners should read Ansible interview questions for freshers first, and troubleshooting stories live in Ansible scenario-based interview questions. Playbook syntax has its own page: Ansible playbook interview questions.

Key takeaways

  • Interviewers for senior roles care less about module names and more about why a run is slow, why a variable has the wrong value, and how you test and ship automation.
  • Know the four built-in strategies (linear, free, host_pinned, debug) and the knobs around them: forks, serial, throttle, run_once and pipelining.
  • Be able to write a small custom module with AnsibleModule and explain when a filter, lookup or action plugin is the better choice.
  • Collections and execution environments are how Ansible content is packaged and run today. Expect questions on galaxy.yml, requirements.yml, ansible-builder and ansible-navigator.
  • Molecule and ansible-lint are the standard testing tools. Explain the idempotence check.
  • Scenario answers should follow symptom, cause, fix, prevention.

Advanced topics and the commands behind them

TopicWhat interviewers probeCommands or files
PerformanceForks, strategies, pipelining, fact cachingansible.cfg, ansible-config dump --only-changed
VariablesPrecedence, scope, hostvarsansible-inventory --graph --vars
ExtendingModules, filters, lookups, callbackslibrary/, plugins/, module_utils/
PackagingCollections, FQCN, versionsgalaxy.yml, ansible-galaxy collection build
RuntimeExecution environmentsexecution-environment.yml, ansible-builder build, ansible-navigator run
TestingLint, Molecule scenarios, idempotenceansible-lint, molecule test
SecurityVault IDs, no_log, privilege escalationansible-vault encrypt_string --vault-id
ScaleAutomation controller, Event-Driven AnsibleJob templates, rulebooks

Foundations interviewers check first

Even for senior roles, the first few minutes usually confirm that you understand the execution model. Short, precise answers here set the tone.

1. What actually happens when you run ansible-playbook?

The controller parses the inventory and playbook, builds variables for each host, and for each task renders the module arguments with Jinja2. For most modules it copies a small Python payload to the target over SSH (or WinRM), runs it with the target's Python, reads the JSON result and deletes the temporary files. Some work, such as templating, lookups and action plugins, runs on the controller.

2. 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 community collections. In production many teams install ansible-core and pin only the collections they need.

3. Why use fully qualified collection names (FQCN)?

FQCNs such as ansible.builtin.copy or community.general.ufw remove ambiguity when two collections ship a module with the same short name, and they make the source of each module clear. ansible-lint flags short names by default.

4. Which tasks run on the controller rather than the managed node?

Lookups, filters and templates are evaluated on the controller. Action plugins (for example the ones behind template, copy and fetch) do part of their work on the controller. Tasks with delegate_to: localhost or connection: local run there too.

5. What is idempotency, and how do you prove it?

Idempotency means running the same playbook again makes no further changes. You prove it by running twice and checking that the second run reports changed=0. Molecule automates this with its idempotence step.

6. When does Ansible need Python on the target?

Most Linux modules need Python on the managed node. The raw and script modules do not, which is why raw is used to bootstrap Python. Network devices often use network_cli or httpapi connections where modules run on the controller.

Advanced Ansible questions for 2 to 5 years of experience

7. What are the built-in execution strategies?

linear (default) runs each task on all hosts before moving to the next task. free lets each host run through the play as fast as it can. host_pinned is like free but keeps a fork pinned to a host until it finishes. debug opens the task debugger on failure.

- hosts: web
  strategy: free
  tasks:
    - ansible.builtin.dnf:
        name: nginx
        state: present

8. What do forks control?

Forks set how many hosts Ansible works on in parallel. The default is 5. Raising it (for example forks = 50 in ansible.cfg or -f 50) speeds up large inventories, limited by controller CPU, memory and network.

9. How do serial, throttle and run_once differ?

serial splits the play into batches of hosts (a number, a percentage or a list such as [1, 5, "25%"]) for rolling updates. throttle limits concurrency for one task or block, useful for API rate limits. run_once runs a task on the first host of the batch only.

10. What is max_fail_percentage, and how is it different from any_errors_fatal?

max_fail_percentage stops the play when more than that share of hosts in the current batch fail. any_errors_fatal: true stops the play for all hosts as soon as any host fails. Use the first for rolling deployments and the second when a partial change is worse than no change.

11. What is pipelining, and what does it need?

Pipelining sends the module to the remote Python over the existing SSH session instead of copying a file first, which cuts the number of SSH operations per task. Enable it with pipelining = True in the [ssh_connection] section. With become, it needs requiretty to be disabled in sudoers.

12. How else do you speed up SSH?

Keep SSH ControlPersist enabled so connections are reused, use pipelining, raise forks, and avoid unnecessary fact gathering. Check the current settings with ansible-config dump --only-changed.

13. How do you reduce fact-gathering time?

Set gather_facts: false where facts are not used, limit collection with gather_subset (for example !all,!min,network), and enable fact caching so facts are reused between runs.

[defaults]
gathering = smart
fact_caching = jsonfile
fact_caching_connection = /tmp/ansible_facts
fact_caching_timeout = 7200

14. How do you profile which tasks are slow?

Enable the ansible.posix.profile_tasks callback (and ansible.posix.timer) with callbacks_enabled in ansible.cfg. It prints the duration of each task at the end of the run.

15. How do async and poll work?

async sets the maximum runtime for a task, and poll sets how often Ansible checks it. poll: 0 fires the task and moves on; you later check it with ansible.builtin.async_status. This is used for long jobs such as large package updates.

- name: Start long backup
  ansible.builtin.command: /usr/local/bin/backup.sh
  async: 3600
  poll: 0
  register: backup_job

- name: Wait for backup
  ansible.builtin.async_status:
    jid: "{{ backup_job.ansible_job_id }}"
  register: result
  until: result.finished
  retries: 120
  delay: 30

16. Explain variable precedence in two sentences.

Ansible has about 22 levels of precedence; role defaults are the lowest and extra vars (-e) always win. In between, inventory vars, play vars, role vars, block and task vars, set_fact and registered vars override each other in a documented order, so put tunables in role defaults and avoid setting the same variable in many places.

17. How do you debug where a variable value came from?

Use ansible-inventory --host NAME --vars or --graph --vars to see inventory values, add a debug: var=name task, and run with -vvv. Search the repo for every place the variable is set, because a role var can silently override an inventory value.

18. What are hostvars, groups and group_names?

hostvars is a dictionary of every host's variables and facts, so one host can read another's data (for example a load balancer reading backend IPs). groups maps group names to host lists, and group_names lists the groups the current host belongs to.

19. What is the difference between delegate_to and local_action?

delegate_to runs a task on another host while keeping the current host's variables, for example removing a node from a load balancer. local_action is shorthand for delegating to localhost. Add delegate_facts: true if facts gathered should belong to the delegated host.

20. How do you write an inventory plugin configuration for AWS?

Install amazon.aws, then create a file whose name ends with aws_ec2.yml containing plugin: amazon.aws.aws_ec2, the regions, filters and keyed_groups to build groups from tags.

plugin: amazon.aws.aws_ec2
regions:
  - ap-south-1
filters:
  tag:Environment: prod
keyed_groups:
  - key: tags.Role
    prefix: role

21. What do changed_when and failed_when solve?

Command and shell tasks report changed every time and fail only on a non-zero return code. changed_when and failed_when let you base both on the output, which keeps runs idempotent and reports accurate.

22. How do block, rescue and always work together?

Tasks in block run normally. If one fails, rescue runs, like a catch. always runs either way, like finally. It is the standard pattern for rollback and cleanup.

23. How do you handle secrets for several environments?

Use Vault IDs, one per environment, and pass the matching password source at runtime, for example --vault-id prod@/path/to/script. Mark tasks that print secrets with no_log: true. In automation controller, use credentials or an external secret manager lookup instead of vault files where possible. See our guide to storing secrets in Ansible and Terraform.

24. What does ansible-lint check?

ansible-lint checks playbooks, roles and collections against rules such as FQCN usage, missing names, risky file permissions, command used instead of a module, and YAML style. It supports profiles (from min to production) so teams can tighten rules over time.

Senior advanced Ansible interview questions

25. When would you write a custom module?

When you need to manage a resource with no existing module and the logic is too complex for templates or the uri module, for example an internal API that needs idempotent create, update and delete. First check the collections on Ansible Galaxy and Automation Hub.

26. Show the skeleton of a custom module.

A module defines an argument_spec, creates an AnsibleModule, does the work and returns JSON with exit_json or fail_json. Supporting check mode means not changing anything when module.check_mode is true.

from ansible.module_utils.basic import AnsibleModule

def main():
    module = AnsibleModule(
        argument_spec=dict(
            name=dict(type="str", required=True),
            state=dict(type="str", default="present", choices=["present", "absent"]),
        ),
        supports_check_mode=True,
    )
    changed = False
    # look up current state, compare with desired state
    if module.check_mode:
        module.exit_json(changed=changed)
    # apply the change here and set changed = True if something was modified
    module.exit_json(changed=changed, name=module.params["name"])

if __name__ == "__main__":
    main()

27. Module, action plugin, filter or lookup: how do you choose?

A module runs on the target and changes state. An action plugin runs on the controller before or instead of the module, for example to render a file first. A filter transforms data inside Jinja2. A lookup fetches data on the controller from a file, API or secret store. Pick the smallest piece that solves the problem.

28. Where does shared Python code for modules go?

In module_utils. In a collection that is plugins/module_utils/, imported as ansible_collections.namespace.name.plugins.module_utils.x. Ansible bundles the needed module_utils with the module when it ships it to the target.

29. Name the main plugin types.

Action, become, cache, callback, cliconf, connection, filter, httpapi, inventory, lookup, netconf, shell, strategy, test and vars plugins, plus modules. In interviews, being able to explain callback, inventory, lookup and filter with an example is usually enough.

30. What does a collection contain?

A galaxy.yml with namespace, name, version and dependencies, plus folders such as plugins/modules, plugins/filter, roles/, playbooks/, docs/, tests/ and meta/runtime.yml. Build it with ansible-galaxy collection build and publish to Galaxy, Automation Hub or a private Galaxy server.

31. How do you pin collection versions?

List them with version ranges in collections/requirements.yml and install with ansible-galaxy collection install -r. In execution environments, the same file is baked into the image so every run uses the same versions.

collections:
  - name: amazon.aws
    version: ">=9.0.0,<10.0.0"
  - name: community.general

32. What is an execution environment?

An execution environment (EE) is a container image with ansible-core, Python, collections and system dependencies. It gives every developer and every controller node the same runtime. You build EEs with ansible-builder and run playbooks in them with ansible-navigator or automation controller.

33. What goes into execution-environment.yml?

The schema version, the base image, and dependency files for Galaxy collections, Python packages and system packages. ansible-builder turns it into a Containerfile and builds the image with Podman or Docker.

version: 3
images:
  base_image:
    name: quay.io/fedora/fedora:latest
dependencies:
  ansible_core:
    package_pip: ansible-core
  ansible_runner:
    package_pip: ansible-runner
  galaxy: requirements.yml
  python: requirements.txt
  system: bindep.txt

34. How do you test roles with Molecule?

Molecule creates test instances (usually containers), runs the role through converge, runs it again in the idempotence step and fails if anything changes, then runs verify tests and destroys the instances. molecule test runs the full sequence in CI.

35. How do you structure a large Ansible repository?

Keep inventories per environment, roles or collections for reusable logic, thin site playbooks that call roles, group_vars for environment data, and a pinned requirements.yml. Run lint and Molecule in CI on every pull request. Our post on Ansible playbooks used in production shows common patterns.

36. What does Ansible Automation Platform add on top of ansible-core?

Red Hat Ansible Automation Platform adds automation controller (formerly Ansible Tower) with RBAC, credentials, job templates, workflows, schedules and an API; automation hub for certified content; execution environments; and Event-Driven Ansible. The upstream community projects are AWX and Galaxy NG.

37. What is Event-Driven Ansible?

Event-Driven Ansible runs rulebooks that listen to event sources (webhooks, Kafka, monitoring alerts and others), match conditions and trigger actions such as running a playbook or a job template. It is used for auto-remediation, for example restarting a service when an alert arrives.

- name: Restart on alert
  hosts: all
  sources:
    - ansible.eda.webhook:
        host: 0.0.0.0
        port: 5000
  rules:
    - name: Service down
      condition: event.payload.status == "down"
      action:
        run_playbook:
          name: playbooks/restart_service.yml

38. How do you make Ansible safe to run against production?

Use check mode and diff mode in pull requests, rolling updates with serial and max_fail_percentage, health checks between batches, limits with --limit, RBAC on who can launch production jobs, and audit logs from automation controller.

39. How do you manage privilege escalation securely?

Use become only on tasks that need it, restrict sudo rules for the automation user, store become passwords as credentials or vaulted variables, and avoid running everything as root by default.

40. How do you scale Ansible to thousands of hosts?

Raise forks within controller limits, use the free or host_pinned strategy where order does not matter, cache facts, slice jobs across nodes (automation controller supports job slicing), and split playbooks so each run touches only what changed.

41. How does Ansible fit into a GitOps or CI/CD workflow?

Store playbooks and inventory in Git, run lint and Molecule on pull requests, run --check --diff against staging, and trigger production runs from merged commits through automation controller or a pipeline. Terraform often provisions infrastructure and Ansible configures it.

42. How do you write a custom filter plugin?

Create a Python file in filter_plugins/ (or plugins/filter/ in a collection) with a FilterModule class whose filters() method returns a dictionary of names to functions.

class FilterModule(object):
    def filters(self):
        return {"to_upper_keys": self.to_upper_keys}

    def to_upper_keys(self, data):
        return {k.upper(): v for k, v in data.items()}

Scenario-based advanced Ansible questions

43. A playbook against 2,000 hosts takes three hours. How do you cut it down?

Profile with profile_tasks to find the slow tasks. Then raise forks, enable pipelining and ControlPersist, cache facts or limit gather_subset, replace shell loops with modules that take lists (for example one dnf task with a list of packages), and switch to the free strategy where order does not matter.

44. A variable has the wrong value only on some hosts. What do you check?

Check ansible-inventory --host for those hosts, look for host_vars files and group membership that differ, then search for role vars, set_fact or extra vars that override it. Move the default to role defaults and keep one owner for each variable.

45. A rolling update took down the whole web tier. How should it have been written?

Use serial with small batches, take each host out of the load balancer with delegate_to, deploy, run a health check with uri and until, put it back, and set max_fail_percentage: 0 so the first failed batch stops the run.

46. Molecule passes but the idempotence step fails. What is the cause?

A task changes something every run: a command or shell task without creates or changed_when, a template with a timestamp, or a lineinfile with a regex that never matches. Fix the task so the second run reports no change.

47. A secret appeared in the automation controller job output. How do you fix and prevent it?

Rotate the secret first. Add no_log: true to the task and any registered variable that holds the secret, remove debug tasks that print it, and add a lint or review rule. Move the secret to a controller credential or an external vault lookup.

48. Your custom module works locally but fails in the execution environment. Why?

Usually a missing Python dependency or system library in the EE. Add it to requirements.txt or bindep.txt, rebuild with ansible-builder, and test with ansible-navigator run using the same image.

49. Two teams' collections both ship a module called user_sync. What happens?

If playbooks use short names, the module found first in the collections search path wins, which can change between machines. Require FQCNs everywhere, enforce it with ansible-lint, and pin collection versions.

50. An API you call from Ansible starts rate-limiting you. What do you change?

Add throttle to the API task, add retries with until and delay, run the task once with run_once where the data is the same for all hosts, and cache results in a fact.

51. A monitoring alert should trigger remediation automatically. How would you build it?

Send the alert to an Event-Driven Ansible webhook source, write a rule that matches the alert name and host, run a job template that restarts the service and checks health, and post the result back to the incident channel. Add a limit so the same host is not restarted in a loop.

52. How do you migrate an old playbook repo with short module names and no tests?

Run ansible-lint with a low profile to list problems, convert to FQCNs (ansible-lint can fix many automatically), move reusable parts into roles, add requirements.yml, add Molecule to the most used roles first, and raise the lint profile over time.

How to prepare for an advanced Ansible interview

  1. Build one collection with a custom module and a filter, and publish it to a local folder.
  2. Build an execution environment with ansible-builder and run a playbook in it with ansible-navigator.
  3. Add Molecule tests to one role and make the idempotence step pass.
  4. Write a rolling update playbook with serial, health checks and load balancer delegation.
  5. Practise explaining one performance fix with numbers you measured yourself.

Our Ansible training covers these labs in the Kharadi, Pune classroom and live online. For a wider interview plan, use the 200+ DevOps interview questions guide.

FAQs

What counts as an advanced Ansible question?

Anything beyond writing tasks: strategies and performance, variable precedence, custom modules and plugins, collections, execution environments, Molecule testing, Vault IDs and scaling with automation controller.

Do I need to write Python for advanced Ansible roles?

Basic Python helps. Senior interviews often ask you to sketch a custom module or filter plugin, but you rarely need more than functions, dictionaries and the AnsibleModule class.

What is the default number of forks in Ansible?

Five. You change it with forks in ansible.cfg or the -f option.

Is Ansible Tower still a product?

Tower's role is now filled by automation controller inside Red Hat Ansible Automation Platform. AWX is the upstream open source project.

Should I learn ansible-navigator?

Yes, if you will work with Ansible Automation Platform. It runs playbooks inside execution environments, the same way automation controller does.

How is this page different from the 80+ Ansible questions post?

The 80+ post covers the whole topic for all levels. This page goes deeper on internals, extending Ansible, packaging and testing for experienced engineers.

How many advanced questions should I practise?

Work through all 52 here, then practise the scenarios aloud. Being able to explain why matters more than the number of questions.

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.