Ravindra BagaleCourses & study guides मराठी

Chapter 91: Ansible Deep Dive

DevOps

91.16 Interview questions, revision and chapter quiz

Interview cards

Interview card: What is idempotence in Ansible?
Interview card: What is idempotence in Ansible?
Interview card: What is a handler and when does it run?
Interview card: What is a handler and when does it run?
Interview card: How do you keep secrets safe in Ansible?
Interview card: How do you keep secrets safe in Ansible?
Interview card: How do you roll out a change safely with Ansible?
Interview card: How do you roll out a change safely with Ansible?

Interview questions

  1. What is a control node and a managed node? — The control node runs Ansible; managed nodes are the servers it configures over SSH.
  2. Why is Ansible called agentless? — It needs no Ansible program running on managed nodes; it uses SSH and Python there.
  3. Ad-hoc vs playbook? — Ad-hoc runs one module once from the command line; a playbook is a saved YAML file of tasks.
  4. What is idempotence? — Running again changes nothing if the server is already correct; you see changed=0.
  5. What does become do? — Runs a task as another user, usually root through sudo.
  6. Which variable wins? — Extra vars with -e win over everything; role defaults are the weakest.
  7. What is a handler? — A task that runs only when notified by a change, once at the end of the play.
  8. Role vs collection? — A role is a folder of tasks, defaults, templates and handlers; a collection is a package of modules, roles and plugins.
  9. How do you protect secrets? — Ansible Vault for the value in Git, vault password outside Git, and no_log on tasks that could print it.
  10. How do you roll out safely? — serial batches, drain with delegate_to, max_fail_percentage, and --check --diff --limit first.

Revision checklist

Revision card: Ansible deep dive checklist
Revision card: Ansible deep dive checklist
  • [ ] I can write an inventory with groups and test a pattern with --list-hosts.
  • [ ] I use a normal SSH user and become only where needed.
  • [ ] I know when to use ad-hoc and when to write a playbook.
  • [ ] I can read ok, changed and the PLAY RECAP, and prove idempotence.
  • [ ] I can put variables in group_vars and read a fact.
  • [ ] I can write a template and a handler with matching names.
  • [ ] I can use loop, when and register.
  • [ ] I can split a playbook into a role and pin collections.
  • [ ] I can encrypt a value with Vault and run with the vault password.
  • [ ] I preview with --check --diff --limit and use tags.
  • [ ] I know serial, delegate_to and that run_once is per batch.
  • [ ] I can sort an error into its family and use -vvv and ansible-doc.

Quick quiz

Q1. What does the pattern lab:!db select?

All hosts in group lab except the hosts in group db.

Q2. A playbook's second run shows changed=0. What does that prove?

The tasks are idempotent: the servers were already in the described state.

Q3. Where should the become keyword go if only one task needs root?

On that one task, not on the whole play.

Q4. Which wins: a group_vars value or -e on the command line?

The -e extra var wins.

Q5. When does a handler run?

Only when a task that notifies it reports changed, once, at the end of the play.

Q6. What does register do?

Saves a task's result in a variable so later tasks can use it.

Q7. What does ansible-vault encrypt_string produce?

An encrypted !vault value you can safely commit in a vars file.

Q8. What does --check --diff --limit web1 do?

A dry run on web1 only that shows the line-by-line file changes.

Q9. In a play with serial: 1 and two hosts, how many times does a run_once task run?

Twice — once per batch.

Q10. Terraform or Ansible: which one installs Nginx on an existing server?

Ansible. Terraform creates the infrastructure.

Ravindra Bagale's Tip

In interviews, show the flow: inventory, playbook, idempotent run, check and diff, rolling release with serial. Then mention Vault for secrets.

In short

  • Ansible pushes config from one control node over SSH; no agent is needed.
  • Inventory and patterns pick hosts; become raises rights only where needed.
  • Good modules are idempotent: the second run shows changed=0.
  • Variables, facts, templates, handlers, loops, conditions and register make one playbook fit many servers.
  • Roles and collections keep work reusable; Vault keeps secrets encrypted in Git.
  • Preview with check and diff, roll out with serial, and fix errors by family.

Did you understand? Let us try it once more.