DEV Community

Kim Jarvis
Kim Jarvis

Posted on Originally published at reemote.hashnode.dev

An alternative to Ansible for configuration management

For nearly a decade, Ansible has been the default answer to almost every automation problem in infrastructure. Need to configure servers? Use Ansible. Deploy applications? Use Ansible. Provision cloud resources? Wrap it in Ansible. Orchestrate workflows? Ansible again. As one recent critique put it, Ansible became the Swiss Army knife of DevOps — and the question worth asking now is whether teams are still using it because it is the best tool for the job, or because it is the most familiar.

That critique is not unfair. What it leaves unanswered is the harder half: if not Ansible, then what — and how do you get there without throwing away a decade of playbooks and role knowledge? Reemote is a Python configuration-management library aimed squarely at that gap, similar enough to Ansible that existing roles migrate instead of being rewritten. Before any of that is argued, the claim is cheap to test: the example below runs a real deploy against two throwaway containers on your own machine.

Try it in under a minute (docker connector)

Reemote ships a docker connector that runs your deploy inside a local container, so this needs no remote host, no SSH key and no agent. Docker or Podman must be installed locally — the connector shells out to whichever CLI you name in the inventory, and there is no default. The script declares two hosts, demo0 and demo1, and yields two operations, because lockstep needs both: a second host to have anyone to wait for, and a second operation to see the waiting happen. The first run previews the deploy without changing anything on either host, which is what Ansible calls check mode; the second applies it, one operation at a time across both hosts, which is what Ansible calls lockstep execution. Two steps:

# 1. Install (Python 3.13+; pip works just as well as uv)
uv venv .venv && source .venv/bin/activate && uv pip install reemote

# 2. Save the script below as hello.py, then run it
python hello.py
Enter fullscreen mode Exit fullscreen mode
# hello.py
import asyncio

from reemote import files, format_log, format_plan, op, run

INVENTORY = [
    {
        "host": "demo0",
        "family": "Alpine",
        "connection": {
            "connector": "docker",
            "identifier": "alpine:3.20",
            "docker_cmd": "podman",   # or "docker"
        },
    },
    {
        "host": "demo1",
        "family": "Alpine",
        "connection": {
            "connector": "docker",
            "identifier": "alpine:3.20",
            "docker_cmd": "podman",
        },
    },
]


def deploy(host):
    yield op(files.install,
             name="Write a greeting",
             content="Hello from reemote!\n",
             dest="/tmp/reemote-hello.txt",
             mode="0644")
    yield op(files.install,
             name="Record the host name",
             content=f"written on {host.name}\n",
             dest="/tmp/reemote-host.txt",
             mode="0644")


async def main():
    # Dry run: facts are gathered for real, nothing is mutated.
    plans, _, _ = await run(INVENTORY, deploy, dry=True)
    print("== Dry run: what would change ==")
    print(format_plan(plans))

    # Apply: the same deploy, executed against a fresh container per host.
    _, report, _ = await run(INVENTORY, deploy)
    print("\n== Applied: what changed ==")
    assert report is not None
    print(format_log(report))


asyncio.run(main())
Enter fullscreen mode Exit fullscreen mode

Verified output, produced by running exactly this script against Podman:

== Dry run: what would change ==
demo0: Write a greeting         [changed: content /tmp/reemote-hello.txt is absent, will install]
demo0: Record the host name     [changed: content /tmp/reemote-host.txt is absent, will install]
demo1: Write a greeting         [changed: content /tmp/reemote-hello.txt is absent, will install]
demo1: Record the host name     [changed: content /tmp/reemote-host.txt is absent, will install]

== Applied: what changed ==
demo0: Write a greeting         [changed: content /tmp/reemote-hello.txt is absent, will install]
    $ scp <files install> -> /tmp/reemote-install-2e52d4f8373a608a/content
    $ sh -c 'mkdir -p /tmp && cp /tmp/reemote-install-2e52d4f8373a608a/content /tmp/reemote-hello.txt && chmod 644 /tmp/reemote-hello.txt && rm -rf /tmp/reemote-install-2e52d4f8373a608a'
demo1: Write a greeting         [changed: content /tmp/reemote-hello.txt is absent, will install]
    $ scp <files install> -> /tmp/reemote-install-2e52d4f8373a608a/content
    $ sh -c 'mkdir -p /tmp && cp /tmp/reemote-install-2e52d4f8373a608a/content /tmp/reemote-hello.txt && chmod 644 /tmp/reemote-hello.txt && rm -rf /tmp/reemote-install-2e52d4f8373a608a'
demo0: Record the host name     [changed: content /tmp/reemote-host.txt is absent, will install]
    $ scp <files install> -> /tmp/reemote-install-8c7265455d37e471/content
    $ sh -c 'mkdir -p /tmp && cp /tmp/reemote-install-8c7265455d37e471/content /tmp/reemote-host.txt && chmod 644 /tmp/reemote-host.txt && rm -rf /tmp/reemote-install-8c7265455d37e471'
demo1: Record the host name     [changed: content /tmp/reemote-host.txt is absent, will install]
    $ scp <files install> -> /tmp/reemote-install-8c7265455d37e471/content
    $ sh -c 'mkdir -p /tmp && cp /tmp/reemote-install-8c7265455d37e471/content /tmp/reemote-host.txt && chmod 644 /tmp/reemote-host.txt && rm -rf /tmp/reemote-install-8c7265455d37e471'
Enter fullscreen mode Exit fullscreen mode

Nothing was set up for this demo beyond having Podman installed and alpine:3.20 available: no agent to deploy, no inventory file to write, no host to provision. The inventory is a plain Python list of host dictionaries, the deploy is a plain function that yields operations, and both runs print what they intend to do before and while they do it. Hold that picture; why those particular lines come out in that order is the payoff this article builds toward.

Where Ansible strains

Two file writes across two containers is the easy case, and Ansible handles the easy case well — that is why it won. The trouble starts where the job stops being easy, and a Swiss Army knife stays convenient because nobody asks what it is bad at. The practitioners who pushed Ansible past its comfort zone did ask, and their answers cluster into five pressure points.

Debugging. Ansible's playbook debugger triggers on task failure and lets you print and set variables, but the internal operation of its modules is not visible. One of those practitioners, Terry Slattery, spent several hours diagnosing a playbook that would not work before discovering that his DNS server had been misconfigured the whole time — a cause entirely outside the playbook. When a task fails and the tool cannot show you why inside the module, you are left guessing.

Performance. Ansible serializes and deserializes JSON data internally between tasks, which consumes a lot of CPU once large volumes of data are in play. It also executes over SSH and processes tasks sequentially per host, so on hundreds or thousands of nodes teams tune fork counts, disable fact gathering and restructure playbooks to buy speed — optimizing the automation tool instead of delivering value.

Complex data structures. Slattery's first attempt at building a network discovery system in Ansible stalled on data. Discovery needs a table of discovered devices, a table of newly discovered devices to check, each device's neighbors, and then the neighbors of those neighbors; maintaining a connectivity drawing needs the same relationships reshaped into a Graphviz DOT file. Listing CDP neighbors is easy. Holding and correlating the structures that turn that list into a graph is where the format runs out.

Control flow. Ansible offers loops and conditionals, but loops inside loops, heavy branching and the Jinja2 filters feeding them make the resulting playbook hard to follow. Readability falls as complexity grows, and a complex playbook that has been in production for six months asks whoever revises it to remember every trick that made it work.

Composition and testing. Roles include other roles by name, and variables flow through precedence rules that have to be remembered rather than read. A playbook cannot be imported and exercised the way a library module can, which is why a second toolchain — Molecule, testinfra, ansible-lint — exists around it.

One decision behind all of it

Five pressure points, one root cause. Ansible looks declarative but is fundamentally procedural: you are scripting a sequence of changes and hoping they converge cleanly, and the configuration itself is written in a data-serialization format with a templating dialect bolted on rather than in a programming language. As playbooks grow, logic creeps in — conditionals multiply, variables override other variables in confusing precedence chains — and what started as clean YAML becomes fragile orchestration code hidden inside configuration files. When automation needs loops inside loops and templating hacks, you are no longer describing configuration; you are writing software in a format never meant to support serious software engineering practices like strong typing, modular design or proper testing.

Each pressure point then has an ordinary answer in Python:

  • Complex logic is just code. if, comprehensions, functions, written next to the deploy and reviewable on their own terms — instead of nested {% set %} blocks and chains of regex_search, ternary and default filters that the next person cannot read.
  • Data structures are just data. Dicts, sets and graphs you build, pass around and test directly, rather than coaxed out of a templating engine.
  • Control flow is real control flow, and your editor knows it. Go-to-definition, rename across usages, a type checker, a linter, completion — so a misspelled module argument fails before the deploy runs, not on the target.
  • Composition is import and arguments. A reusable block of configuration is a function you call with named arguments from another file, not a directory-layout convention with precedence rules attached.
  • Testing is pytest. A Reemote deploy is a generator, so a test asserts on the requests it yields; the shipped role tests replay a whole role twice against a simulated host, with no server involved.
  • The result is objects, not terminal output. A deploy returns the plan and the report — changed flags, reasons, the exact commands sent — that you can assert on, log to a database, or gate a rollout on.

None of that is an argument about whether Ansible works. It does, at scale, for years. It is an argument about the ceiling on how far the format can be pushed — and every item above is a solved problem in the language most automation teams already use.

What Ansible earns its adoption for

Raising that ceiling is only worth doing if the replacement keeps what Ansible actually earned. Ansible is easy to learn: playbooks are a sequence of tasks in YAML, and anyone who has had to learn a device command-line interface picks the syntax up quickly. It is agentless. Its module library covers package management, files, services and templated configuration files well, and Red Hat's backing made it enterprise-safe early. Two properties of its execution model matter most — the two the opening demo was built to show:

Check mode. Ansible simulates execution without actually making any changes, so you can validate a configuration before deploying it.

Lockstep execution. Ansible runs the same task on all target hosts and only proceeds to the next one after every host has finished the current one.

An alternative that discards those two is not an alternative for configuration management. Reemote implements both. Check mode is the dry-run flag:

plans, report, hosts = await run(inventory, deploy, dry=True)
Enter fullscreen mode Exit fullscreen mode

You get back a plan — the operations that would change something, per host, with the reason each one is marked changed — and no change is made on any host: the state is read for real, the writes are not. Lockstep is not a mode you switch on; it is how the runner works: operations are dispatched to every host in the inventory concurrently, and the controller waits for all of them to finish an operation before advancing to the next. The hello.py output at the start of this article prints exactly that ordering. The agentless transport carries over too — for SSH targets, the supported options in a host's connection block are forwarded verbatim to asyncssh's connect(), under asyncssh's own names — and since Reemote is a library on asyncio rather than a CLI that marshals JSON between tasks, that concurrency is the design rather than a knob to tune.

Reading the example again

The dry run in that opening example is check mode with evidence: four planned changes, two per host, each carrying the reason it is marked changed. Read an operation's plan line against its line in the apply log and they are the same line — the plan the preview showed is the plan the apply executed, verbatim, with the shell commands appended.

The apply log is also where lockstep becomes visible. The dry-run plan is host-major — both of demo0's operations, then both of demo1's — because a plan is one deploy read per host. The log is step-major: Write a greeting on demo0 and demo1, then Record the host name on demo0 and demo1. Neither host was handed its second operation until both had finished the first, which is the barrier behind "the controller waits for all of them to finish an operation before advancing to the next" above. And demo0 before demo1 inside a step is not sequencing either: the two containers ran each step at the same time, and the results are simply collected in inventory order.

One detail worth noticing. The second operation writes different bytes to each host because host.name is an ordinary Python value in an f-string — no templating dialect, no hostvar to look up — yet its two $ scp lines are identical, because the spool path is derived from the destination rather than the payload. Same path on both hosts, different content behind it.

Each run(...) starts its own throwaway container per host from alpine:3.20, so the dry run and the apply both observe the same absent files; the demo shows the two phases and the lockstep barrier, not idempotence.

That closes the loop on the debugging complaint from earlier: a Reemote deploy is importable, the state it reads comes back as facts you can print, and the exact commands are visible in the plan before any of them touch a host.

What migrating actually costs

Matching check mode and lockstep is the cheap half of an alternative. The expensive half is what the critique waves through: getting from here to there. Puppet, Salt and Chef are structurally different from Ansible, which is why nobody ports an Ansible playbook to Puppet — they rewrite it against a different model of the world. "Deliberately choose better-suited tools" is sound advice right up to the point where you price a full rewrite plus a skills reset for a team holding years of playbooks.

Reemote was designed so that the price is mostly syntax. A deploy is a generator that yields operation requests; each request reads the current state of the host, compares it against the state you described, and emits commands only when there is a real difference — which is why a second run against the same host reports no change instead of reinstalling the package and restarting the service, the same semantics that make an Ansible task come out ok rather than changed. The following deploy maps task for task onto its Ansible equivalent:

from reemote import op
from reemote.modules import apt, files, systemd

PAGE = "<!doctype html><h1>Hello from staging</h1>\n"

def deploy(host):
    yield op(apt.packages, name="Install nginx",
             packages=("nginx",), sudo=True)
    yield op(files.install, name="Write landing page",
             content=PAGE, dest="/var/www/html/index.html",
             mode="0644", sudo=True)
    yield op(systemd.service, name="Run nginx",
             service="nginx", running=True, enabled=True, sudo=True)
Enter fullscreen mode Exit fullscreen mode

Read that against the Ansible tasks it corresponds to and the differences are syntactic: a module becomes a function, a task name becomes a name= argument, become: true becomes sudo=True, and a list of tasks becomes a generator that yields them. The vocabulary carries over as well — 29 modules covering package management, files and version control, services, firewalls, system configuration, security, databases and containers, from apt, dnf and apk through files, git, systemd, firewalld, selinux, mysql and postgresql.

The roles carry over too, and that is where a decade of Ansible Galaxy work stops being sunk cost. Sixty-three of the seventy-one roles in the library today are Jeff Geerling's — Apache, Docker, nginx, PHP, PostgreSQL, NTP, Memcached, NFS, Certbot, Redis, the firewall role and the rest — alongside DataDog's official agent role and migrations from other published Ansible roles. Each is a Python module with typed role variables rather than a directory of YAML loaded by convention, and each ships with a runnable example and an offline test that replays it twice against a simulated host and asserts the second pass reports no change anywhere. There is no CLI to invoke and no DSL to learn: you import the library and write Python.

Use it where it fits

The critique's real takeaway survives the change of tool: stop using any one tool for everything. Ansible is not obsolete — it still fits straightforward configuration management, bootstrapping legacy environments and simple operational tasks, and the advice to recognize when a tool has outgrown its problem class applies here as well. Reemote configures machines you can reach over SSH or a local container. It is not a provisioning system: if your infrastructure is a resource graph applied through APIs and replaced rather than modified, a graph-aware tool remains the right choice, and immutable-infrastructure shops will not find their problem in this library.

Where the job is long-lived Linux servers and the playbooks have begun to strain — the nested templating, the six-month-later revision, the debugging session that ends in a DNS outage — Reemote is the alternative you can actually migrate to. It keeps Ansible's execution model, its semantics and its role ecosystem, and hands you back the language.


Sources

Top comments (0)