Key Takeaways
Turn server setup into versioned instructions, not a memory test
Capture the real work. The book begins with a familiar failure: a Django application works on a laptop, but deploying it means installing packages, editing web-server settings, and repeating the same steps months later on another machine. Configuration management records those steps as executable instructions, so the deployment process itself becomes a maintained artifact rather than scattered notes and recollection.
Ansible keeps the machinery light. It connects from a control machine to remote Linux or Unix-like hosts over SSH, pushes tasks when an operator runs a playbook, and does not require an Ansible agent on each host. Its YAML instructions use built-in modules for common work such as installing packages, copying files, and managing services. The approach is useful for one test server as well as larger fleets.
What's striking is the shift from remembering a procedure to maintaining a system that can perform it. That is a form of institutional memory: a new operator can inspect the same instructions that configure the machine. The design also keeps the control plane small, which lowers adoption costs. But a runnable procedure is more consequential than a README. A mistake in a checked-in instruction can be repeated consistently, so review, version history, and access control become part of operational safety.
Prefer modules that describe the target state over commands that merely run
Reruns should be ordinary. Ansible modules are designed to describe outcomes. A user module can ensure an account exists, while apt can ensure a package is installed. If the host already matches the request, the module reports no change; if it does not, the module corrects it. This property is called idempotence: repeating the operation produces the same intended result as performing it once.
Commands need guardrails. A raw command may report a change every time, or cause damage on a second run. The book recommends using native modules where possible and adding conditions such as a file-exists check when a command must be used. For commands with unreliable status reporting, `changed when` and `failed when` let the playbook define what counts as a real change or failure.
Idempotence makes automation recoverable. A rerun after a partial failure can reconcile the machine instead of requiring an operator to reconstruct exactly which steps happened. This resembles retry-safe operations in distributed systems, where networks and processes fail at inconvenient moments. The important limitation is that idempotence is not guaranteed by writing YAML: it depends on module behavior and on accurate descriptions of state. A command wrapped in a task remains a command unless its effects are explicitly bounded.
Model the fleet with groups, environments, and facts, not a flat host list
Inventory is the map. An Ansible inventory names the hosts it can manage and organizes them into groups. A Django service might group machines by environment, such as production and staging, and by function, such as web, database, and task queue. A host can belong to several groups, allowing a playbook to target either a whole environment or a particular service tier.
Keep changing facts out of static lists. Variables can live with a host or group, in separate YAML files, while facts describe information discovered on a machine, including its operating system and network interfaces. Dynamic inventory obtains host data from an external source instead of maintaining a second, potentially stale list. For EC2, the book shows groups formed from tags, so labels such as environment and service type can drive targeting.
Inventory is more than a directory of machines. It is a compact model of how a service is organized, and that model determines which changes can be applied safely and selectively. Separating environment from function is especially valuable because those dimensions often change independently. Dynamic inventory reduces duplication, but it also makes the external source of truth operationally important. When group membership comes from tags or cloud data, careless labels can silently widen the scope of a deployment.
Write playbooks as readable runbooks that execute in a deliberate order
A playbook connects hosts to work. It contains one or more plays. Each play selects hosts and lists ordered tasks, and each task invokes a module with arguments. Ansible runs a task across the selected hosts in parallel, waits for that task to finish on those hosts, and then proceeds to the next task. YAML makes this sequence relatively easy to read, while task names explain intent and improve troubleshooting.
Templates centralize configuration. A template combines a text file with variables, allowing one source to generate host-specific configuration, such as an nginx file containing certificate paths or a site name. A handler is a task that runs only when a notifying task reports a change. Handlers are useful for restarting a service after its configuration changes, and run once after the play's ordinary tasks, even if several tasks notify them.
The playbook's sequence acts like an explicit operational contract: operators can see both what should happen and in what order. Parallelism across hosts speeds routine work, while the task boundary creates a synchronization point before dependent work begins. Templates also reduce configuration drift by deriving related files from shared variables. Still, readability depends on restraint. A long playbook with hidden variable precedence or indirect control flow can become harder to reason about than the manual procedure it replaced.
Treat production deployment as a chain of services, not a single app install
The Mezzanine example exposes the dependencies. In development, the Django-based content-management application can use SQLite and a built-in web server. Production requires more: PostgreSQL for the database, Gunicorn to run the application, nginx to serve static files and proxy requests, and Supervisor to manage the application process. TLS certificates, system packages, Python libraries, permissions, and configuration files also have to line up.
Ansible makes the chain repeatable. The worked deployment installs operating-system packages, checks out application code from Git, creates a Python virtual environment, installs dependencies, creates a database and user, renders settings from templates, runs database setup commands, and configures services. The example also separates secret credentials from ordinary settings. It illustrates why deployment automation must describe the whole running system, not just copy application code.
This example teaches an architectural lesson through practical friction: production behavior emerges from several components whose boundaries matter. The application can be correct while its database credentials, proxy headers, process manager, or static-file paths are wrong. Modeling the deployment forces those dependencies into view. The scope is deliberately concrete, but the same pattern applies only when the surrounding services are understood; automation cannot infer a correct production architecture from the application source alone.
Break growing playbooks into roles with clear responsibilities
Roles package related work. A role groups tasks with any associated handlers, files, templates, variables, defaults, and dependencies. The book separates the Mezzanine deployment into database and application roles. A play then assigns each role to the appropriate hosts, making it easier to deploy the database and web service on separate machines without duplicating their instructions.
Keep reuse practical. Role defaults provide values that a playbook can override, while role variables are intended for values that should be harder to replace. Role dependencies can ensure prerequisite roles run first, and Ansible Galaxy offers a repository of community-contributed roles. The author cautions against assuming generic roles will fit every organization: they are useful building blocks and examples, but local infrastructure often requires locally maintained configuration.
Roles resemble modular design in software: they make a large operational task easier to inspect, test, and assign to a service boundary. The strongest benefit is not abstract reuse, but the ability to change one responsibility without editing an undifferentiated script. Shared roles also create a governance question. A role imported from a community repository may encode assumptions about operating systems, security, or filesystem layout, so reuse should mean review and adaptation, not blind adoption.
Limit rollout risk with serial execution, delegation, and explicit failure rules
Choose where and how tasks run. Ansible can run a task on the control machine, delegate it to another host, execute it only once, or process hosts in batches. For a rolling upgrade behind a load balancer, the `serial` setting can limit work to one server at a time. The play can remove that server from traffic, update it, and return it to service before proceeding. `max fail percentage` can stop the rollout when failures exceed a chosen threshold.
Protect sensitive values. The book also covers Ansible Vault, which encrypts files containing items such as database passwords and API credentials. A playbook can read an encrypted file just as it reads a regular variable file, provided the operator supplies its password. These controls do not make a deployment safe by themselves, but they let operators constrain its scope and reduce exposure of secrets.
This is where automation becomes a control system rather than a batch script. Serial execution limits simultaneous disruption, delegation lets a deployment coordinate with systems such as a load balancer, and failure thresholds define when the process should stop. These mechanisms make risk visible and configurable. They still rely on a sound recovery plan: taking servers out of rotation one by one is not protection if the health check is misleading or the rollback procedure is absent.
Speed up repeated SSH work, but preserve visibility into what changed
Reduce connection overhead. Ansible uses SSH to communicate with hosts. OpenSSH multiplexing allows several sessions to share a TCP connection, avoiding repeated connection setup. Pipelining can reduce the number of SSH sessions needed for a task, though the remote sudo configuration may need adjustment. Fact caching avoids repeatedly gathering host information, and the `forks` setting controls how many hosts Ansible handles in parallel.
Debug before guessing. The book recommends verbose output for SSH failures, the debug module for inspecting variables, and the assert module for checking assumptions. Syntax checks, host and task listings, check mode, and diffs can help inspect a playbook before applying it. Check mode is useful but imperfect: a task may fail in a dry run because an earlier task would have installed a prerequisite that is not actually present.
Performance settings and diagnostic tools solve different problems. Multiplexing and pipelining reduce repeated transport costs, while assertions and diffs improve the operator's understanding of the change. Treating them as one concern can be dangerous: faster execution is not automatically safer execution. Caching also introduces a freshness trade-off, since a cached operating-system fact ages differently from a changing network address. The practical standard is not maximum speed, but a deployment whose runtime and consequences remain legible.
Let cloud metadata drive inventory, and make instance creation idempotent
Cloud hosts are moving targets. The EC2 dynamic inventory script retrieves instances and their attributes directly from Amazon, then groups them by properties such as region, instance type, security group, and tags. Tags can express an organization's own categories, such as production web servers. This avoids maintaining a separate static host list that drifts as instances are added or removed.
Provisioning needs a desired count. A basic EC2 task can launch an instance, but rerunning it may launch another one. The book uses `exact count` with `count tag` to ensure a specified number of matching instances exists. It also shows creating keys and security groups, waiting for instances and SSH to become ready, and adding newly created hosts to the play's inventory. Credentials can be supplied through environment variables or instance IAM roles.
Cloud automation combines two kinds of state: the infrastructure provider's record of resources and the configuration tool's view of those resources. Dynamic inventory connects the views, while tags provide a shared vocabulary. Idempotent counts are especially important because a retry should not unexpectedly multiply costs. The design is only as reliable as its identity rules: a count based on a broad tag can select the wrong instances, so tags must be deliberate and consistently maintained.
Use Ansible to coordinate containers, while keeping image building in the build pipeline
Docker separates services into containers. The book's Mezzanine example places PostgreSQL, Memcached, the Django application, nginx, and TLS certificates in separate images or containers. The deployment playbook starts them in dependency order, passes configuration through environment variables, waits for the database to accept connections, links containers that need to communicate, and shares static files through a mounted volume.
Images and running systems are different jobs. Ansible can configure an image by running a playbook inside a base image, and its Docker module can coordinate containers. The book argues that image creation and publication fit naturally into an application build process, while Ansible is especially useful for deployment and orchestration. For custom behavior, a script may suffice; a full module is appropriate when no built-in module expresses the task cleanly.
The container example clarifies an important distinction: packaging a service and coordinating live services are related but separate responsibilities. Environment variables keep deployment-specific settings out of a reusable image, while container links and shared volumes make dependencies explicit. The approach also makes startup ordering visible, which is valuable when services are not instantly ready. Container tooling was changing rapidly when the book was written, so its particular module limitations should be read as historical implementation details, not timeless Docker guidance.
Write custom modules only when built-in state management cannot express the job
Start with the smallest suitable tool. Ansible includes modules for common operations, and the book shows a short script as a simpler alternative when a one-off task needs custom logic. A custom module becomes worthwhile when the task is complex, needs meaningful failure handling, or should behave like a reusable Ansible operation. Its result should tell Ansible whether state changed, whether the task failed, and why.
Make the module a good citizen. Python modules can use Ansible's helper class to parse arguments, run external commands, and return structured results. The author recommends supporting check mode, documenting arguments, and testing the module directly. A module that says it changed nothing when it altered the host, or reports success after a failed operation, undermines the clarity that makes Ansible useful.
A custom module is an interface commitment, not merely a convenient script. Once other playbooks depend on it, argument validation, predictable output, and check-mode behavior become part of its contract. That investment is justified when the operation recurs or needs reliable semantics; for a single narrow action, a script can be more economical. The distinction mirrors a broader engineering principle: abstraction earns its keep when it reduces repeated complexity without hiding consequential behavior.
Analysis
This is a practical tutorial, not a general theory of operations. Its narrative moves from the author's experience repeating a hand-built Django deployment to a full Mezzanine rollout, then widens outward to roles, performance, cloud provisioning, containers, and custom modules. The ordering matters: readers first learn the smallest useful unit, a task invoking a module, before confronting fleet models and service dependencies. Its central contribution is a way to make operational knowledge both executable and inspectable.
The book's most durable ideas are architectural. Keep the control plane thin, express desired state through modules, organize hosts by meaningful groups, and decompose complex deployments into roles. The Mezzanine case makes those ideas concrete by showing why production requires more than an application server: a database, reverse proxy, process management, static files, credentials, and TLS must work together. The examples also demonstrate that configuration management is a form of systems modeling. A playbook makes assumptions about dependencies, ownership, and readiness explicit, or reveals that they were never understood.
The important caveat is age. The book was tested with Ansible 1.8.4 and its examples use Python 2, historical module names, and syntax that has since changed. Its conceptual lessons remain valuable, but example files should not be copied directly into a current environment without checking present-day Ansible documentation and module behavior. The Docker tooling section itself acknowledges rapid change, and cloud APIs evolve as well. Security guidance also deserves careful application: disabling host-key checks is convenient for disposable test machines, but risky for production connections.
A strong way to use the book today is as a mental model and a debugging guide, not a version-current reference. The core operational question remains: can the intended state be described clearly, applied repeatedly, scoped to the right hosts, and inspected before and after execution? Ansible is most valuable when the answer is yes.
Review Summary
Ansible: Up and Running receives generally positive reviews, praised for its comprehensive coverage of Ansible basics and practical examples. Readers appreciate its tutorials on integrating Ansible with AWS, Docker, and Vagrant. The book is recommended for beginners and experienced users alike, offering valuable insights and tips. Some criticisms include outdated content and occasional dry sections. Many reviewers consider it an essential resource for learning Ansible, with clear explanations and useful code samples. Overall, it's viewed as a solid introduction to Ansible automation.
Glossary
Playbook
Ordered host instructionsA YAML file containing one or more plays. Each play selects a set of hosts and specifies ordered tasks to perform on them. Tasks invoke Ansible modules with arguments, and may also use variables, handlers, and other controls. A playbook is both an operational description and executable automation.
Inventory
Hosts and their groupsThe set of hosts Ansible knows how to manage, organized into groups and optionally associated with variables. An inventory can be a static file, a collection of files, or a dynamic source that retrieves host information from another system. Plays use inventory names and patterns to select their targets.
Idempotent
Safe to repeatAn operation is idempotent when running it multiple times has the same intended effect as running it once. Ansible modules commonly check whether a host already matches the requested state and avoid unnecessary changes. This makes reruns safer, although raw commands and poorly designed tasks may need extra conditions to behave idempotently.
Facts
Discovered host informationFacts are variables containing information gathered about a host, such as its operating system, network interfaces, architecture, and memory. Ansible normally gathers them at the start of a play, and playbooks can use them to make configuration decisions. Modules can also return facts, which Ansible makes available as variables.
Handler
Change-triggered taskA handler resembles a task but runs only when another task notifies it after reporting a change. Handlers typically perform actions such as restarting a service after its configuration changes. They run after the ordinary tasks in a play and run only once even when multiple tasks notify the same handler.
Role
Reusable task bundleA role organizes related tasks and supporting files, templates, handlers, variables, defaults, and dependencies under a named directory structure. Plays assign roles to hosts. Roles help separate responsibilities, such as database setup from web-application deployment, and can be shared or downloaded through Ansible Galaxy.
Dynamic inventory
Live host discoveryA source, commonly an executable script in the book's Ansible version, that supplies hosts, groups, and host variables when Ansible runs. It can query an external system such as a cloud provider, reducing duplication between that system's host records and a manually maintained inventory. Its output may be cached.
Vault
Encrypted variable filesAn Ansible mechanism for encrypting files that contain sensitive data, such as passwords or tokens. Playbooks can load encrypted files as variable sources, while the operator supplies a vault password at execution time or through a configured password source. It allows encrypted secrets to be stored alongside automation more safely than plaintext.
Check mode
Change-free previewA mode for running a playbook that reports whether tasks would change hosts without applying those changes. Modules must support this behavior, and results are not always complete because later tasks may depend on earlier changes that were not actually made. It is useful for review, but should not be treated as a perfect simulation.
SSH multiplexing
Shared SSH connectionAn OpenSSH feature that lets multiple SSH sessions to the same host reuse a master TCP connection. Ansible uses it to reduce the overhead of repeatedly establishing connections while running tasks. The connection remains available for a configured period, and a control socket provides the local mechanism for reusing it.
Download PDF
Download EPUB
.epub digital book format is ideal for reading ebooks on phones, tablets, and e-readers.