Ansible Series

🎧 [Listen] The Ansible Series, Fully Recapped

This article is an audio-learning recap for anyone who’s already read all twenty-five articles in the Ansible series. Use your browser’s or phone’s text-to-speech feature and let it play in the background during a commute or while doing chores. There are no diagrams, tables, or code here — just spoken-style prose, stitching the whole series back together into a single, continuous thread.

The series started with Ansible’s most basic characteristic: being agentless. There’s no need to pre-install dedicated software on a managed server — all it needs is SSH and Python. That lightness is right at the core of why Ansible is so widely used. And idempotency — the property that running the same Playbook any number of times produces the same result — was the design philosophy holding this whole mechanism together.

Next came ansible-pull. Regular Ansible is a push model, where the control node actively connects to the target node over SSH, but in an environment like auto-scaling, where the control node’s side can’t know a target’s IP address ahead of time, that very premise breaks down. ansible-pull was an entirely reversed mechanism, where the target node itself fetches the Playbook from a git repository and runs it locally, addressed to localhost. And don’t forget: in exchange for not needing an inbound SSH connection, it carries trade-offs the push model doesn’t, when it comes to centralized visibility into execution results and safely distributing secrets.

Next came the hands-on of actually deploying configuration to multiple servers. One lesson learned there was a common real-world stumbling block: a single typo inside an inventory file gets silently ignored without even producing an error. From there, we went deeper into more production-grade configuration management with roles, Handlers, and templates — the Handler mechanism that only restarts a service when its config file actually changed, and using Jinja2 to feed different values into a template per environment.

Next came exactly when a Handler actually runs. notify isn’t a command that runs a handler the instant it’s called — it’s a command that registers a reservation: “run this later, all together.” By default, a notified handler is flushed all at once, right after each section of a play finishes: pre_tasks, roles/tasks, post_tasks. If you need execution settled immediately, mid-play, without waiting for the end of a section, you insert a task with meta: flush_handlers. And if a task fails partway through, the entire play stops and already-notified handlers never run either — so if you still want cleanup to happen even after a failure, that’s what the force_handlers setting is for.

Then came Ansible Vault, for never leaving a password in plaintext in Git. A design letting encrypted and unencrypted files coexist in the same directory, and a mechanism called vault-id that lets you use a different password per environment.

Next was AWS’s dynamic inventory: instead of a static inventory file with hardcoded IPs, querying the AWS API on every run to automatically fetch the list of instances actually running at that moment. Using a setting called keyed_groups, you could also automatically generate Ansible groups based on the value of a tag attached to an EC2 instance.

From here, things leaned more toward real-world scenarios. Using group_vars and —limit to safely run dev, staging, and prod — multiple environments — from a single Playbook. And stopping the reinvention of the wheel, using a battle-tested role and Collection from Ansible Galaxy, pinned to a version via requirements.yml.

Next, we went into finer-grained spec details: chaining Jinja2 filters together like a pipe, the fact that a registered variable is actually a structured dictionary, and the easily-overlooked spec that when is evaluated individually per loop item. We also covered the cost of facts gathering — a problem that becomes impossible to ignore as the number of target hosts grows — and reducing it with a JSON file cache.

The final two articles were about raising the quality of operations further. The first was designing structured exception handling with block, rescue, and always — automatically rolling back and guaranteeing cleanup when a configuration deployment fails partway through. The lesson was that merely ignoring a failure and continuing, like ignore_errors does, isn’t enough — you need to detect the failure, run recovery processing, and accurately report that fact. The second, an educational, defense-focused security hands-on, covered no_log’s effect and its limits, the path where a secret becomes visible via the target host’s process list, and the danger of shell injection created by embedding an untrusted value directly into the shell module.

Next came zero-downtime rolling updates with serial and delegate_to. A Playbook applies changes to nearly every host at almost the same time by default, so a change involving a service restart means every host goes down simultaneously, for an instant. serial limits how many hosts get processed and forces sequential execution, but that alone still isn’t enough — the host being processed keeps receiving traffic from the load balancer the whole time. Using delegate_to to delegate the removal and return requests to the load balancer itself, instead of the host being processed, is what finally achieves a practical, zero-downtime result. And don’t forget: the design philosophy you learned in the Load Balancing Department — “stop new inflow” and “wait for existing work to complete” — showed up here as a concrete implementation, through pre_tasks and post_tasks.

Next came tags and skip-tags. The tags keyword only labels a task — the actual selecting and excluding is handled by the —tags/—skip-tags options at execution time. There was a pitfall here. A tag on include_tasks (a dynamic include) only applies to the include task itself, never propagating to the individual tasks inside the file. With import_tasks (a static import), the tag correctly propagates all the way down to each individual task. When you feel “the tag isn’t working,” you first need to check whether the target task is loaded via include or import. And don’t forget: a task tagged always runs every time unless explicitly excluded with —skip-tags always, and the fact-gathering task itself carries this always tag internally, too.

Next came automated testing with Molecule. Molecule is a framework that spins up a disposable Docker container as a test environment, automating an idempotence test that runs the same playbook twice and fails if even one single task gets reported as changed on the second run. The three typical causes of an idempotence test failure were a command/shell task missing changed_when, a dynamic value in a template, and use of state: latest. And the verify stage uses Testinfra to confirm a service has actually started and reached its intended state — remember that a playbook running without an error, and reaching the intended state, were separate guarantees.

Next came async/poll. By default, an Ansible task holds its SSH connection open until processing finishes, but async specifies the maximum background execution time, and poll specifies the interval for checking completion. Only explicitly specifying poll: 0 genuinely achieves fire and forget — specifying async alone and omitting poll still has Ansible waiting at its default polling interval. And don’t forget: an async task always gets reported as changed, even when nothing actually changed, which collides directly with Molecule’s idempotence testing.

From here, the series moved into re-understanding Ansible’s own behavior at a deeper layer. First, ansible.cfg. Settings get loaded from one of four fixed locations, including the current directory, and then get overridden in this order: built-in defaults, ansible.cfg, environment variables, command-line arguments. When “only my environment behaves differently” shows up on a team, the fix is to suspect that somewhere in that precedence order, a personal environment variable is overriding the shared configuration.

Next came variable precedence. Role defaults, group_vars, host_vars, vars inside a Playbook, role vars, and -e — many places exist to define a variable, governed by the core principle that a narrower scope wins over a broader one, and a later-loaded value wins over an earlier one. In particular, -e is effectively the strongest override mechanism there is, and a CI/CD pipeline misconfiguration passing an unintended value through it can override every other setting without exception.

Then came Check Mode and Diff Mode, for confirming what will actually change before applying a real change to production. But there was an important caveat too — modules like command and shell never actually run during Check Mode, so they can’t be accurately simulated.

The execution-strategy discussion touched on how Ansible’s default, the linear strategy, carries a structural weakness: for any given Task, every host has to wait for the single slowest one to finish. The free strategy solves that weakness, but carries a different tradeoff in exchange — it’s not suited to a step requiring synchronization across hosts.

Next came error handling at an even finer grain than block, rescue, and always. ignore_errors merely lets processing continue on that host while still recording that the failure happened; failed_when lets you rewrite the judgment logic behind what even counts as a failure; and setting any_errors_fatal turns one host’s failure into an emergency stop switch, immediately halting every other host’s processing too.

Finally came the story of what happens once an organization grows large. Running ansible-playbook directly from an individual’s machine makes it increasingly hard to track who ran what, and to segment execution permissions. Ansible Tower, and its open-source counterpart AWX, solve that with role-based access control, centralized execution logging, scheduled execution, and Job Templates — creating a setup where the person running a job never has to directly handle an SSH key or a credential themselves.

And the twenty-second article wasn’t like the others — it never taught a single new technique. Instead, under the setup of a fictional startup, KoiKoi Tech, managing web servers across dev, staging, and prod beyond what manual work could sustain, you designed, yourself, a single integrated configuration management platform combining everything you’d learned separately up to that point: roles, Handlers, templates, Vault, AWS dynamic inventory, environment separation, Galaxy, error handling, and secrets protection. Following a fixed procedure and designing from requirements are genuinely different skills, and finishing every individual hands-on doesn’t make you immediately effective in real work without experience combining them into one coherent platform.

Looking back across all twenty-five articles, one consistent pattern emerges. Being agentless, a Handler’s true nature as notify being a “reservation” rather than “execute immediately,” automated testing with Molecule as a way to verify a playbook’s success and a role’s correctness as separate guarantees, async/poll’s poll: 0 as the only value that genuinely fires and forgets, the difference in tag propagation between tags/skip-tags and include/import, the push/pull inversion via ansible-pull, encrypting with Vault, dynamic inventory, exception handling with block/rescue, protecting information with no_log, zero-downtime design via serial and delegate_to, a seemingly unglamorous mechanism like ansible.cfg or variable precedence, and the whole configuration management platform integrated in the capstone — every one of them was a different, concrete implementation of the same idea: build in, ahead of time, the assumption that the target will change and that failure is always possible. Will this Playbook keep running genuinely safely as the target count grows, as failures happen, as it handles secrets? Asking yourself that question, over and over, is the perspective a top-1% engineer carries away from this series. And that’s the recap of the Ansible series, complete.

Comments

Feel free to leave thoughts, questions, or corrections below (sign in with a GitHub account to comment or react).