DEV Community

Kim Jarvis
Kim Jarvis

Posted on Originally published at reemote.hashnode.dev

Reemote: dry-run, then apply — no DSL required

Reemote is a pure-Python configuration-management library built around one idea: every deploy runs twice, first as a dry-run and then as an apply, and the dry-run is as clear as the apply step. Same code, same inventory, same operations — the only difference is a dry=True flag. The dry-run gathers real facts from real hosts and reports exactly what the apply is about to do, so nothing is executed until you have read the plan.

That two-phase shape is what lets teams use automation without turning every change into a leap of faith. A Reemote dry-run shows you, before a single command is sent:

  • The intended diff. For each operation the plan reports changed or no change, and when it changes it says why — content /etc/nginx/nginx.conf differs, will install, packages ('nginx',) missing, will install, service nginx is not running, will start. You read the diff, not a promise that something will be fine.
  • The host scope. The plan is keyed by host label, so a deploy aimed at forty servers shows you which of the forty will actually change and which will be no-ops. Nothing hides behind a play-level hosts: glob.
  • The exact commands. When the apply phase does run, its log lists the same operations with the shell commands that were sent, rendered canonically so a deploy reads the same whether the transport is SSH, docker, or podman. The dry-run tells you what will happen; the apply log tells you what did.

Try it in under a minute (docker connector)

Reemote ships a docker connector that runs your deploy inside a local container, so you need neither a remote host nor an SSH key to see the two phases work. Docker or Podman must be installed locally — the connector shells out to whichever CLI you name in the inventory, and there is no default. 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": "demo",
      "family": "Alpine",
      "connection": {
          "connector": "docker",
          "identifier": "alpine:3.20",
          "docker_cmd": "podman",   # or "docker"
      },
  }]


  def deploy(host):
      yield op(files.install,
               name="Write a greeting",
               content="Hello from reemote!\n",
               dest="/tmp/reemote-hello.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.
      _, 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

Reemote starts a throwaway alpine:3.20 container, previews the change without touching it, then runs the same deploy for real against a second container, prints the resulting command log, and finally commits each container into a new image and removes it. Verified output:

  == Dry run: what would change ==
  demo: Write a greeting         [changed: content /tmp/reemote-hello.txt is absent, will install]

  == Applied: what changed ==
  demo: 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'
Enter fullscreen mode Exit fullscreen mode

The dry-run line and the first line of the apply log are the same line — that is the point. The plan the dry-run showed you is the plan the apply executed, verbatim, with the shell commands appended. Each run(...) starts its own throwaway container from alpine:3.20, so both phases observe the same absent file; the demo is about the two-phase pattern, not idempotence.

The inventory is a plain Python list of host dictionaries carrying connection information. Reemote is agentless: for SSH targets the connection block is passed to asyncssh.

A deploy is a generator that yields operation requests in order — here, a single files.install. In general these operations map closely to their Ansible counterparts, so the vocabulary will be familiar.

The following deploy installs and starts nginx:

  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

Point that deploy at your staging inventory with dry=True first and you get a per-host, per-operation diff of what staging is about to look like — the packages that will be installed, the file that will change, the service that will be started or left alone — before any of it happens. Read it, then run the same code without dry=True to apply.

The program is asynchronous. Operations are dispatched to every host in the inventory concurrently, and the controller waits for every host to finish an operation before advancing to the next.

run(...) returns the plans and the report as structured objects your program can inspect, so the dry-run diff is not just printable text — it is data you can gate a rollout on, log to a dashboard, or attach to a pull request.

Reemote is a Python library for automation. It has no CLI, and there is no DSL to learn. The library is thoroughly documented, and the repository contains over 400 usage examples.

Reemote is inspired by Pyinfra, an excellent CLI configuration-management tool maintained by Nick Mills-Barrett, which we recommend without reservation. Commercially developed, Reemote is now open source under the EPL-2.0 license. I am the maintainer of the open-source library.

If you have ever wanted a configuration-management tool that shows you the change before it makes it — in the same language as the rest of your stack — Reemote is worth a look.

Try it

Top comments (2)

Collapse
 
userxnom profile image
Abdullah Naseer •

The line that sold me is the one about the dry-run line and the first line of the apply log being the same line. Most tools simulate a dry run, and the simulation is exactly where the plan drifts from reality — here the dry run and the apply are the same code, same inventory, same operations, with only the dry=True flag flipped, so the plan you read is the run you get. One question: what happens when the world moves between the two phases — say a host drops off, or a package version shifts after the dry run across forty servers? Does the apply re-check the facts, or does it trust the plan it just made? That gap is where a two-phase deploy either earns its trust or quietly loses it.

Collapse
 
kimbofab profile image
Kim Jarvis •

The apply re-reads the world rather than trusting the plan. Reemote's semantics are based on Ansible. The two-phase deploy behaves in exactly the same way as Ansible.

Within one run, the fact cache is rebuilt at every step, so each operation checks current state and only sends a command when something changed — a version that shifted between prepare and apply shows up as "no change," not a stale command. A dry run and a real run are two independent calls, each opening fresh connections and preparing against the live world: a dropped-off host surfaces as a connection error naming every unreachable host at once, and a shifted version surfaces as a different plan line before anything is sent. Drift between phases raises an error, so chaining means re-reading the world, not reusing a plan.