Portal | Level: L1: Foundations | Topics: Ansible | Domain: DevOps & Tooling
Ansible - Skill Check¶
Mental model (bottom-up)¶
Ansible is: controller connects over SSH/WinRM, transfers a module, runs it, and returns structured results. Idempotency comes from modules knowing state, not from "shell scripts".
Visual guide¶
Glossary¶
- inventory - targets: hosts and groups
- playbook - ordered set of plays/tasks
- module - unit of work (package, service, file, etc)
- idempotent - re-run yields same end state without repeated changes
- handler - delayed action triggered only when notified
- facts - discovered host data used for conditionals
- role - packaged reusable tasks/templates/vars/handlers
Common failure modes¶
- Using
shelleverywhere -> non-idempotent snowflakes. - Variable precedence confusion -> "why is my value ignored?"
- Secrets leak via debug output.
Roadmap core (10, easy -> hard)¶
- What is Ansible (one line)?
- Agentless automation over SSH using YAML playbooks.
- Inventory: what is it?
- The list/grouping of hosts (static or dynamic) Ansible targets.
- Play vs task vs role?
- Play targets hosts; tasks are steps; roles package reusable content.
- Idempotency meaning in Ansible?
- Re-running yields same end state without repeated changes.
- Variables precedence: why it matters?
- Same var defined multiple places; precedence controls which wins.
- Handlers: what are they for?
- Run actions (like restart) only when notified by changed tasks.
- Templates vs files?
- Templates (Jinja2) render variables; files copy as-is.
- Facts +
gather_facts: what does it do? - Collect host info for conditional logic.
- Vault: what problem does it solve?
- Encrypt secrets in repo; control access.
- Collections + modules: how to stay sane?
- Pin versions; prefer modules over shell; avoid snowflake hacks.
Inventory & targeting (easy -> hard)¶
- How do groups help?
- Target sets of hosts; apply vars/roles cleanly.
- What is
--limit? - Narrow run to specific hosts/groups.
- Static vs dynamic inventory?
- Static file vs generated from cloud APIs/CMDB.
- Why tags are useful?
- Run subsets of tasks safely:
--tags,--skip-tags. - How do you avoid "blast radius"?
- Limit + serial + check mode + good defaults.
Variables, templating, and structure (easy -> hard)¶
- Why use roles?
- Reuse and standardize with a known structure.
include_rolevsimport_role?- Include is dynamic; import is static (affects load/vars).
- When to use
defaultsvsvars? - Defaults are override-friendly; vars are higher precedence.
- Jinja2 pitfall #1?
- Forgetting quotes / type coercion; test rendering.
- How to validate inputs?
- Use role argument validation + asserts.
Idempotency and "don't shell out" (easy -> hard)¶
- Why avoid
shell/commandwhen modules exist? - Modules are idempotent and parse state; shell is fragile.
- How do you detect "changed" correctly?
- Let modules decide; else use
changed_whencarefully. - When do handlers run?
- End of play by default, after notifications; can
meta: flush_handlers. - How to do safe restarts?
- Notify handler only on config change; avoid restart storms.
- What's a common idempotency bug?
- Appending lines repeatedly; use
lineinfile/templates instead.
Secrets (easy -> hard)¶
- What does Ansible Vault encrypt?
- Vars files/strings; content at rest in git.
- Vault operational risk?
- Key management; sharing; rotation; CI handling.
- What's the "right" secret source in enterprise?
- External secret store (Vault/Secrets Manager) + dynamic creds when possible.
- How to prevent secret leaks?
no_log: true, avoid debug dumps, keep secrets out of CLI args.
Debugging & reliability (easy -> hard)¶
- First triage flags?
-vvv,--check,--diff,--step.- How to debug vars?
debug: var=...(watch for secrets).- How to make runs stable under flaky SSH?
- Control forks, retries, timeouts; fix SSH known_hosts policy.
- What's a sane "test before prod" workflow?
- Run in lab/stage inventory; then prod with
serialand health checks.
Sources¶
- Ansible community documentation (playbooks, roles, handlers, vault).
- https://docs.ansible.com/
Wiki Navigation¶
Related Content¶
- Ansible Automation (Topic Pack, L1) — Ansible
- Ansible Core Flashcards (CLI) (flashcard_deck, L1) — Ansible
- Ansible Deep Dive (Topic Pack, L2) — Ansible
- Ansible Drills (Drill, L1) — Ansible
- Ansible Exercises (Quest Ladder) (CLI) (Exercise Set, L1) — Ansible
- Ansible Lab: Conditionals and Loops (Lab, L1) — Ansible
- Ansible Lab: Facts and Variables (Lab, L0) — Ansible
- Ansible Lab: Install Nginx (Idempotency) (Lab, L1) — Ansible
- Ansible Lab: Ping and Debug (Lab, L0) — Ansible
- Ansible Lab: Roles (Lab, L1) — Ansible
Pages that link here¶
- Ansible Automation
- Ansible Deep Dive
- Ansible Deep Dive - Primer
- Ansible Drills
- Ansible for Infrastructure Automation - Primer
- DevOps Tooling Domain
- Fleet Operations at Scale
- RHCE (EX294) Exam Preparation
- Symptoms: Ansible Playbook Hangs, SSH Agent Forwarding Broken, Root Cause Is Firewall Rule
- Symptoms: Node NotReady, NIC Firmware Bug, Fix Is Ansible Playbook
- Track: Infrastructure & Data Center Operations