Ansible Interview Questions

Top Ansible interview questions and answers covering Playbooks, Roles, Inventory, Vault, AWX, Ansible Automation Platform, Dynamic Inventory, Kubernetes Automation, OpenShift, CI/CD, and production troubleshooting.

Introduction

Ansible is one of the most commonly used automation tools in enterprise DevOps environments. It is widely adopted for configuration management, application deployment, cloud provisioning, patch management, compliance, Kubernetes automation, and CI/CD.

Interviewers expect candidates to understand not only Ansible syntax but also enterprise automation architecture, security, performance optimization, troubleshooting, and production best practices.

This guide covers frequently asked interview questions for:

  • DevOps Engineers
  • Cloud Engineers
  • Platform Engineers
  • Site Reliability Engineers (SRE)
  • Linux Administrators
  • Solution Architects

Enterprise Ansible Architecture

flowchart LR

Developer --> GitHub --> Jenkins --> Ansible

Ansible --> Linux

Ansible --> AWS

Ansible --> OpenShift

Ansible --> Kubernetes

Basic Questions


1. What is Ansible?

Answer

Ansible is an open-source automation platform used for:

  • Configuration Management
  • Application Deployment
  • Infrastructure Automation
  • Cloud Provisioning
  • Network Automation
  • Security Automation

It is agentless and communicates using SSH (Linux) or WinRM (Windows).


2. Why is Ansible popular?

Advantages

  • Agentless
  • YAML Based
  • Easy Learning
  • Idempotent
  • Cross Platform
  • Large Module Library
  • Cloud Integration

3. What is Configuration Management?

Configuration Management ensures servers remain in the desired state.

Examples

  • Install packages
  • Configure web servers
  • Create users
  • Restart services
  • Apply security policies

Architecture Questions


4. Explain Ansible Architecture.

flowchart LR

ControlNode --> Inventory

Inventory --> ManagedNodes

ManagedNodes --> Modules

Components

  • Control Node
  • Inventory
  • Managed Nodes
  • Playbooks
  • Modules

5. What is a Control Node?

The machine where Ansible is installed.

Responsibilities

  • Reads inventory
  • Executes playbooks
  • Connects using SSH
  • Runs modules

6. What are Managed Nodes?

Servers managed by Ansible.

Examples

  • Linux
  • Windows
  • EC2
  • Azure VM
  • Kubernetes Nodes

Inventory Questions


7. What is Inventory?

Inventory defines managed hosts.

Example

[web]

web01

web02

[db]

db01

8. Static vs Dynamic Inventory?

Static Inventory Dynamic Inventory
Manual Automatic
inventory.ini AWS/Azure/GCP
Small Environments Cloud Environments

Playbook Questions


9. What is a Playbook?

A Playbook is a YAML file that defines automation tasks.

Example

- hosts: web

  tasks:

    - name: Install Nginx

      yum:

        name: nginx

        state: present

10. What is a Module?

Modules perform specific automation tasks.

Examples

  • yum
  • apt
  • service
  • copy
  • template
  • file
  • user

Variables


11. Why use Variables?

Variables make playbooks reusable.

Example

app_name: payment-service

12. What are Facts?

Facts are automatically collected system information.

Examples

  • Hostname
  • Memory
  • CPU
  • OS
  • IP Address

Command

ansible all -m setup

Roles


13. What are Roles?

Roles organize automation into reusable components.

Structure

roles/

webserver/

database/

security/

Benefits

  • Reusable
  • Modular
  • Standardized

14. Why use Roles?

Instead of maintaining one huge playbook, organizations separate automation into reusable roles.


Templates


15. What are Templates?

Templates generate configuration files dynamically using Jinja2.

Example

server_name {{ inventory_hostname }}

Handlers


16. What are Handlers?

Handlers execute only when notified.

Example

Restart Apache after configuration changes.


Idempotency


17. What is Idempotency?

Running the same playbook multiple times produces the same result.

Example

Package already installed

No changes made


Vault Questions


18. What is Ansible Vault?

Vault encrypts sensitive information.

Examples

  • Passwords
  • Tokens
  • API Keys
  • Certificates

Command

ansible-vault encrypt secrets.yml

Galaxy & Collections


19. What is Ansible Galaxy?

Galaxy is a repository for reusable Roles and Collections.

Install

ansible-galaxy install geerlingguy.nginx

20. What are Collections?

Collections package

  • Roles
  • Modules
  • Plugins
  • Documentation

AWX Questions


21. What is AWX?

AWX is the open-source web interface for Ansible.

Features

  • Dashboard
  • Scheduling
  • RBAC
  • Credentials
  • Job History

22. What is Ansible Automation Platform?

Enterprise edition of AWX.

Provides

  • Automation Controller
  • Automation Hub
  • Analytics
  • Execution Environments

Security Questions


23. How do you secure Ansible?

Best Practices

  • SSH Keys
  • Vault
  • Least Privilege
  • RBAC
  • Encrypted Variables

24. Where should passwords be stored?

Never inside playbooks.

Use

  • Vault
  • Secrets Manager
  • HashiCorp Vault

Kubernetes Questions


25. Can Ansible manage Kubernetes?

Yes.

Examples

  • Pods
  • Deployments
  • Services
  • ConfigMaps
  • Secrets
flowchart LR

Ansible --> KubernetesAPI --> Cluster

OpenShift Questions


26. Can Ansible automate OpenShift?

Yes.

Examples

  • Projects
  • Routes
  • BuildConfigs
  • DeploymentConfigs
  • ImageStreams

Performance Questions


27. How do you improve Ansible performance?

Methods

  • Increase Forks
  • Dynamic Inventory
  • Fact Caching
  • Async Tasks
  • Tags

Scenario Questions


28. Playbook execution is slow. What will you check?

Possible reasons

  • SSH Latency
  • Low Fork Count
  • Large Inventory
  • Gathering Facts
  • Slow Modules

29. A playbook works on one server but fails on another.

What will you verify?

  • OS Version
  • Python Installed
  • SSH Access
  • Variables
  • Permissions
  • Package Repository

30. Service did not restart after configuration changed.

Possible reasons

  • Handler not notified
  • Wrong handler name
  • Service module failure

Advanced Questions


31. Explain Dynamic Inventory.

flowchart LR

AWS --> InventoryPlugin --> Ansible --> EC2Instances

Inventory automatically discovers cloud resources.


32. Explain Delegation.

Tasks execute on another host.

Example

delegate_to: localhost

33. What are Async Tasks?

Execute long-running tasks without waiting.

Example

async: 600

poll: 0

34. Explain Blocks.

Blocks group related tasks.

Structure

block:

rescue:

always:

Useful for rollback and error handling.


35. Explain Enterprise Ansible Workflow.

flowchart LR

Developer --> GitHub --> Jenkins --> Ansible --> LinuxServers --> ApplicationDeployment

Production Troubleshooting

Application deployment failed.

Steps

  • Check Inventory
  • Verify SSH Connectivity
  • Review Playbook Logs
  • Check Variables
  • Validate Templates
  • Review Handler Execution
  • Verify Permissions
  • Check Target Server Logs

Enterprise Directory Structure

ansible/

inventories/

development/

production/

roles/

collections/

playbooks/

group_vars/

host_vars/

templates/

files/

ansible.cfg

Common Enterprise Modules

Module Purpose
yum Install Packages
apt Ubuntu Packages
service Manage Services
user Manage Users
file File Operations
copy Copy Files
template Generate Configurations
git Clone Repository
kubernetes.core Kubernetes
amazon.aws AWS

Production Best Practices

  • Use Roles
  • Dynamic Inventory
  • Version Control
  • Vault for Secrets
  • SSH Keys
  • Small Playbooks
  • CI/CD Integration
  • Separate Environments
  • Fact Caching
  • Tags
  • Async Tasks
  • Idempotent Automation

Real-World Example

A company manages 2,000 Linux servers across AWS.

Workflow

  1. AWS Dynamic Inventory discovers EC2 instances.
  2. Jenkins triggers Ansible after a GitHub merge.
  3. Playbooks configure Java, Docker, Nginx, and monitoring agents.
  4. Templates generate environment-specific configuration files.
  5. Vault securely provides database credentials.
  6. Handlers restart only affected services.
  7. AWX schedules nightly patching jobs.
  8. Slack notifications are sent after successful automation.

Quick Revision Cheat Sheet

Topic Key Point
Control Node Executes Playbooks
Managed Node Target Server
Inventory List of Hosts
Playbook YAML Automation
Module Performs Task
Variable Reusable Value
Facts System Information
Handler Executes on Notify
Template Jinja2 Configuration
Role Reusable Automation
Vault Secret Management
Galaxy Community Roles
Collection Modules + Plugins
AWX Web UI
AAP Enterprise Platform
Dynamic Inventory Cloud Discovery
Async Background Tasks
Tags Partial Execution

Interview Tips

Remember these keywords

  • Agentless
  • SSH
  • YAML
  • Inventory
  • Playbook
  • Module
  • Variables
  • Facts
  • Handlers
  • Roles
  • Templates
  • Vault
  • Galaxy
  • Collections
  • AWX
  • Automation Platform
  • Dynamic Inventory
  • Idempotency
  • Async
  • Delegation

Summary

Ansible interviews focus on practical automation skills rather than memorizing commands. Interviewers expect candidates to understand how Ansible automates configuration management, cloud infrastructure, Kubernetes, OpenShift, security, and CI/CD pipelines at enterprise scale.

Hands-on experience with Playbooks, Roles, Dynamic Inventory, Vault, AWX, Automation Platform, Kubernetes modules, and production troubleshooting will significantly improve your ability to answer DevOps, Platform Engineering, Cloud Engineering, SRE, and Solution Architect interview questions confidently.