Chapter 70: DevOps Interview Questions by Topic and Company
70.8 Ansible Interview Questions
Ansible sopa ahe - SSH aani YAML. Playbook, role aani vault he teen shabda nakki vapra.
What you will learn in this lesson
- 17 real Ansible questions with short answers
- Which companies asked them, from public interview stories
- Fresher, experienced and senior levels
- A simple way to answer: why, what, how
Why: the problem
Servers still need software and config. Ansible does that over SSH, so interviewers ask about playbooks, roles and safe secrets.
What: how to read this lesson
Each question has a short answer in three parts.
- Why: the reason the thing exists.
- What: the plain meaning.
- How: how you use it, often with a small command.
"Asked at" names a company only when a public interview story says the question was asked there. No tag means it is a common question that many companies ask.
Companies with the most questions in this lesson: Accenture (2), Wipro (1), Barclays (1), Oracle (1).
How: answer any question in 4 steps
- Start with the reason. One sentence.
- Give the plain meaning. No big words.
- Show one command or file.
- Add one example from your work. Then stop and wait.
Fresher questions
Q1. What is Ansible and what are its use cases?
Why: Config management is core DevOps.
What: Ansible is an agentless automation tool that uses SSH and YAML playbooks.
How: Use cases: install packages, configure servers, deploy apps, patching, user management.
Q2. What is an Ansible playbook?
Why: The main Ansible file.
What: A playbook is a YAML list of plays; each play runs tasks on a group of hosts.
How: Run it with ansible-playbook.
- hosts: web
become: true
tasks:
- name: install nginx
ansible.builtin.package: {name: nginx, state: present}
Q3. What is an Ansible inventory?
Why: Ansible needs to know which servers to touch.
What: An inventory lists hosts and groups (static file or dynamic from AWS).
How: Use group_vars for group settings.
[web]
10.0.1.10
10.0.1.11
Q4. What is idempotency in Ansible?
Why: Running twice should be safe.
What: Idempotent tasks change things only if needed.
How: Use modules (not shell) so re-runs show ok, not changed.
Q5. What are handlers?
Why: Restart only when config changes.
What: A handler runs when a task notifies it, once at the end.
How: Use for service restarts after config edits.
notify: restart nginx
handlers:
- name: restart nginx
service: {name: nginx, state: restarted}
Q6. What is the difference between ad-hoc commands and playbooks?
Why: Quick task vs repeatable task.
What: Ad-hoc commands run one module once from the CLI. Playbooks are saved, repeatable automation.
How: Use ad-hoc for checks, playbooks for changes.
ansible web -m ping
ansible web -m shell -a "uptime"
Q7. What is become in Ansible?
Why: Many tasks need root.
What: become runs tasks with sudo.
How: Set become: true at play or task level.
Experienced questions (2-5 years)
Q8. What are Ansible roles?
Why: Big playbooks become messy.
What: A role is a standard folder for tasks, handlers, templates, vars and defaults.
How: Create with ansible-galaxy init and reuse across playbooks.
ansible-galaxy init nginx
Q9. What is Ansible Vault?
Why: Passwords must not be in plain YAML.
What: Vault encrypts files or variables.
How: Encrypt secrets and pass the vault password from a safe store in CI.
ansible-vault encrypt group_vars/prod/secrets.yml
ansible-playbook site.yml --ask-vault-pass
Q10. Write a playbook to stop one of five data centres.
Why: A scenario asked in a real interview.
What: Group hosts by data centre in the inventory.
How: Target that group, drain traffic first, stop services in batches with serial, and confirm.
- hosts: dc3
serial: "20%"
become: true
tasks:
- service: {name: app, state: stopped}
Q11. What are Ansible facts?
Why: Playbooks often need host info.
What: Facts are details Ansible gathers (OS, IP, memory).
How: Use them in conditions and templates.
when: ansible_os_family == "Debian"
Q12. What are Jinja2 templates in Ansible?
Why: Config files differ per server.
What: A template is a file with variables filled at run time.
How: Use the template module.
- template: {src: nginx.conf.j2, dest: /etc/nginx/nginx.conf}
Q13. How does Ansible connect to Windows and Linux hosts?
Why: Mixed estates are common.
What: Linux uses SSH. Windows uses WinRM or SSH.
How: Set ansible_connection per group.
Q14. What is the difference between Ansible and Chef or Puppet?
Why: Tool choice.
What: Ansible is agentless and push-based with YAML. Chef/Puppet use agents and pull, with Ruby/DSL.
How: Ansible is simpler to start; Puppet/Chef suit long-running config enforcement.
Q15. How do you run an Ansible task only on some hosts or conditions?
Why: Control is needed in big runs.
What: Use when, tags, limit and serial.
How: --limit picks hosts, --tags picks tasks.
ansible-playbook site.yml --limit web1 --tags nginx
Q16. What is dynamic inventory?
Why: Cloud servers change often.
What: Dynamic inventory reads hosts from AWS or another source each run.
How: Use the amazon.aws.aws_ec2 plugin with tag filters.
plugin: amazon.aws.aws_ec2
filters:
tag:env: prod
Q17. How do you test Ansible roles?
Why: Untested automation breaks prod.
What: Use ansible-lint and Molecule.
How: Run --check (dry run) and --diff before real runs.
ansible-playbook site.yml --check --diff
Practice tasks
Easy What is an Ansible playbook?
Why: Saying it once with your own words makes it stick.
What to do: Answer this question as if the interviewer just asked it.
- Open a lab VM or container, never production.
- Run or write the example from the answer.
- Read the output line by line.
- Say the answer aloud in under 60 seconds.
Check: Your answer has a reason, a plain meaning and one command.
Easy What is an Ansible inventory?
Why: Saying it once with your own words makes it stick.
What to do: Answer this question as if the interviewer just asked it.
- Open a lab VM or container, never production.
- Run or write the example from the answer.
- Read the output line by line.
- Say the answer aloud in under 60 seconds.
Check: Your answer has a reason, a plain meaning and one command.
Medium What are Ansible roles?
Why: Saying it once with your own words makes it stick.
What to do: Answer this question as if the interviewer just asked it.
- Open a lab VM or container, never production.
- Run or write the example from the answer.
- Read the output line by line.
- Say the answer aloud in under 60 seconds.
Check: Your answer has a reason, a plain meaning and one command.
Medium What is Ansible Vault?
Why: Saying it once with your own words makes it stick.
What to do: Answer this question as if the interviewer just asked it.
- Open a lab VM or container, never production.
- Run or write the example from the answer.
- Read the output line by line.
- Say the answer aloud in under 60 seconds.
Check: Your answer has a reason, a plain meaning and one command.
Easy What are handlers?
Why: Saying it once with your own words makes it stick.
What to do: Answer this question as if the interviewer just asked it.
- Open a lab VM or container, never production.
- Run or write the example from the answer.
- Read the output line by line.
- Say the answer aloud in under 60 seconds.
Check: Your answer has a reason, a plain meaning and one command.
Medium Write a playbook to stop one of five data centres.
Why: Saying it once with your own words makes it stick.
What to do: Answer this question as if the interviewer just asked it.
- Open a lab VM or container, never production.
- Run or write the example from the answer.
- Read the output line by line.
- Say the answer aloud in under 60 seconds.
Check: Your answer has a reason, a plain meaning and one command.
Easy What is the difference between ad-hoc commands and playbooks?
Why: Saying it once with your own words makes it stick.
What to do: Answer this question as if the interviewer just asked it.
- Open a lab VM or container, never production.
- Run or write the example from the answer.
- Read the output line by line.
- Say the answer aloud in under 60 seconds.
Check: Your answer has a reason, a plain meaning and one command.
Medium What are Ansible facts?
Why: Saying it once with your own words makes it stick.
What to do: Answer this question as if the interviewer just asked it.
- Open a lab VM or container, never production.
- Run or write the example from the answer.
- Read the output line by line.
- Say the answer aloud in under 60 seconds.
Check: Your answer has a reason, a plain meaning and one command.
Homework: try at home
- Pick five questions you find hard.
- Write your own answer for each in three lines.
- Record yourself answering them. Listen once and improve.
Recap
In short
- Answer in order: why, what, how, then one example.
- Show one small command when you can.
- "Asked at" comes from public interview stories.
- Practise aloud; do not memorise word for word.
FAQ
Do I need to learn all 17 questions?
No. Start with the fresher ones. Then add the experienced ones for your level.
Should I memorise these answers?
No. Understand the why, then say it in your own words. Interviewers notice memorised lines.
What if I do not know an answer?
Say so honestly. Then explain how you would find out, step by step.
Are these questions only for one company?
No. "Asked at" shows where people said it was asked. Other companies ask the same things.
How long should an answer be?
About 30 to 60 seconds. Give a reason, a plain meaning and one example.
Is a lab really needed?
Yes. Running the command once makes your answer real and confident.
Interview questions
Practise these five first. Many companies asked them.
- What is Ansible and what are its use cases? - Ansible is an agentless automation tool that uses SSH and YAML playbooks.
- What is an Ansible playbook? - A playbook is a YAML list of plays; each play runs tasks on a group of hosts.
- What are Ansible roles? - A role is a standard folder for tasks, handlers, templates, vars and defaults.
- What is Ansible Vault? - Vault encrypts files or variables.
- Write a playbook to stop one of five data centres. - Group hosts by data centre in the inventory.
Quick quiz
Q1. What is Ansible and what are its use cases?
Ansible is an agentless automation tool that uses SSH and YAML playbooks.
Q2. What is the difference between ad-hoc commands and playbooks?
Ad-hoc commands run one module once from the CLI.
Q3. How do you test Ansible roles?
Use ansible-lint and Molecule.
Samajla ka?
Revision card
Interview card