91.16 Interview questions, revision and chapter quiz
Interview cards
Interview questions
- What is a control node and a managed node? — The control node runs Ansible; managed nodes are the servers it configures over SSH.
- Why is Ansible called agentless? — It needs no Ansible program running on managed nodes; it uses SSH and Python there.
- Ad-hoc vs playbook? — Ad-hoc runs one module once from the command line; a playbook is a saved YAML file of tasks.
- What is idempotence? — Running again changes nothing if the server is already correct; you see
changed=0. - What does become do? — Runs a task as another user, usually root through sudo.
- Which variable wins? — Extra vars with
-ewin over everything; role defaults are the weakest. - What is a handler? — A task that runs only when notified by a change, once at the end of the play.
- Role vs collection? — A role is a folder of tasks, defaults, templates and handlers; a collection is a package of modules, roles and plugins.
- How do you protect secrets? — Ansible Vault for the value in Git, vault password outside Git, and
no_logon tasks that could print it. - How do you roll out safely? —
serialbatches, drain withdelegate_to,max_fail_percentage, and--check --diff --limitfirst.
Revision 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.
Interview मध्ये flow दाखवा: inventory, playbook, idempotent run, check आणि diff, serial ने rolling release. मग secrets साठी Vault सांगा.
Interview में flow दिखाओ: inventory, playbook, idempotent run, check और diff, serial से rolling release. फिर secrets के लिए Vault बताओ.
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.