<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Kim Jarvis</title>
    <description>The latest articles on DEV Community by Kim Jarvis (@kimbofab).</description>
    <link>https://dev.to/kimbofab</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4242515%2F51c0c907-7f70-4be9-a3e8-ba710605d967.png</url>
      <title>DEV Community: Kim Jarvis</title>
      <link>https://dev.to/kimbofab</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kimbofab"/>
    <language>en</language>
    <item>
      <title>Managing Systems and Applications with Reemote</title>
      <dc:creator>Kim Jarvis</dc:creator>
      <pubDate>Tue, 01 Dec 2026 11:30:31 +0000</pubDate>
      <link>https://dev.to/kimbofab/managing-systems-and-applications-with-reemote-31a4</link>
      <guid>https://dev.to/kimbofab/managing-systems-and-applications-with-reemote-31a4</guid>
      <description>&lt;p&gt;Keeping Linux machines in a known state requires a configuration management system. Reemote approaches that problem as a Python library: your inventory, deployment logic, and integrations are ordinary Python code, while Reemote supplies the facts, idempotent operations, and execution model that turn that code into changes on remote machines.&lt;/p&gt;

&lt;p&gt;If you already know Python, the learning curve is short. Loops, conditions, functions, classes, and third-party packages are all available without translating your intent into a separate configuration language. Under the hood, Reemote renders Python operations as shell commands and transfers them over SSH. The target needs a POSIX-compatible shell, but it does not need Python or a Reemote agent.&lt;/p&gt;

&lt;p&gt;Reemote is a younger project than the established configuration management systems, so its built-in module collection and surrounding ecosystem are smaller. That is the trade-off for a compact, Python-native design. When an operation is missing, the answer is often a small Python function rather than a new plugin system.&lt;/p&gt;

&lt;p&gt;The examples below progress from a disposable container to a reusable inventory, a multi-step application deployment, and a GitOps workflow. They use Python 3.13 or newer and run on Reemote 0.1.4 as well as current source.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installing Reemote
&lt;/h2&gt;

&lt;p&gt;Reemote is a Python package, so install it with &lt;code&gt;pip&lt;/code&gt; or the more modern &lt;code&gt;uv&lt;/code&gt; package manager. A virtual environment keeps the project dependencies separate from other Python work:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python3 -m venv .venv
. .venv/bin/activate
python -m pip install reemote
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With &lt;code&gt;uv&lt;/code&gt;, the equivalent setup is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;uv venv
. .venv/bin/activate
uv pip install reemote
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Confirm that the package imports and shows its version:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python -c &lt;span class="s1"&gt;'import reemote; from importlib.metadata import version; print(version("reemote"))'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The examples assume that the commands run from the directory containing your inventory and deploy files.&lt;/p&gt;

&lt;h2&gt;
  
  
  A Docker Base Example
&lt;/h2&gt;

&lt;p&gt;The quickest way to see Reemote work is to target a local container. The Docker connector accepts either an existing container or an image name. When given an image, it creates a throwaway container for each run, so the example can install a file without leaving a changed container behind.&lt;/p&gt;

&lt;p&gt;Save the following as &lt;code&gt;hello.py&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# hello.py&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;asyncio&lt;/span&gt;

&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;reemote&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;files&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;format_log&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;format_plan&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;op&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;run&lt;/span&gt;

&lt;span class="no"&gt;INVENTORY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="s2"&gt;"host"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"demo"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"family"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Alpine"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"connection"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="s2"&gt;"connector"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"docker"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"identifier"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"alpine:3.20"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"docker_cmd"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"podman"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nf"&gt;op&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;files&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;install&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Write a greeting"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Hello from reemote!\n"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;dest&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/tmp/reemote-hello.txt"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"0644"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;plans&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;INVENTORY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dry&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"== Dry run =="&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;format_plan&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;plans&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;report&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;INVENTORY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"\n== Apply =="&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="n"&gt;report&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;format_log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;report&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="n"&gt;asyncio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace &lt;code&gt;podman&lt;/code&gt; with &lt;code&gt;docker&lt;/code&gt; if that is the container runtime you use. Run the script with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python hello.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output has two parts:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;== Dry run ==
demo: Write a greeting         [changed: content /tmp/reemote-hello.txt is absent, will install]

== Apply ==
demo: Write a greeting         [changed: content /tmp/reemote-hello.txt is absent, will install]
    $ scp &amp;lt;files install&amp;gt; -&amp;gt; /tmp/reemote-install-2e52d4f8373a608a/content
    $ sh -c 'mkdir -p /tmp &amp;amp;&amp;amp; cp /tmp/reemote-install-2e52d4f8373a608a/content /tmp/reemote-hello.txt &amp;amp;&amp;amp; chmod 644 /tmp/reemote-hello.txt &amp;amp;&amp;amp; rm -rf /tmp/reemote-install-2e52d4f8373a608a'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;files.install&lt;/code&gt; operation first transfers the content to a temporary spool file, then installs it with an elevated shell command when necessary. This spool-and-install pattern lets Reemote write root-owned files without embedding arbitrary file content directly in a privileged shell command.&lt;/p&gt;

&lt;p&gt;The container example also illustrates an important connector detail: an image-based Docker host owns its container. Closing it commits the result to a new image and removes the container. Separate dry-run and apply calls therefore both begin from the original image rather than from the state left by the preceding call.&lt;/p&gt;

&lt;h2&gt;
  
  
  Inventory, Operations, and Facts
&lt;/h2&gt;

&lt;p&gt;The container inventory introduces the three central Reemote concepts: inventory, operations, and facts.&lt;/p&gt;

&lt;p&gt;An inventory is a Python list of dictionaries. Each dictionary describes one host, including its name, operating-system family, connection settings, and optional metadata. The &lt;code&gt;family&lt;/code&gt; value is one of &lt;code&gt;Ubuntu&lt;/code&gt;, &lt;code&gt;RedHat&lt;/code&gt;, or &lt;code&gt;Alpine&lt;/code&gt;; it lets deployment code choose the appropriate package manager without first discovering the distribution.&lt;/p&gt;

&lt;p&gt;Reemote separates immediate actions from state operations. An action executes a command now, such as &lt;code&gt;uname -r&lt;/code&gt;. A state operation describes the desired state and is idempotent: it compares that state with the current state and changes something only when the two differ.&lt;/p&gt;

&lt;p&gt;Facts are read-only observations of a host. Operations use facts to decide whether a command is necessary. For example, a package operation reads the installed-package state and requests an installation only when the package is absent.&lt;/p&gt;

&lt;p&gt;The distinction is practical. A shell command is appropriate for a one-off query or an intentionally non-idempotent action. A state operation is usually the better choice for configuration because a second run converges to the same result without repeating work that is already complete.&lt;/p&gt;

&lt;h2&gt;
  
  
  Running Commands in Python
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;hello.py&lt;/code&gt; script used a state operation. For an immediate command, Reemote provides actions such as &lt;code&gt;Shell&lt;/code&gt;. The &lt;code&gt;gather_action&lt;/code&gt; helper runs an action concurrently across a list of hosts and returns a dictionary keyed by host name.&lt;/p&gt;

&lt;p&gt;The following script assumes an inventory named &lt;code&gt;INVENTORY&lt;/code&gt;, which the "Creating an Inventory File" section below shows how to create. It also assumes that &lt;code&gt;journalctl&lt;/code&gt; is installed on every selected host:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# commands.py&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;asyncio&lt;/span&gt;

&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;reemote&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;Host&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Shell&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;gather_action&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;inventory&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="no"&gt;INVENTORY&lt;/span&gt;

&lt;span class="n"&gt;hosts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;Host&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;from_inventory&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;entry&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="no"&gt;INVENTORY&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;


&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;command&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"uname -r"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"uptime"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"journalctl --no-pager -n 1"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;results&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;gather_action&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hosts&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Shell&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;command&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;command&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"$ {command}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;results&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;items&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"{name}: {result['stdout'].strip()}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="n"&gt;asyncio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each &lt;code&gt;Shell&lt;/code&gt; result contains &lt;code&gt;exit_status&lt;/code&gt;, &lt;code&gt;stdout&lt;/code&gt;, and &lt;code&gt;stderr&lt;/code&gt;. A non-zero command exit is data returned to the caller; connection, timeout, and privilege failures are reported as typed exceptions.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;gather_action&lt;/code&gt; closes the host connections it used when the call returns. The same &lt;code&gt;Host&lt;/code&gt; objects can be reused for later calls; each call opens and closes a fresh connection.&lt;/p&gt;

&lt;p&gt;On a systemd host with &lt;code&gt;journalctl&lt;/code&gt; installed, a command such as &lt;code&gt;journalctl --follow&lt;/code&gt; works too, but it never finishes under normal circumstances, so the call waits until you interrupt it or the command exits. Reemote captures the result rather than maintaining an interactive terminal session.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rebooting and Checking Uptime
&lt;/h2&gt;

&lt;p&gt;The same action API can reboot a host and then wait for it to return. A reboot normally drops the SSH connection before the command can return a clean result, so the script treats that specific connection loss as expected. It records the boot ID beforehand, then polls until the machine has a new boot ID and reports its uptime. Checking the boot ID avoids a race in which SSH briefly accepts a connection while the old system is still shutting down.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# reboot.py&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;asyncio&lt;/span&gt;

&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;reemote&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nc"&gt;Host&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;HostConnectionError&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Shell&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;WaitForConnection&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;gather_action&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;inventory&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="no"&gt;INVENTORY&lt;/span&gt;


&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;hosts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;Host&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;from_inventory&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;entry&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="no"&gt;INVENTORY&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;before&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;gather_action&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;hosts&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Shell&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;command&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"cat /proc/sys/kernel/random/boot_id"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;old_boot_ids&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"stdout"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;strip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;before&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;items&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;gather_action&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hosts&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Shell&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;command&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"reboot"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sudo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="nc"&gt;HostConnectionError&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;exc&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="c1"&gt;# A successful reboot can tear down SSH connections mid-command.&lt;/span&gt;
        &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"Reboot disconnected a host: {exc}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;hosts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;Host&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;from_inventory&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;entry&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="no"&gt;INVENTORY&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;gather_action&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hosts&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;WaitForConnection&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;300&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;retry&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;asyncio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;timeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;300&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;gather_action&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                    &lt;span class="n"&gt;hosts&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="nc"&gt;Shell&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="n"&gt;command&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"cat /proc/sys/kernel/random/boot_id &amp;amp;&amp;amp; uptime"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="nc"&gt;HostConnectionError&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="c1"&gt;# SSH can disappear again while the old systems shut down.&lt;/span&gt;
                &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;asyncio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="k"&gt;continue&lt;/span&gt;

            &lt;span class="n"&gt;lines&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;output&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"stdout"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;strip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;splitlines&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;output&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;items&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nb"&gt;all&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lines&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;old_boot_ids&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;old_boot_ids&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;output&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;lines&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;items&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"{name}: {output[1]}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="k"&gt;return&lt;/span&gt;
            &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;asyncio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="n"&gt;asyncio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;WaitForConnection&lt;/code&gt; action polls until the host is reachable or the timeout expires. The boot-ID loop then waits for every host to complete its reboot, and each final uptime reports the time since that host's new boot.&lt;/p&gt;

&lt;p&gt;The reboot and package examples use &lt;code&gt;sudo=True&lt;/code&gt;; the connecting user must therefore have passwordless sudo, or sudo credentials must be supplied through the inventory's &lt;code&gt;privilege&lt;/code&gt; mapping.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installing Packages Idempotently
&lt;/h2&gt;

&lt;p&gt;A package installation is a better fit for a state operation than a shell command. The &lt;code&gt;apt.packages&lt;/code&gt; operation reads the installed-package facts, installs only missing packages, and reports no change when the desired set is already present.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# packages.py&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;asyncio&lt;/span&gt;

&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;reemote&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;apt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;format_log&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;op&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;run&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;inventory&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="no"&gt;INVENTORY&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nf"&gt;op&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;apt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;packages&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Install tmux and vim"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;packages&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"tmux"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"vim"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;sudo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;attempt&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;report&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;INVENTORY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"== Run {attempt} =="&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="n"&gt;report&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;
        &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;format_log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;report&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="n"&gt;asyncio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On an Ubuntu or Debian host, the first run installs any missing packages. The second run ends with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;== Run 2 ==
demo: Install tmux and vim     [no change: all packages present]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Reemote also provides package operations for DNF and APK. A family-aware deploy can choose the operation from static inventory data. The small &lt;code&gt;host_family&lt;/code&gt; helper works with published Reemote 0.1.4, which preserves &lt;code&gt;family&lt;/code&gt; in &lt;code&gt;host.extra&lt;/code&gt;, and with current source, which exposes &lt;code&gt;host.family&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;reemote&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;apt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;apk&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dnf&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;op&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;host_family&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;getattr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"family"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;extra&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"family"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;install_packages&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;installer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="s2"&gt;"Ubuntu"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;apt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;packages&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"RedHat"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;dnf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;packages&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"Alpine"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;apk&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;packages&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;host_family&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nf"&gt;op&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;installer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Install tmux and vim"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;packages&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"tmux"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"vim"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;sudo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This branch is safe because the family value is fixed for both execution phases. It does not depend on a fact that could change while the deploy is running.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting Facts from Your Servers
&lt;/h2&gt;

&lt;p&gt;The package operation already used facts internally, but you can gather the same read-only information directly. Suppose you want to compare the installed Vim version and kernel release across several Ubuntu machines. Materialize the inventory and call &lt;code&gt;gather_fact&lt;/code&gt; for each fact:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# facts.py&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;asyncio&lt;/span&gt;

&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;reemote&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;Host&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;apt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;gather_fact&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;server&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;inventory&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="no"&gt;INVENTORY&lt;/span&gt;


&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;hosts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;Host&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;from_inventory&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;entry&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="no"&gt;INVENTORY&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;vim&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;gather_fact&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hosts&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;apt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DebPackage&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"vim"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;kernels&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;gather_fact&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hosts&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;server&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;KernelVersion&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;distributions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;gather_fact&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hosts&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;server&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;LinuxName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;finally&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;asyncio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;gather&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;aclose&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;host&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;hosts&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;vim&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;package&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;vim&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="n"&gt;version&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;package&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"version"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;package&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="s2"&gt;"not installed"&lt;/span&gt;
        &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"{name}: {distributions[name]}, kernel {kernels[name]}, "&lt;/span&gt;
              &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"vim {version}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="n"&gt;asyncio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;gather_fact&lt;/code&gt; returns one value per host and runs the reads concurrently. Unlike &lt;code&gt;gather_action&lt;/code&gt;, it does not close the connections it opens, so the script closes them in a &lt;code&gt;finally&lt;/code&gt; block.&lt;/p&gt;

&lt;p&gt;Reemote does not currently provide a distribution-neutral &lt;code&gt;RebootRequired&lt;/code&gt; fact. On Ubuntu and Debian, the conventional &lt;code&gt;/var/run/reboot-required&lt;/code&gt; marker can be queried with a &lt;code&gt;Shell&lt;/code&gt; action instead:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;results&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;gather_action&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;hosts&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nc"&gt;Shell&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;command&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"if [ -f /var/run/reboot-required ]; then echo yes; else echo no; fi"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Treat that marker as an operating-system-specific convention, not as a portable fact. The module documentation lists the facts that are available for each subsystem.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating an Inventory File
&lt;/h2&gt;

&lt;p&gt;The Docker example kept its inventory inline. For a real fleet, a separate &lt;code&gt;inventory.py&lt;/code&gt; makes the targets and their metadata easier to reuse. The file is ordinary Python, so groups can be lists that are combined into the final inventory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# inventory.py&lt;/span&gt;
&lt;span class="no"&gt;SSH&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="s2"&gt;"username"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"your-user"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"key_path"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"~/.ssh/id_ed25519"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;host&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;group&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="s2"&gt;"host"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"family"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Ubuntu"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"connection"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;SSH&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;address&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"group"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;group&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"tags"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;group&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;


&lt;span class="no"&gt;SERVERS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nf"&gt;host&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"podpile.home"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"servers"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nf"&gt;host&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"microos.home"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"servers"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nf"&gt;host&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"code.example.com"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"servers"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="no"&gt;WORKSTATIONS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nf"&gt;host&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"nov.home"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"workstations"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nf"&gt;host&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"tux.home"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"workstations"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="no"&gt;INVENTORY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;SERVERS&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="no"&gt;WORKSTATIONS&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every entry in these inventories supplies &lt;code&gt;host&lt;/code&gt;, &lt;code&gt;family&lt;/code&gt;, and &lt;code&gt;connection&lt;/code&gt;; current Reemote requires all three. The &lt;code&gt;group&lt;/code&gt; and &lt;code&gt;tags&lt;/code&gt; fields are optional classifiers that deployment code can inspect. Additional keys are preserved in &lt;code&gt;host.extra&lt;/code&gt;, which provides a simple place for host-specific data.&lt;/p&gt;

&lt;p&gt;To restrict a deployment to one group, pass only that group's list to &lt;code&gt;run&lt;/code&gt;, or attach a &lt;code&gt;when&lt;/code&gt; predicate to each request. A predicate must remain stable across the prepare and apply phases, so define it at module level:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;is_server&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;group&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"servers"&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nf"&gt;op&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;apt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;packages&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Install tmux and vim"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;packages&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"tmux"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"vim"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;sudo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;when&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;is_server&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;when&lt;/code&gt; guard keeps the request in every host's schedule but skips it on ineligible hosts. That uniform schedule lets Reemote compare hosts in lockstep without losing determinism.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating a Deploy
&lt;/h2&gt;

&lt;p&gt;A deploy is a synchronous generator that yields operation requests through &lt;code&gt;op()&lt;/code&gt;. Put the package deployment in &lt;code&gt;deploy.py&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# deploy.py&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;asyncio&lt;/span&gt;

&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;reemote&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;apt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;format_log&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;format_plan&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;op&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;run&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;inventory&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="no"&gt;INVENTORY&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nf"&gt;op&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;apt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;packages&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Install packages"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;packages&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"tmux"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"vim"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;sudo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;plans&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;INVENTORY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dry&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;format_plan&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;plans&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;report&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;INVENTORY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="n"&gt;report&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;format_log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;report&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="n"&gt;asyncio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The dry run reads the current state for real and plans the work without applying changes. The normal run performs the same preparation, checks that the request sequence is unchanged, and then applies the plan. This gives you a reviewable preview without maintaining a second description of the deployment.&lt;/p&gt;

&lt;p&gt;Use tuples rather than lists for operation arguments such as &lt;code&gt;packages&lt;/code&gt;. Requests must be hashable and comparable by value so that Reemote can verify that both phases describe the same work.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using Host Data
&lt;/h2&gt;

&lt;p&gt;A single package list is rarely ideal for every machine. Reemote preserves additional inventory keys in &lt;code&gt;host.extra&lt;/code&gt;, so the inventory can carry a package list for each host and the deploy can remain generic.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# inventory.py&lt;/span&gt;
&lt;span class="no"&gt;SSH&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="s2"&gt;"username"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"your-user"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"key_path"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"~/.ssh/id_ed25519"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;host&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;group&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;packages&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="s2"&gt;"host"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"family"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Ubuntu"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"connection"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;SSH&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;address&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"group"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;group&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"tags"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;group&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"packages"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;tuple&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;packages&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;


&lt;span class="no"&gt;SERVERS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nf"&gt;host&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"podpile.home"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"servers"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"tmux"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"vim"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nf"&gt;host&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"microos.home"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"servers"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"tmux"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nf"&gt;host&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"code.example.com"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"servers"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"tmux"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"vim"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="no"&gt;WORKSTATIONS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nf"&gt;host&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"nov.home"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"workstations"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"git"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"tmux"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"vim"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nf"&gt;host&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"tux.home"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"workstations"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"git"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="no"&gt;INVENTORY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;SERVERS&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="no"&gt;WORKSTATIONS&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The deploy now reads the list from the host instead of embedding it in the operation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nf"&gt;op&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;apt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;packages&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Install host packages"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;packages&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;extra&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"packages"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;sudo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The inventory remains data, while the deploy remains reusable. Because the package tuple is fixed before the run starts, both execution phases see the same value.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using Group Data
&lt;/h2&gt;

&lt;p&gt;Host data is flexible, but repeating the same package list for every member of a group defeats the purpose of grouping. A small inventory helper can provide group defaults and allow individual hosts to override them.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# inventory.py&lt;/span&gt;
&lt;span class="no"&gt;SSH&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="s2"&gt;"username"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"your-user"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"key_path"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"~/.ssh/id_ed25519"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="no"&gt;GROUP_PACKAGES&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="s2"&gt;"servers"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"tmux"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"vim"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"workstations"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"git"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"tmux"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"vim"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;host&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;group&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;packages&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;extra&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;extra&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"packages"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;tuple&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;packages&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;packages&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="no"&gt;GROUP_PACKAGES&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;group&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="s2"&gt;"host"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"family"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Ubuntu"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"connection"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;SSH&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;address&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"group"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;group&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"tags"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;group&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;


&lt;span class="no"&gt;SERVERS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nf"&gt;host&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"podpile.home"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"servers"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nf"&gt;host&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"microos.home"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"servers"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;packages&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"tmux"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nf"&gt;host&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"code.example.com"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"servers"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="no"&gt;WORKSTATIONS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nf"&gt;host&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"nov.home"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"workstations"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nf"&gt;host&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"tux.home"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"workstations"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;packages&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"git"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="no"&gt;INVENTORY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;SERVERS&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="no"&gt;WORKSTATIONS&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The precedence rule is explicit: a host-level &lt;code&gt;packages&lt;/code&gt; argument wins; otherwise the group default applies. The same pattern works for welcome messages, service ports, or any other static configuration value.&lt;/p&gt;

&lt;p&gt;This is ordinary Python rather than a special inheritance language. You can compute defaults, validate them, or load them from another source, and the final inventory still consists of plain dictionaries.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installing Caddy in a Task
&lt;/h2&gt;

&lt;p&gt;The package deploys are intentionally small. A real application usually combines several operations: install a package, write a configuration file, and restart a service when the configuration changes. Caddy makes a compact example because its configuration can be a short text file.&lt;/p&gt;

&lt;p&gt;Reemote deliberately has no &lt;code&gt;files.template&lt;/code&gt; operation. A template context is naturally a dictionary, but operation arguments must be hashable so the prepare and apply phases can be compared. More importantly, a deploy cannot read a live fact and render differently in each phase without violating determinism.&lt;/p&gt;

&lt;p&gt;The recommended shape is to render on the control node before the deploy and pass the finished string to &lt;code&gt;files.install&lt;/code&gt;. For Caddy, the renderer can use Python's &lt;code&gt;json.dumps&lt;/code&gt; to quote the welcome message safely:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# tasks/caddy.py&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;asyncio&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;

&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;reemote&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;apt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;files&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;format_log&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;op&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;run&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;systemd&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;render_caddyfile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;":80 {{\n    respond {json.dumps(message)}\n}}\n"&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;build_caddy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;configs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;configs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt;

        &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nf"&gt;op&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;apt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;packages&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                 &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Install Caddy"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                 &lt;span class="n"&gt;packages&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"caddy"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                 &lt;span class="n"&gt;sudo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nf"&gt;op&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;files&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;install&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                 &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Write Caddyfile"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                 &lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;configs&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                 &lt;span class="n"&gt;dest&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/etc/caddy/Caddyfile"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                 &lt;span class="n"&gt;mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"0644"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                 &lt;span class="n"&gt;sudo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;deploy&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;build_restart&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;changed&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;daemon_reload&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;False&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;restart&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;changed&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nf"&gt;op&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;systemd&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;service&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                     &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Restart Caddy"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                     &lt;span class="n"&gt;service&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"caddy"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                     &lt;span class="n"&gt;restarted&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                     &lt;span class="n"&gt;daemon_reload&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;daemon_reload&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                     &lt;span class="n"&gt;sudo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;restart&lt;/span&gt;


&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;deploy_caddy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;inventory&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;configs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"host"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;render_caddyfile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"welcome_message"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;entry&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;inventory&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;report&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;inventory&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;build_caddy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;configs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="n"&gt;report&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;format_log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;report&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;notifying&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"Install Caddy"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Write Caddyfile"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;changed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;frozenset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;entry&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;report&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;log&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;changed&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;notifying&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;restart_report&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;inventory&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;build_restart&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;changed&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="n"&gt;restart_report&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;format_log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;restart_report&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"__main__"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;inventory&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="no"&gt;WEBSERVERS&lt;/span&gt;
    &lt;span class="n"&gt;asyncio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;deploy_caddy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;WEBSERVERS&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The corresponding web-server inventory carries the message as static data. Add this list to &lt;code&gt;inventory.py&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="no"&gt;WEBSERVERS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nf"&gt;host&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"playground.home"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"webservers"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
         &lt;span class="n"&gt;packages&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"tmux"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
         &lt;span class="n"&gt;welcome_message&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Hello world!"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run the task as a module from the directory containing &lt;code&gt;inventory.py&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python -m tasks.caddy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first run installs Caddy and writes &lt;code&gt;/etc/caddy/Caddyfile&lt;/code&gt;. The code then freezes the names of hosts whose notifying operations reported a change. &lt;code&gt;build_restart&lt;/code&gt; turns that frozen set into a second deploy, so Caddy restarts only on hosts that changed.&lt;/p&gt;

&lt;p&gt;This two-deploy split is the key detail. A plain &lt;code&gt;run()&lt;/code&gt; deploy cannot branch on the result of an operation it yielded earlier, because its generator runs once against pre-deployment state and again against live state. Reading the &lt;code&gt;ApplyReport&lt;/code&gt; between two complete runs moves the decision to a point where the outcome is final and immutable.&lt;/p&gt;

&lt;p&gt;The Caddy package must be available from the target's configured repositories. On distributions where it is not, add the vendor repository with Reemote's repository operations before requesting the package, or install a pinned binary with the file operations.&lt;/p&gt;

&lt;h2&gt;
  
  
  How Does It All Work?
&lt;/h2&gt;

&lt;p&gt;The Caddy example uses more of Reemote's execution model than the earlier scripts, so it is worth stepping back through what &lt;code&gt;run()&lt;/code&gt; does.&lt;/p&gt;

&lt;p&gt;First, Reemote validates and materializes the inventory. It then executes the deploy generator in a prepare phase. Each yielded operation reads the facts it needs and emits a command descriptor only if the current state differs from the requested state. The resulting plan shows which hosts would change and why.&lt;/p&gt;

&lt;p&gt;For a dry run, execution stops there. For a normal run, Reemote executes the generator again in the apply phase and compares the new request sequence with the prepared sequence. If the requests differ, it raises a determinism error rather than applying a plan that no longer matches the code.&lt;/p&gt;

&lt;p&gt;Once the sequences match, Reemote applies the operations in order. At each step, eligible hosts run concurrently, and the driver waits for that step to finish before advancing to the next operation. This lockstep execution gives every host the same logical schedule while still overlapping network and command latency across the fleet.&lt;/p&gt;

&lt;p&gt;The apply report records each host's outcome: changed, unchanged, or skipped. A non-zero command fails the run rather than being silently recorded as a successful change. At the end, Reemote closes the connections it owns and returns the plan, report, and host objects to the caller.&lt;/p&gt;

&lt;p&gt;This model explains several design choices. Request arguments must be hashable and value-stable because they are compared between phases. &lt;code&gt;when&lt;/code&gt; predicates must read static inventory data because both phases must make the same eligibility decision. And a decision based on an earlier operation's result belongs between runs, not in an ordinary generator branch.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conditional Operations
&lt;/h2&gt;

&lt;p&gt;Static conditions belong in &lt;code&gt;when&lt;/code&gt; predicates. A deploy that installs a package only on Red Hat family hosts can select &lt;code&gt;dnf.packages&lt;/code&gt; and attach a family guard; the earlier family-aware package example showed the selection half.&lt;/p&gt;

&lt;p&gt;Conditions based on facts require one more step. Gather the fact before calling &lt;code&gt;run()&lt;/code&gt;, freeze the result, and pass it into a deploy factory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;build_debian_deploy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;names&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;eligible&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;frozenset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;names&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;eligible&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt;
        &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nf"&gt;op&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;apt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;packages&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                 &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Install Debian build tools"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                 &lt;span class="n"&gt;packages&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"build-essential"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                 &lt;span class="n"&gt;sudo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;deploy&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;eligible&lt;/code&gt; set is fixed before either phase starts, so the branch is deterministic. Do not call &lt;code&gt;gather_fact&lt;/code&gt; or read mutable host state from inside an ordinary deploy generator and use the answer to choose which requests to yield.&lt;/p&gt;

&lt;p&gt;Conditions based on change outcomes follow the Caddy pattern. If a service must restart when either of two files changes, include both request names in the notification set:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;notifying&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"Write Caddyfile"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Write Caddy unit"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="n"&gt;changed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;frozenset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;entry&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;report&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;log&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;changed&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;notifying&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;restart&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;build_restart&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;changed&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;daemon_reload&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A host is included if any matching entry changed. The frozen set keeps the second deploy deterministic across its own prepare and apply phases.&lt;/p&gt;

&lt;p&gt;For more complex orchestration, keep explicit fact and change barriers in separate Python steps around &lt;code&gt;run()&lt;/code&gt; calls. The ordinary &lt;code&gt;run()&lt;/code&gt; path intentionally keeps caller-driven fact barriers and change-outcome branches outside the generator so its two-phase contract stays simple.&lt;/p&gt;

&lt;h2&gt;
  
  
  Applying GitOps with Reemote
&lt;/h2&gt;

&lt;p&gt;Once the inventory, deploy modules, and configuration content live in files, they can be stored in Git as the authoritative record of the infrastructure. A change becomes a reviewable diff rather than a sequence of commands typed into a terminal.&lt;/p&gt;

&lt;p&gt;A practical repository might contain:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;inventory.py
deploy.py
tasks/
  caddy.py
secrets.json
.sops.yaml
.pre-commit-config.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pre-commit hooks can check Python syntax, run the test suite, and lint the deployment code. A pull request then shows which packages, files, and services the deployment code manages, and another team member can review that intent before it reaches production.&lt;/p&gt;

&lt;p&gt;Continuous integration can add a stronger check by running the deploy against disposable containers or test hosts. A dry run against a representative inventory catches invalid arguments and unresolved inputs without changing a real server. A normal run against a disposable target verifies convergence and can run the deployment a second time to detect unintended changes.&lt;/p&gt;

&lt;p&gt;After a pull request is merged, a delivery workflow can install the repository, retrieve the deployment credentials, and run the deploy. This is the GitOps loop: Git holds the desired state, review protects the change, automation applies it, and the next run proves whether the target already matches.&lt;/p&gt;

&lt;p&gt;Secrets need separate treatment. Storing encrypted secret material in the same repository preserves the reviewable workflow without committing plaintext passwords.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using Secrets with Reemote
&lt;/h2&gt;

&lt;p&gt;Reemote does not require a special secrets file format or a global configuration object. Because a deploy is Python, it can call an existing secrets manager before constructing its operations.&lt;/p&gt;

&lt;p&gt;One option is Secrets OPerationS (SOPS) with &lt;code&gt;age&lt;/code&gt; encryption. Create a &lt;code&gt;.sops.yaml&lt;/code&gt; file that selects your age public key, replacing the placeholder below with the key you generated:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;creation_rules&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="s"&gt;-&lt;/span&gt;
      &lt;span class="s"&gt;age1ql3zl7d8k4m2p9w6y5x4c3v2b1n0m9a8s7d6f5g4h3j2k&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create an encrypted JSON file with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sops edit secrets.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The decrypted document can contain ordinary key-value pairs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"smtp_user"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"060ef95df2fa4683aef6ca3ecf"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"smtp_password"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"c983deee174a4f6b9c97035a6d"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After you save and close the editor, SOPS encrypts the values in &lt;code&gt;secrets.json&lt;/code&gt;. The encrypted file can be committed to Git; only a holder of the corresponding private key can decrypt it. Running &lt;code&gt;sops edit secrets.json&lt;/code&gt; again opens the decrypted content and re-encrypts it when saved.&lt;/p&gt;

&lt;p&gt;A small Python module can decrypt that file at startup and expose the values to the deploy:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# app_secrets.py&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;subprocess&lt;/span&gt;

&lt;span class="no"&gt;DECRYPTED&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;subprocess&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"sops"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"--decrypt"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"--output-type"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"json"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"secrets.json"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;check&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;capture_output&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;stdout&lt;/span&gt;
&lt;span class="no"&gt;SECRETS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;loads&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;DECRYPTED&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A deploy can then install an application environment file. The content remains a plain string, which is exactly what &lt;code&gt;files.install&lt;/code&gt; expects:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# smtp.py&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;asyncio&lt;/span&gt;

&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;reemote&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;files&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;format_log&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;op&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;run&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;inventory&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="no"&gt;INVENTORY&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;app_secrets&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="no"&gt;SECRETS&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;content&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"SMTP_USER={SECRETS['smtp_user']}\n"&lt;/span&gt;
        &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"SMTP_PASSWORD={SECRETS['smtp_password']}\n"&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nf"&gt;op&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;files&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;install&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Install SMTP environment"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;dest&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/etc/reemote-smtp.env"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"0600"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;sudo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nf"&gt;op&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;files&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;file&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Protect SMTP environment"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/etc/reemote-smtp.env"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"0600"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;sudo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;report&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;INVENTORY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="n"&gt;report&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;format_log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;report&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="n"&gt;asyncio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The second operation enforces the file mode even when the content is already correct. Reemote logs command descriptors rather than printing the environment file's contents, but you should still avoid logging the &lt;code&gt;SECRETS&lt;/code&gt; mapping or the operation arguments yourself.&lt;/p&gt;

&lt;p&gt;This integration has no privileged plugin API. SOPS handles encryption and decryption, Python handles the workflow, and Reemote receives the finished configuration through the same operation used for non-secret files.&lt;/p&gt;

&lt;h3&gt;
  
  
  Verified output
&lt;/h3&gt;

&lt;p&gt;The example was verified with SOPS 3.13.3 and age 1.2.1 against a fresh Ubuntu 24.04 host. It passed with both current Reemote source and published Reemote 0.1.4. The encrypted file contained neither plaintext secret, and the first deployment produced:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sops-demo: Install SMTP environment [changed: content /etc/reemote-smtp.env is absent, will install]
    $ scp &amp;lt;files install&amp;gt; -&amp;gt; /tmp/reemote-install-99f76d7123b98c88/content
    $ sudo sh -c 'mkdir -p /etc &amp;amp;&amp;amp; cp /tmp/reemote-install-99f76d7123b98c88/content /etc/reemote-smtp.env &amp;amp;&amp;amp; chmod 600 /etc/reemote-smtp.env &amp;amp;&amp;amp; rm -rf /tmp/reemote-install-99f76d7123b98c88'
sops-demo: Protect SMTP environment [no change: file /etc/reemote-smtp.env already exists]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The remote file matched the decrypted values and had mode &lt;code&gt;0600&lt;/code&gt;. After changing its mode to &lt;code&gt;0644&lt;/code&gt;, a second run left the content alone and repaired the permissions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sops-demo: Install SMTP environment [no change: content already up to date (/etc/reemote-smtp.env)]
sops-demo: Protect SMTP environment [changed: mode 644 differs, will chmod 600]
    $ sudo chmod 600 /etc/reemote-smtp.env
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Neither run printed the secret values.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Reemote brings configuration management back to a small set of Python ideas: a list of hosts, generator functions that describe desired state, facts that observe the present state, and an execution model that compares the two. Its immediate actions cover ad-hoc commands, while its state operations make package, file, and service changes idempotent.&lt;/p&gt;

&lt;p&gt;The Docker connector is useful for experiments and tests, SSH is the normal path to real machines, and the same inventory and deploy code can move between them. Python remains available for the parts that a configuration language often makes awkward: group defaults, control-side rendering, external secrets, and custom deployment logic.&lt;/p&gt;

&lt;p&gt;The documentation covers the complete module vocabulary and the two-phase execution rules. For a fleet that already speaks Python, those are enough building blocks to keep the desired state readable, reviewable, and reproducible.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://reemote.org/" rel="noopener noreferrer"&gt;Reemote documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/kimjarvis/reemote" rel="noopener noreferrer"&gt;Reemote source repository&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.python.org/" rel="noopener noreferrer"&gt;Python&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.astral.sh/uv/" rel="noopener noreferrer"&gt;uv&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://caddyserver.com/" rel="noopener noreferrer"&gt;Caddy&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://getsops.io/" rel="noopener noreferrer"&gt;SOPS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://age-encryption.org/" rel="noopener noreferrer"&gt;age&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>showdev</category>
      <category>opensource</category>
      <category>devops</category>
    </item>
    <item>
      <title>An alternative to Ansible for configuration management</title>
      <dc:creator>Kim Jarvis</dc:creator>
      <pubDate>Mon, 30 Nov 2026 17:02:05 +0000</pubDate>
      <link>https://dev.to/kimbofab/an-alternative-to-ansible-for-configuration-management-58b7</link>
      <guid>https://dev.to/kimbofab/an-alternative-to-ansible-for-configuration-management-58b7</guid>
      <description>&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it in under a minute (docker connector)
&lt;/h2&gt;

&lt;p&gt;Reemote ships a &lt;strong&gt;docker connector&lt;/strong&gt; that runs your deploy inside a local container, so this needs no remote host, no SSH key and no agent. &lt;strong&gt;Docker or Podman must be installed locally&lt;/strong&gt; — the connector shells out to whichever CLI you name in the inventory, and there is no default. The script declares two hosts, &lt;code&gt;demo0&lt;/code&gt; and &lt;code&gt;demo1&lt;/code&gt;, 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 &lt;strong&gt;check mode&lt;/strong&gt;; the second applies it, one operation at a time across both hosts, which is what Ansible calls &lt;strong&gt;lockstep execution&lt;/strong&gt;. Two steps:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# 1. Install (Python 3.13+; pip works just as well as uv)&lt;/span&gt;
uv venv .venv &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;source&lt;/span&gt; .venv/bin/activate &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; uv pip install reemote

&lt;span class="c"&gt;# 2. Save the script below as hello.py, then run it&lt;/span&gt;
python hello.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# hello.py&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;asyncio&lt;/span&gt;

&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;reemote&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;files&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;format_log&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;format_plan&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;op&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;run&lt;/span&gt;

&lt;span class="no"&gt;INVENTORY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="s2"&gt;"host"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"demo0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"family"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Alpine"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"connection"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="s2"&gt;"connector"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"docker"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s2"&gt;"identifier"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"alpine:3.20"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s2"&gt;"docker_cmd"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"podman"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;   &lt;span class="c1"&gt;# or "docker"&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="s2"&gt;"host"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"demo1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"family"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Alpine"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"connection"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="s2"&gt;"connector"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"docker"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s2"&gt;"identifier"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"alpine:3.20"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s2"&gt;"docker_cmd"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"podman"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nf"&gt;op&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;files&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;install&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Write a greeting"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Hello from reemote!\n"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;dest&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/tmp/reemote-hello.txt"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"0644"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nf"&gt;op&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;files&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;install&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Record the host name"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"written on {host.name}\n"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;dest&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/tmp/reemote-host.txt"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"0644"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="c1"&gt;# Dry run: facts are gathered for real, nothing is mutated.&lt;/span&gt;
    &lt;span class="n"&gt;plans&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;INVENTORY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dry&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"== Dry run: what would change =="&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;format_plan&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;plans&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# Apply: the same deploy, executed against a fresh container per host.&lt;/span&gt;
    &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;report&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;INVENTORY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"\n== Applied: what changed =="&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="n"&gt;report&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;format_log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;report&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="n"&gt;asyncio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Verified output, produced by running exactly this script against Podman:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;== 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 &amp;lt;files install&amp;gt; -&amp;gt; /tmp/reemote-install-2e52d4f8373a608a/content
    $ sh -c 'mkdir -p /tmp &amp;amp;&amp;amp; cp /tmp/reemote-install-2e52d4f8373a608a/content /tmp/reemote-hello.txt &amp;amp;&amp;amp; chmod 644 /tmp/reemote-hello.txt &amp;amp;&amp;amp; rm -rf /tmp/reemote-install-2e52d4f8373a608a'
demo1: Write a greeting         [changed: content /tmp/reemote-hello.txt is absent, will install]
    $ scp &amp;lt;files install&amp;gt; -&amp;gt; /tmp/reemote-install-2e52d4f8373a608a/content
    $ sh -c 'mkdir -p /tmp &amp;amp;&amp;amp; cp /tmp/reemote-install-2e52d4f8373a608a/content /tmp/reemote-hello.txt &amp;amp;&amp;amp; chmod 644 /tmp/reemote-hello.txt &amp;amp;&amp;amp; rm -rf /tmp/reemote-install-2e52d4f8373a608a'
demo0: Record the host name     [changed: content /tmp/reemote-host.txt is absent, will install]
    $ scp &amp;lt;files install&amp;gt; -&amp;gt; /tmp/reemote-install-8c7265455d37e471/content
    $ sh -c 'mkdir -p /tmp &amp;amp;&amp;amp; cp /tmp/reemote-install-8c7265455d37e471/content /tmp/reemote-host.txt &amp;amp;&amp;amp; chmod 644 /tmp/reemote-host.txt &amp;amp;&amp;amp; rm -rf /tmp/reemote-install-8c7265455d37e471'
demo1: Record the host name     [changed: content /tmp/reemote-host.txt is absent, will install]
    $ scp &amp;lt;files install&amp;gt; -&amp;gt; /tmp/reemote-install-8c7265455d37e471/content
    $ sh -c 'mkdir -p /tmp &amp;amp;&amp;amp; cp /tmp/reemote-install-8c7265455d37e471/content /tmp/reemote-host.txt &amp;amp;&amp;amp; chmod 644 /tmp/reemote-host.txt &amp;amp;&amp;amp; rm -rf /tmp/reemote-install-8c7265455d37e471'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Nothing was set up for this demo beyond having Podman installed and &lt;code&gt;alpine:3.20&lt;/code&gt; 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.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where Ansible strains
&lt;/h2&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Debugging.&lt;/strong&gt; 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.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Performance.&lt;/strong&gt; 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.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Complex data structures.&lt;/strong&gt; 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.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Control flow.&lt;/strong&gt; 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.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Composition and testing.&lt;/strong&gt; 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.&lt;/p&gt;

&lt;h2&gt;
  
  
  One decision behind all of it
&lt;/h2&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;Each pressure point then has an ordinary answer in Python:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Complex logic is just code.&lt;/strong&gt; &lt;code&gt;if&lt;/code&gt;, comprehensions, functions, written next to the deploy and reviewable on their own terms — instead of nested &lt;code&gt;{% set %}&lt;/code&gt; blocks and chains of &lt;code&gt;regex_search&lt;/code&gt;, &lt;code&gt;ternary&lt;/code&gt; and &lt;code&gt;default&lt;/code&gt; filters that the next person cannot read.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Data structures are just data.&lt;/strong&gt; Dicts, sets and graphs you build, pass around and test directly, rather than coaxed out of a templating engine.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Control flow is real control flow, and your editor knows it.&lt;/strong&gt; 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.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Composition is &lt;code&gt;import&lt;/code&gt; and arguments.&lt;/strong&gt; 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.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Testing is &lt;code&gt;pytest&lt;/code&gt;.&lt;/strong&gt; 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.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The result is objects, not terminal output.&lt;/strong&gt; 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.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Ansible earns its adoption for
&lt;/h2&gt;

&lt;p&gt;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:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Check mode.&lt;/strong&gt; Ansible simulates execution without actually making any changes, so you can validate a configuration before deploying it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lockstep execution.&lt;/strong&gt; Ansible runs the same task on all target hosts and only proceeds to the next one after every host has finished the current one.&lt;/p&gt;

&lt;p&gt;An alternative that discards those two is not an alternative for configuration management. Reemote implements both. Check mode is the dry-run flag:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;plans&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;report&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;hosts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;inventory&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dry&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;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 &lt;code&gt;hello.py&lt;/code&gt; 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 &lt;code&gt;connection&lt;/code&gt; block are forwarded verbatim to &lt;a href="https://asyncssh.readthedocs.io/" rel="noopener noreferrer"&gt;asyncssh&lt;/a&gt;'s &lt;code&gt;connect()&lt;/code&gt;, 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.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reading the example again
&lt;/h2&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;The apply log is also where lockstep becomes visible. The dry-run plan is &lt;strong&gt;host-major&lt;/strong&gt; — both of demo0's operations, then both of demo1's — because a plan is one deploy read per host. The log is &lt;strong&gt;step-major&lt;/strong&gt;: &lt;code&gt;Write a greeting&lt;/code&gt; on demo0 and demo1, then &lt;code&gt;Record the host name&lt;/code&gt; 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 &lt;code&gt;demo0&lt;/code&gt; before &lt;code&gt;demo1&lt;/code&gt; 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.&lt;/p&gt;

&lt;p&gt;One detail worth noticing. The second operation writes different bytes to each host because &lt;code&gt;host.name&lt;/code&gt; is an ordinary Python value in an f-string — no templating dialect, no hostvar to look up — yet its two &lt;code&gt;$ scp&lt;/code&gt; 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.&lt;/p&gt;

&lt;p&gt;Each &lt;code&gt;run(...)&lt;/code&gt; starts its own throwaway container per host from &lt;code&gt;alpine:3.20&lt;/code&gt;, 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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;h2&gt;
  
  
  What migrating actually costs
&lt;/h2&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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 &lt;code&gt;ok&lt;/code&gt; rather than &lt;code&gt;changed&lt;/code&gt;. The following deploy maps task for task onto its Ansible equivalent:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;reemote&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;op&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;reemote&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;modules&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;apt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;files&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;systemd&lt;/span&gt;

&lt;span class="no"&gt;PAGE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"&amp;lt;!doctype html&amp;gt;&amp;lt;h1&amp;gt;Hello from staging&amp;lt;/h1&amp;gt;\n"&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nf"&gt;op&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;apt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;packages&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Install nginx"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;packages&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"nginx"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sudo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nf"&gt;op&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;files&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;install&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Write landing page"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="no"&gt;PAGE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dest&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/var/www/html/index.html"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"0644"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sudo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nf"&gt;op&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;systemd&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;service&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Run nginx"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;service&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"nginx"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;running&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;enabled&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sudo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Read that against the Ansible tasks it corresponds to and the differences are syntactic: a module becomes a function, a task name becomes a &lt;code&gt;name=&lt;/code&gt; argument, &lt;code&gt;become: true&lt;/code&gt; becomes &lt;code&gt;sudo=True&lt;/code&gt;, 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 &lt;code&gt;apt&lt;/code&gt;, &lt;code&gt;dnf&lt;/code&gt; and &lt;code&gt;apk&lt;/code&gt; through &lt;code&gt;files&lt;/code&gt;, &lt;code&gt;git&lt;/code&gt;, &lt;code&gt;systemd&lt;/code&gt;, &lt;code&gt;firewalld&lt;/code&gt;, &lt;code&gt;selinux&lt;/code&gt;, &lt;code&gt;mysql&lt;/code&gt; and &lt;code&gt;postgresql&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use it where it fits
&lt;/h2&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;




&lt;ul&gt;
&lt;li&gt;Documentation and full guide: &lt;a href="https://reemote.org/" rel="noopener noreferrer"&gt;https://reemote.org/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Source: &lt;a href="https://github.com/kimjarvis/reemote" rel="noopener noreferrer"&gt;https://github.com/kimjarvis/reemote&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;PyPI: &lt;code&gt;pip install reemote&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;License: EPL-2.0&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;F8010, &lt;em&gt;Stop Using Ansible for Everything&lt;/em&gt;, Medium — &lt;a href="https://medium.com/@f8010/stop-using-ansible-for-everything-7940cc22d74c" rel="noopener noreferrer"&gt;https://medium.com/@f8010/stop-using-ansible-for-everything-7940cc22d74c&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Terry Slattery, &lt;em&gt;Ansible limitations for network automation&lt;/em&gt;, TechTarget — &lt;a href="https://www.techtarget.com/news/Ansible-limitations-for-network-automation/864462/" rel="noopener noreferrer"&gt;https://www.techtarget.com/news/Ansible-limitations-for-network-automation/864462/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;The Ansible alternative you can actually migrate to&lt;/em&gt;, Reemote on Hashnode — &lt;a href="https://reemote.hashnode.dev/the-ansible-alternative-you-can-actually-migrate-to" rel="noopener noreferrer"&gt;https://reemote.hashnode.dev/the-ansible-alternative-you-can-actually-migrate-to&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>opensource</category>
      <category>showdev</category>
    </item>
    <item>
      <title>How Reemote Implements Ansible's Two Core Principles in Python</title>
      <dc:creator>Kim Jarvis</dc:creator>
      <pubDate>Sun, 29 Nov 2026 07:37:26 +0000</pubDate>
      <link>https://dev.to/kimbofab/how-reemote-implements-ansibles-two-core-principles-in-python-39em</link>
      <guid>https://dev.to/kimbofab/how-reemote-implements-ansibles-two-core-principles-in-python-39em</guid>
      <description>&lt;p&gt;Ansible is the canonical configuration management tool. Ansible relies on two core principles: dry run — check for changes before you apply them — and lockstep execution, where each operation completes on all hosts before the next one starts. The Reemote library implements Ansible's core principles in Python. Reemote is a pure Python library for configuration management that is very similar to Ansible.&lt;/p&gt;

&lt;p&gt;Let's look at an example that demonstrates both dry run and lockstep execution in Reemote.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it in under a minute (docker connector)
&lt;/h2&gt;

&lt;p&gt;Reemote ships a &lt;strong&gt;docker connector&lt;/strong&gt; that runs your deploy inside a local container, so you need neither a remote host nor an SSH key to see the two principles work. &lt;strong&gt;Docker or Podman must be installed locally&lt;/strong&gt; — the connector shells out to whichever CLI you name in the inventory, and there is no default. Two steps:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# 1. Install (Python 3.13+; pip works just as well as uv)&lt;/span&gt;
uv venv .venv &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;source&lt;/span&gt; .venv/bin/activate &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; uv pip install reemote

&lt;span class="c"&gt;# 2. Save the script below as hello.py, then run it&lt;/span&gt;
python hello.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The inventory holds &lt;strong&gt;two&lt;/strong&gt; hosts and the deploy has &lt;strong&gt;two&lt;/strong&gt; steps, so the run demonstrates lockstep as well as dry run: the first step has to finish on both hosts before the second step starts on either.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# hello.py&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;asyncio&lt;/span&gt;

&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;reemote&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;files&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;format_log&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;format_plan&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;op&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;run&lt;/span&gt;

&lt;span class="no"&gt;INVENTORY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="s2"&gt;"host"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"web1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"family"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Alpine"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"connection"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="s2"&gt;"connector"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"docker"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s2"&gt;"identifier"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"alpine:3.20"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s2"&gt;"docker_cmd"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"podman"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;   &lt;span class="c1"&gt;# or "docker"&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="s2"&gt;"host"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"web2"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"family"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Alpine"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"connection"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="s2"&gt;"connector"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"docker"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s2"&gt;"identifier"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"alpine:3.20"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s2"&gt;"docker_cmd"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"podman"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;   &lt;span class="c1"&gt;# or "docker"&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="c1"&gt;# Step 1: create the demo directory on every host.&lt;/span&gt;
    &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nf"&gt;op&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;files&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;directory&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Create the demo directory"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/tmp/reemote-demo"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"0755"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="c1"&gt;# Step 2: write a greeting into it -- runs only after step 1 has&lt;/span&gt;
    &lt;span class="c1"&gt;# finished on every host.&lt;/span&gt;
    &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nf"&gt;op&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;files&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;install&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Write a greeting"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Hello from reemote!\n"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;dest&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/tmp/reemote-demo/hello.txt"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"0644"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="c1"&gt;# Dry run: facts are gathered for real, nothing is mutated.&lt;/span&gt;
    &lt;span class="n"&gt;plans&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;INVENTORY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dry&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"== Dry run: what would change =="&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;format_plan&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;plans&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# Apply: the same deploy, executed against fresh containers.&lt;/span&gt;
    &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;report&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;INVENTORY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"\n== Applied: what changed =="&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="n"&gt;report&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;format_log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;report&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="n"&gt;asyncio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Reemote starts a throwaway &lt;code&gt;alpine:3.20&lt;/code&gt; container per host, previews both steps against both containers without touching them, then runs the same deploy for real against a second pair of containers, prints the resulting command log, and finally commits each container into a new image and removes it. Verified output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;== Dry run: what would change ==
web1: Create the demo directory [changed: /tmp/reemote-demo missing, will create]
web1: Write a greeting         [changed: content /tmp/reemote-demo/hello.txt is absent, will install]
web2: Create the demo directory [changed: /tmp/reemote-demo missing, will create]
web2: Write a greeting         [changed: content /tmp/reemote-demo/hello.txt is absent, will install]

== Applied: what changed ==
web1: Create the demo directory [changed: /tmp/reemote-demo missing, will create]
    $ mkdir -p /tmp/reemote-demo
    $ chmod 755 /tmp/reemote-demo
web2: Create the demo directory [changed: /tmp/reemote-demo missing, will create]
    $ mkdir -p /tmp/reemote-demo
    $ chmod 755 /tmp/reemote-demo
web1: Write a greeting         [changed: content /tmp/reemote-demo/hello.txt is absent, will install]
    $ scp &amp;lt;files install&amp;gt; -&amp;gt; /tmp/reemote-install-00b39035d25048db/content
    $ sh -c 'mkdir -p /tmp/reemote-demo &amp;amp;&amp;amp; cp /tmp/reemote-install-00b39035d25048db/content /tmp/reemote-demo/hello.txt &amp;amp;&amp;amp; chmod 644 /tmp/reemote-demo/hello.txt &amp;amp;&amp;amp; rm -rf /tmp/reemote-install-00b39035d25048db'
web2: Write a greeting         [changed: content /tmp/reemote-demo/hello.txt is absent, will install]
    $ scp &amp;lt;files install&amp;gt; -&amp;gt; /tmp/reemote-install-00b39035d25048db/content
    $ sh -c 'mkdir -p /tmp/reemote-demo &amp;amp;&amp;amp; cp /tmp/reemote-install-00b39035d25048db/content /tmp/reemote-demo/hello.txt &amp;amp;&amp;amp; chmod 644 /tmp/reemote-demo/hello.txt &amp;amp;&amp;amp; rm -rf /tmp/reemote-install-00b39035d25048db'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every dry-run line reappears in the apply log verbatim, with the shell commands appended beneath it — that is the point. The plan the dry run showed you is the plan the apply executed. Each &lt;code&gt;run(...)&lt;/code&gt; starts its own throwaway containers from &lt;code&gt;alpine:3.20&lt;/code&gt;, so both phases observe the same empty state; the demo is about the two principles, not idempotence.&lt;/p&gt;

&lt;p&gt;Look closely, though, and the two blocks are ordered differently. The &lt;strong&gt;dry-run plan is host-major&lt;/strong&gt;: &lt;code&gt;web1&lt;/code&gt;'s two steps, then &lt;code&gt;web2&lt;/code&gt;'s two. The &lt;strong&gt;apply log is step-major&lt;/strong&gt;: step 1 on both hosts, then step 2 on both. Same four lines, two orders — and the apply log's order is lockstep execution made visible. Both hosts create the directory before either host writes the greeting. The rest of this article is about how each of those two orderings is produced.&lt;/p&gt;

&lt;p&gt;The inventory is a plain Python list of host dictionaries carrying connection information. Reemote is agentless: for SSH targets the connection block configures an &lt;a href="https://asyncssh.readthedocs.io/" rel="noopener noreferrer"&gt;asyncssh&lt;/a&gt; connection.&lt;/p&gt;

&lt;p&gt;A deploy is a generator that yields operation requests in order — here, a &lt;code&gt;files.directory&lt;/code&gt; then a &lt;code&gt;files.install&lt;/code&gt;. In general these operations map closely to their Ansible counterparts, so the vocabulary will be familiar.&lt;/p&gt;

&lt;p&gt;The following deploy installs and starts nginx:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nf"&gt;op&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;apt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;packages&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Install nginx"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;packages&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"nginx"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sudo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nf"&gt;op&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;files&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;install&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Write landing page"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="no"&gt;PAGE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dest&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/var/www/html/index.html"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"0644"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sudo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nf"&gt;op&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;systemd&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;service&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Run nginx"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;service&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"nginx"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;running&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;enabled&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sudo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Point that deploy at your staging inventory with &lt;code&gt;dry=True&lt;/code&gt; 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 &lt;code&gt;dry=True&lt;/code&gt; to apply.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;run(...)&lt;/code&gt; 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.&lt;/p&gt;

&lt;h2&gt;
  
  
  How dry run is implemented
&lt;/h2&gt;

&lt;p&gt;"Every dry-run line reappears in the apply log verbatim." That is easy to promise and surprisingly hard to earn, so it is worth being precise about what makes it true.&lt;/p&gt;

&lt;h3&gt;
  
  
  The problem
&lt;/h3&gt;

&lt;p&gt;A configuration change against production is scary, and the usual antidotes are weak. Echoing the shell commands you &lt;em&gt;think&lt;/em&gt; you would run shows your intent, not the effect on a host whose real state you never read. A separate "check mode" bolted onto a tool is a second code path that drifts from the one that actually applies, so the preview lies in exactly the edge cases you hoped it would catch. What you want is a guarantee: the thing you previewed and the thing you executed are computed by the &lt;em&gt;same&lt;/em&gt; code, against the &lt;em&gt;same&lt;/em&gt; live facts, and differ only in whether the final commands get sent.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why it is interesting
&lt;/h3&gt;

&lt;p&gt;Reemote earns the "same line" property structurally, not by discipline. There is no separate dry-run implementation to keep in sync, because a dry run is not a different mode — it is the &lt;em&gt;first half&lt;/em&gt; of the ordinary run, stopped before it sends anything.&lt;/p&gt;

&lt;h3&gt;
  
  
  The solution
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;run(inventory, deploy, dry=True)&lt;/code&gt; validates the inventory, materializes a &lt;code&gt;Host&lt;/code&gt; per entry, and calls &lt;code&gt;run_prepare(hosts, deploy, planning=dry)&lt;/code&gt;. When &lt;code&gt;dry&lt;/code&gt; is set it returns &lt;code&gt;(plans, None, hosts)&lt;/code&gt; and never calls &lt;code&gt;run_apply&lt;/code&gt; at all. The &lt;code&gt;None&lt;/code&gt; in the report slot is why the example guards with &lt;code&gt;assert report is not None&lt;/code&gt; before printing &lt;code&gt;format_log(report)&lt;/code&gt;: a dry run produces a plan, not a log.&lt;/p&gt;

&lt;p&gt;The prepare phase is where the guarantee lives. For each host, &lt;code&gt;_prepare_host&lt;/code&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Creates a &lt;strong&gt;per-host, per-phase&lt;/strong&gt; &lt;code&gt;FactCache&lt;/code&gt; tagged &lt;code&gt;phase="prepare"&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Drains the deploy generator into a list of &lt;code&gt;OperationRequest&lt;/code&gt; objects. A counter tallies every &lt;code&gt;op(...)&lt;/code&gt; the body built against every one it actually yielded, so a body that forgets a &lt;code&gt;yield&lt;/code&gt; fails here — before anything is sent — with a &lt;code&gt;DeployRequestError&lt;/code&gt; naming the host.&lt;/li&gt;
&lt;li&gt;For each request, calls &lt;code&gt;materialize(...)&lt;/code&gt; and records a &lt;code&gt;PlannedOperation(request, changed, reason, commands)&lt;/code&gt;. A request whose &lt;code&gt;when&lt;/code&gt; guard fails on this host is recorded &lt;code&gt;skipped&lt;/code&gt; without reading a single fact — a guard exists precisely to keep an inapplicable operation off a host that could not even answer its facts.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Operations are generators, and materializing one never sends a command.&lt;/strong&gt; An operation is an &lt;em&gt;async generator function&lt;/em&gt;; &lt;code&gt;materialize&lt;/code&gt; drives it to completion and collects what it yields:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;ctx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;OpContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;facts&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;cache&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;planning&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;planning&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;commands&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;cmd&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;cmd&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;func&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;kwargs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;commands&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Running the generator &lt;em&gt;reads facts&lt;/em&gt; and &lt;em&gt;builds command descriptors&lt;/em&gt;; it does not execute them. The descriptors are collected into a tuple and returned. Nothing in the prepare path calls &lt;code&gt;send_command&lt;/code&gt; — that happens only later, inside &lt;code&gt;run_apply&lt;/code&gt;. So a dry run genuinely touches the host (facts are gathered over the wire) but genuinely mutates nothing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Facts are cached and compared — that is where&lt;/strong&gt; &lt;code&gt;changed&lt;/code&gt; &lt;strong&gt;comes from.&lt;/strong&gt; An operation reads current state through &lt;code&gt;ctx.facts.get(FactClass, *args)&lt;/code&gt;. &lt;code&gt;FactCache.get&lt;/code&gt; memoizes on &lt;code&gt;(fact_cls, args, sorted kwargs)&lt;/code&gt;, and on a miss it awaits &lt;code&gt;fact_cls.process(host, ...)&lt;/code&gt; — a coroutine, because a fact gathers its value by running shell commands over asyncssh (or through the docker connector's overridden transport). Facts are typed data, never scraped strings: &lt;code&gt;FileExists.process&lt;/code&gt; runs &lt;code&gt;test -e&lt;/code&gt;, re-asking elevated when a parent directory denies the login user traversal; &lt;code&gt;FileContents.process&lt;/code&gt; cats a file, falling back to an elevated read for a mode the login user cannot open.&lt;/p&gt;

&lt;p&gt;The operation compares the fact it read against the state it wants and sets &lt;code&gt;ctx.changed&lt;/code&gt; and &lt;code&gt;ctx.reason&lt;/code&gt; itself. This is "check for changes before apply" expressed as ordinary Python. Here is the real decision inside &lt;code&gt;files.install&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;current&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;facts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;FileContents&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dest&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;current&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;reason&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"content already up to date ({dest})"&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt;                              &lt;span class="c1"&gt;# no change -&amp;gt; yields no commands&lt;/span&gt;
&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;changed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;
&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;reason&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"content {dest} differs, will install"&lt;/span&gt;
              &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;current&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;
              &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"content {dest} is absent, will install"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nc"&gt;InstallSpoolCommand&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dest&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;spool&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;          &lt;span class="c1"&gt;# the scp line&lt;/span&gt;
&lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nc"&gt;InstallCommand&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;spool&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;spool&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dest&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;dest&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;mode_int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# the sh -c line&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On a fresh &lt;code&gt;alpine:3.20&lt;/code&gt; container &lt;code&gt;/tmp/reemote-demo/hello.txt&lt;/code&gt; does not exist, so &lt;code&gt;FileContents&lt;/code&gt; reads back &lt;code&gt;None&lt;/code&gt;, the comparison fails, and the operation sets &lt;code&gt;reason="content /tmp/reemote-demo/hello.txt is absent, will install"&lt;/code&gt; and yields two descriptors. That reason string is the exact text in the example's dry-run line, and those two descriptors are the exact &lt;code&gt;scp&lt;/code&gt; and &lt;code&gt;sh -c&lt;/code&gt; lines under it in the apply log. They are the same strings because they are produced by the same &lt;code&gt;materialize&lt;/code&gt; call — run once in prepare, once in apply.&lt;/p&gt;

&lt;p&gt;The one place the two runs differ is the &lt;code&gt;planning&lt;/code&gt; flag threaded onto &lt;code&gt;OpContext&lt;/code&gt; (set from &lt;code&gt;dry&lt;/code&gt;). A full run keeps its prepare &lt;strong&gt;strict&lt;/strong&gt;: an operation whose input does not exist yet raises, so a typo fails before a single command is sent. A &lt;code&gt;dry=True&lt;/code&gt; prepare runs in &lt;strong&gt;planning&lt;/strong&gt; mode, which lets an operation whose input a &lt;em&gt;later&lt;/em&gt; request of the same deploy would create — a spool a subsequent step extracts, say — report a plan line instead of raising on state that has not been produced yet.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Changes are reported as data, then rendered.&lt;/strong&gt; Each &lt;code&gt;PlannedOperation&lt;/code&gt; carries &lt;code&gt;changed&lt;/code&gt;, &lt;code&gt;reason&lt;/code&gt; and the &lt;code&gt;commands&lt;/code&gt; tuple. &lt;code&gt;format_plan&lt;/code&gt; renders one line per operation — &lt;code&gt;host: name [changed|no change|skipped: reason]&lt;/code&gt; — and deliberately omits the &lt;code&gt;$&lt;/code&gt; command lines; those belong to &lt;code&gt;format_log&lt;/code&gt;, which renders the apply-phase report. But the plan is not only text: &lt;code&gt;run&lt;/code&gt; returns it as &lt;code&gt;dict[str, list[PlannedOperation]]&lt;/code&gt;, structured objects you can assert on.&lt;/p&gt;

&lt;h3&gt;
  
  
  What follows from the solution
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;In the example&lt;/strong&gt;, &lt;code&gt;run(INVENTORY, deploy, dry=True)&lt;/code&gt; starts a throwaway container per host, reads &lt;code&gt;/tmp/reemote-demo&lt;/code&gt; (absent) and &lt;code&gt;/tmp/reemote-demo/hello.txt&lt;/code&gt; (absent) as real facts over the connector, records both steps as &lt;code&gt;[changed]&lt;/code&gt; for &lt;code&gt;web1&lt;/code&gt; and &lt;code&gt;web2&lt;/code&gt;, sends nothing, commits and removes both containers, and returns the plans with &lt;code&gt;report=None&lt;/code&gt;. &lt;code&gt;format_plan&lt;/code&gt; prints the four lines host-major — each host's two steps together — because it walks &lt;code&gt;plans.items()&lt;/code&gt;, one host at a time.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Because a dry run &lt;em&gt;is&lt;/em&gt; the prepare phase of the real run, the preview cannot drift from the apply: same &lt;code&gt;materialize&lt;/code&gt;, same operations, same reason strings. The plan line reappears verbatim as the apply log's entry line, with the commands it built appended beneath it.&lt;/p&gt;

&lt;p&gt;Because the plan is a returned value, you can gate on it: assert in CI that no host reports &lt;code&gt;changed&lt;/code&gt;, attach the diff to a pull request, or refuse a rollout when a host you expected to be clean is not.&lt;/p&gt;

&lt;p&gt;The catch is that a dry run is only as faithful as the deploy is deterministic. The driver re-invokes the generator for the apply phase and compares each pulled request against the plan; branch on a live fact, or build a fresh value per pass (&lt;code&gt;datetime.now()&lt;/code&gt;, &lt;code&gt;random&lt;/code&gt;, an inline &lt;code&gt;lambda&lt;/code&gt;), and the two sequences diverge — which raises &lt;code&gt;DeterminismError&lt;/code&gt; before anything is sent. Dry run does not just tolerate pure, functional deploys; it rewards them, and the determinism guard enforces them.&lt;/p&gt;

&lt;h2&gt;
  
  
  How lockstep execution is implemented
&lt;/h2&gt;

&lt;p&gt;The dry-run plan walked each host's work in turn. The apply log did the opposite: it ran step 1 on both hosts, then step 2 on both. That step-major ordering is not a rendering choice — it is the shape of the execution, and it comes from a single join.&lt;/p&gt;

&lt;h3&gt;
  
  
  The problem
&lt;/h3&gt;

&lt;p&gt;With N hosts across a network you want two things that pull in opposite directions. You want &lt;strong&gt;concurrency&lt;/strong&gt;: the network wait for host A should overlap the wait for host B, not run after it. And you want &lt;strong&gt;cross-host ordering&lt;/strong&gt;: operation &lt;em&gt;i&lt;/em&gt; finishes everywhere before operation &lt;em&gt;i+1&lt;/em&gt; starts anywhere. Some deploys depend on that ordering — a repository before the package it provides, a schema migration before the app that reads the new column, a directory before the file that lands in it.&lt;/p&gt;

&lt;p&gt;The naive answers each give up one of the two. "One task per host, let them race" gets concurrency but loses ordering: a fast host is writing the config file while a slow one is still installing the package. "One host at a time, top to bottom" gets ordering but throws away concurrency and runs the fleet serially.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why it is interesting
&lt;/h3&gt;

&lt;p&gt;The resolution has to hold under real networks, where hosts finish the same operation at wildly different times. The barrier cannot be "wait a moment"; it has to be "wait for &lt;em&gt;every&lt;/em&gt; host, whoever is slowest, before anyone advances."&lt;/p&gt;

&lt;h3&gt;
  
  
  The solution
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;run_apply(runtimes, plans)&lt;/code&gt; keeps a list of &lt;code&gt;active&lt;/code&gt; hosts and loops in three steps:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;active&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;rt&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;rt&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;runtimes&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;rt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;done&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="n"&gt;active&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="c1"&gt;# Step 1 -- pull the next request from every active host (synchronous).&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;rt&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;active&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;rt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;fact_cache&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;FactCache&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;phase&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"apply"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   &lt;span class="c1"&gt;# fresh per step&lt;/span&gt;
        &lt;span class="n"&gt;item&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;next&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;generator&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;                           &lt;span class="c1"&gt;# StopIteration -&amp;gt; rt.done&lt;/span&gt;
        &lt;span class="n"&gt;rt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;current_request&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt;
    &lt;span class="c1"&gt;# ... compare each pulled request against the plan; DeterminismError on drift ...&lt;/span&gt;

    &lt;span class="c1"&gt;# Step 2 -- execute this step on all active hosts at once. The gather join&lt;/span&gt;
    &lt;span class="c1"&gt;# IS the barrier: no host pulls request i+1 until every step-i has returned.&lt;/span&gt;
    &lt;span class="n"&gt;results&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;asyncio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;gather&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;_apply_host_step&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;rt&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;active&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;return_exceptions&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="c1"&gt;# ... append log entries; aggregate PrivilegeError; re-raise anything else ...&lt;/span&gt;

    &lt;span class="c1"&gt;# Step 3 -- drop finished hosts.&lt;/span&gt;
    &lt;span class="n"&gt;active&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;rt&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;rt&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;active&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;rt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;done&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Operations are async, and the concurrency is only across hosts.&lt;/strong&gt; Inside &lt;code&gt;_apply_host_step&lt;/code&gt;, the request is re-materialized against the fresh cache and — only when &lt;code&gt;ctx.changed&lt;/code&gt; is true — its commands are sent &lt;em&gt;sequentially&lt;/em&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;commands&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;materialize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;rt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;fact_cache&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;changed&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;cmd&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;commands&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;send_command&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cmd&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sudo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;sudo&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;su&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;su&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;doas&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;doas&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So a single host's commands stay in order (some sequences are order-dependent), while &lt;code&gt;asyncio.gather&lt;/code&gt; overlaps the hosts. The gather's join is the barrier: the loop cannot reach step 1 of the next iteration — cannot pull request &lt;em&gt;i+1&lt;/em&gt; for anyone — until every &lt;code&gt;_apply_host_step&lt;/code&gt; coroutine for step &lt;em&gt;i&lt;/em&gt; has returned. An operation is an async-generator function (&lt;code&gt;materialize&lt;/code&gt; refuses anything else with &lt;code&gt;OperationError&lt;/code&gt;); facts await asyncssh; &lt;code&gt;send_command&lt;/code&gt; is a coroutine. The deploy script itself stays a plain synchronous generator — you never write &lt;code&gt;async&lt;/code&gt; in a deploy. All the asynchrony lives in the runtime.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;asyncssh is the wire.&lt;/strong&gt; A real &lt;code&gt;Host&lt;/code&gt; owns a lazily-established asyncssh connection, and &lt;code&gt;send_command&lt;/code&gt; dispatches each descriptor by kind: a &lt;code&gt;TransferCommand&lt;/code&gt; copies over the connection's scp channel (&lt;code&gt;cmd.transfer&lt;/code&gt;), a &lt;code&gt;WaitCommand&lt;/code&gt; polls a fact (&lt;code&gt;cmd.wait&lt;/code&gt;), and anything else runs its shell through &lt;code&gt;host.run_shell&lt;/code&gt; or, when elevated, &lt;code&gt;host.run_shell_privileged&lt;/code&gt;. The docker connector is the same &lt;code&gt;Host&lt;/code&gt; with the transport seams overridden — &lt;code&gt;connect&lt;/code&gt;, &lt;code&gt;_run_shell&lt;/code&gt;, &lt;code&gt;upload_file&lt;/code&gt;, &lt;code&gt;download_file&lt;/code&gt;, &lt;code&gt;aclose&lt;/code&gt; — to shell out to &lt;code&gt;docker&lt;/code&gt;/&lt;code&gt;podman&lt;/code&gt; instead, which is why the identical driver code produces the example's &lt;code&gt;mkdir&lt;/code&gt;/&lt;code&gt;scp&lt;/code&gt;/&lt;code&gt;sh -c&lt;/code&gt; lines against a local container.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Connectivity errors are thrown — and aggregated.&lt;/strong&gt; Because a step's hosts connect concurrently, several can fail at once, and reporting only the first is useless when you need to fix all of them. &lt;code&gt;run_prepare&lt;/code&gt; gathers with &lt;code&gt;return_exceptions=True&lt;/code&gt;, collects each host's &lt;code&gt;HostConnectionError&lt;/code&gt;, and raises &lt;code&gt;HostConnectionError.aggregate(...)&lt;/code&gt; naming every unreachable host together. &lt;code&gt;run_apply&lt;/code&gt; does the same for &lt;code&gt;PrivilegeError&lt;/code&gt;, so one bad &lt;code&gt;sudo_password&lt;/code&gt; is reported across the whole fleet at once. A non-zero command exit is different: it raises &lt;code&gt;CommandError&lt;/code&gt; and propagates fail-fast, aborting the run rather than reporting a broken step as applied.&lt;/p&gt;

&lt;h3&gt;
  
  
  What follows from the solution
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;In the example&lt;/strong&gt;, read the apply log straight down the page:&lt;/p&gt;


&lt;pre class="highlight plaintext"&gt;&lt;code&gt;web1: Create the demo directory ...   (step 1)
web2: Create the demo directory ...   (step 1)
web1: Write a greeting ...            (step 2)
web2: Write a greeting ...            (step 2)
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;&lt;code&gt;web1&lt;/code&gt; and &lt;code&gt;web2&lt;/code&gt; run step 1 &lt;em&gt;concurrently&lt;/em&gt;; the gather join holds step 2 until both have returned, so neither host writes the greeting until both have created the directory. The log lists &lt;code&gt;web1&lt;/code&gt; before &lt;code&gt;web2&lt;/code&gt; within each step not because &lt;code&gt;web1&lt;/code&gt; ran first — they overlapped — but because &lt;code&gt;asyncio.gather&lt;/code&gt; returns results in input order. That is the whole fleet advancing one operation at a time, made visible.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Two further properties fall out of the same loop:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Deterministic logs.&lt;/strong&gt; &lt;code&gt;asyncio.gather&lt;/code&gt; preserves input order, so the report reads the same way every run regardless of the order hosts finish on the wire. Determinism is a property of the schedule, not of the network.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;"Act, then read" within a host.&lt;/strong&gt; The &lt;code&gt;FactCache&lt;/code&gt; is rebuilt at every step, so a generator-body fact read sees the effect of the operations before it. Step 2's &lt;code&gt;files.install&lt;/code&gt; observes the directory step 1 created because the cache it reads through is fresh for step 2. Re-materializing also means each step re-checks its governing fact against &lt;em&gt;current&lt;/em&gt; state, so a host that converged between plan and apply reports &lt;code&gt;[no change]&lt;/code&gt; and sends nothing.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Because every host finishes step &lt;em&gt;i&lt;/em&gt; before step &lt;em&gt;i+1&lt;/em&gt;, the &lt;code&gt;ApplyReport&lt;/code&gt; is a consistent per-step view of the fleet — which is what makes handlers possible without a &lt;code&gt;notify&lt;/code&gt; keyword. Read the entries whose &lt;code&gt;changed&lt;/code&gt; is true (&lt;code&gt;changed_hosts&lt;/code&gt;) and drive a second deploy that restarts a service on exactly those hosts.&lt;/p&gt;

&lt;p&gt;The trade is explicit: the slowest host in a step gates the fleet's advance to the next. That is the same bargain Ansible's default linear strategy strikes — a little latency bought back as a schedule you can reason about, one operation at a time, across every host at once.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;Ansible's two core principles are not features bolted onto Reemote; they fall out of one execution model.&lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;dry run&lt;/strong&gt; is simply the prepare phase of the ordinary run, stopped before it sends anything. Operations are async generators that read cached facts and compare them against the state you described, so &lt;code&gt;changed&lt;/code&gt; and its reason are computed by the same code whether you preview or apply. The plan line and the apply-log line are the same line because they are the same string, produced by the same &lt;code&gt;materialize&lt;/code&gt; call — there is no second implementation free to drift.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lockstep&lt;/strong&gt; is a single &lt;code&gt;asyncio.gather&lt;/code&gt; join in the apply loop. Every host runs its Nth operation concurrently, and the join holds the fleet until the slowest host returns before anyone pulls operation N+1: concurrency across hosts, sequence within a host, and a deterministic log because gather preserves input order. That is why the apply log reads step-major — one operation across all hosts, then the next — while the plan reads host-major. The same loop rebuilds each host's fact cache every step, so an operation re-checks the world as it now is, and a connectivity or privilege failure is aggregated across the fleet rather than surfacing one host at a time.&lt;/p&gt;

&lt;p&gt;The result behaves like Ansible — preview before apply, one operation across all hosts at a time — but hands back its plans and reports as ordinary Python objects you can assert on, gate a rollout on, or feed into a second deploy. If you have ever wanted configuration management that shows you the change before it makes it, in the same language as the rest of your stack, Reemote is worth a look.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Documentation and full guide: &lt;a href="https://reemote.org/" rel="noopener noreferrer"&gt;https://reemote.org/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Source: &lt;a href="https://github.com/kimjarvis/reemote" rel="noopener noreferrer"&gt;https://github.com/kimjarvis/reemote&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;PyPI: &lt;code&gt;pip install reemote&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;License: EPL-2.0&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>showdev</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Converting Ansible to Python</title>
      <dc:creator>Kim Jarvis</dc:creator>
      <pubDate>Fri, 27 Nov 2026 17:54:02 +0000</pubDate>
      <link>https://dev.to/kimbofab/converting-ansible-to-python-273c</link>
      <guid>https://dev.to/kimbofab/converting-ansible-to-python-273c</guid>
      <description>&lt;p&gt;Ansible has well-known shortcomings, yet teams have lacked a direct migration path away from it. Alternatives like Puppet, Salt, and Chef use structurally different models, creating a high barrier to conversion. Rather than porting an Ansible playbook, engineers typically rewrite it from scratch against a different paradigm—often at considerable cost.&lt;/p&gt;

&lt;p&gt;Converting Ansible workflows to Python offers more than familiarity with a widely used DevOps language. Tools like Pulumi already bring infrastructure provisioning into Python, and a native Python configuration management library complements that stack. Ideally, teams can provision and configure infrastructure in the same language.&lt;/p&gt;

&lt;p&gt;Reemote is a pure Python configuration management library designed to bridge that gap. It supports Ansible-style check mode, simulating execution without applying changes so you can validate configurations before deployment. It also preserves Ansible's lockstep execution model: it runs each task across all target hosts and advances to the next task only after every host finishes the current one.&lt;/p&gt;

&lt;p&gt;Because Reemote closely mirrors Ansible's mental model, converting an Ansible role into a Python program is straightforward—supported by a dedicated AI skill for the translation. The Reemote repository includes more than 40 examples of Ansible Galaxy roles converted to Python, including many of Jeff Geerling's canonical roles.&lt;/p&gt;

</description>
      <category>showdev</category>
      <category>opensource</category>
    </item>
    <item>
      <title>The Ansible alternative you can actually migrate to</title>
      <dc:creator>Kim Jarvis</dc:creator>
      <pubDate>Wed, 25 Nov 2026 17:07:47 +0000</pubDate>
      <link>https://dev.to/kimbofab/the-ansible-alternative-you-can-actually-migrate-to-56pn</link>
      <guid>https://dev.to/kimbofab/the-ansible-alternative-you-can-actually-migrate-to-56pn</guid>
      <description>&lt;p&gt;Ansible has many shortcomings, but until now there has not been an alternative that is simple to migrate to. Ansible alternatives such as Puppet, Salt and Chef are structurally different from Ansible, which is a barrier to migration: nobody ports an Ansible playbook to Puppet, they rewrite it against a different model of the world. Reemote is a Python configuration-management library that is very similar to Ansible. Reemote is so similar to Ansible that it is possible to migrate existing Ansible roles into Python.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Ansible is bad at, and what Python gives back
&lt;/h2&gt;

&lt;p&gt;Ansible's shortcomings mostly follow from one decision: configuration is written in a data-serialization format with a templating dialect bolted on, rather than in a programming language. Each cost has an ordinary Python answer:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Complex logic is difficult to express in Jinja2.&lt;/strong&gt; Interpolating a value into a config file is what the templating language is good at; filtering a host's interfaces to pick a listen address, merging per-environment defaults, or computing a package list from the target's release is not. That logic ends up as nested &lt;code&gt;{% set %}&lt;/code&gt; blocks and chains of &lt;code&gt;regex_search&lt;/code&gt;, &lt;code&gt;ternary&lt;/code&gt; and &lt;code&gt;default&lt;/code&gt; filters that the next person cannot read. In Python it is just code — &lt;code&gt;if&lt;/code&gt;, comprehensions, functions — written next to the deploy and reviewable on its own terms.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Your editor does not know your YAML.&lt;/strong&gt; No go-to-definition on a task, no rename across usages, no check that a module argument is spelled correctly; a typo surfaces at runtime, on the target. Python gives you imports, a type checker, a linter and completion, so the same mistakes are caught before the deploy runs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Composition is a directory-layout convention.&lt;/strong&gt; Roles include other roles by name, and variables flow through precedence rules that have to be remembered rather than read. Python composes with &lt;code&gt;import&lt;/code&gt; and function arguments: a reusable block of configuration is a function you can call with named arguments from another file.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The result is terminal output.&lt;/strong&gt; What changed, on which host and why is printed for a human, so a program that needs to know parses stdout. A Reemote deploy returns the plan and the report as objects — changed flags, reasons, the exact commands sent — that you can assert on, log to a database, or gate a rollout on.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tests need a toolchain of their own.&lt;/strong&gt; Molecule, testinfra and ansible-lint exist because a playbook cannot be imported and exercised directly the way a module can. A deploy is a generator, so the test opens by asserting on the requests it yields; the shipped role tests run a whole deploy twice against a simulated host, with no server involved.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;None of these are arguments about whether Ansible works. It does, at scale, for years. They are the ceiling on how far the format can be pushed — and every one of them is a solved problem in the language most automation teams already use.&lt;/p&gt;

&lt;h2&gt;
  
  
  Ansible's core execution mechanisms
&lt;/h2&gt;

&lt;p&gt;The costs above are all about how a deploy is written, composed and &lt;em&gt;tested&lt;/em&gt;. What Ansible earns its adoption for is what happens when it runs — and those guarantees are the ones a migration cannot afford to lose.&lt;/p&gt;

&lt;p&gt;Ansible's core execution mechanisms are:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Check mode.&lt;/strong&gt; Ansible simulates the execution without actually making any changes, allowing you to validate configuration before deployment.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lockstep execution.&lt;/strong&gt; Ansible executes the same task on all target hosts and only proceeds to the next task after all hosts have completed the current task.&lt;/p&gt;

&lt;p&gt;Reemote implements both lockstep execution and check mode. To run a deploy in check mode, add the dry-run flag:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;plans&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;report&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;hosts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;inventory&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dry&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You get back a plan — the operations that would change something, per host, with the reason each one is marked changed — and nothing on any host is touched. Lockstep is not a mode you switch on; it is how the runner works. The apply phase advances one deploy generator per host in step, and each step has a barrier: no host moves on to the next operation until every host has finished the current one. Both of the mechanisms that make Ansible safe to run against production are therefore already there before you migrate a single task.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it in under a minute (docker connector)
&lt;/h2&gt;

&lt;p&gt;Seeing both phases needs a target, and Reemote lets you pick a cheap one. It ships a &lt;strong&gt;docker connector&lt;/strong&gt; 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. &lt;strong&gt;Docker or Podman must be installed locally&lt;/strong&gt; — the connector shells out to whichever CLI you name in the inventory, and there is no default. Two steps:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# 1. Install (Python 3.13+; pip works just as well as uv)&lt;/span&gt;
uv venv .venv &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;source&lt;/span&gt; .venv/bin/activate &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; uv pip install reemote

&lt;span class="c"&gt;# 2. Save the script below as hello.py, then run it&lt;/span&gt;
python hello.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# hello.py&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;asyncio&lt;/span&gt;

&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;reemote&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;files&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;format_log&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;format_plan&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;op&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;run&lt;/span&gt;

&lt;span class="no"&gt;INVENTORY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="s2"&gt;"host"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"demo"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"family"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Alpine"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"connection"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="s2"&gt;"connector"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"docker"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"identifier"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"alpine:3.20"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"docker_cmd"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"podman"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;   &lt;span class="c1"&gt;# or "docker"&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nf"&gt;op&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;files&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;install&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Write a greeting"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Hello from reemote!\n"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;dest&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/tmp/reemote-hello.txt"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"0644"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="c1"&gt;# Dry run: facts are gathered for real, nothing is mutated.&lt;/span&gt;
    &lt;span class="n"&gt;plans&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;INVENTORY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dry&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"== Dry run: what would change =="&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;format_plan&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;plans&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# Apply: the same deploy, executed against a fresh container.&lt;/span&gt;
    &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;report&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;INVENTORY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"\n== Applied: what changed =="&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="n"&gt;report&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;format_log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;report&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="n"&gt;asyncio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Reemote starts a throwaway &lt;code&gt;alpine:3.20&lt;/code&gt; 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:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;== 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 &amp;lt;files install&amp;gt; -&amp;gt; /tmp/reemote-install-2e52d4f8373a608a/content
    $ sh -c 'mkdir -p /tmp &amp;amp;&amp;amp; cp /tmp/reemote-install-2e52d4f8373a608a/content /tmp/reemote-hello.txt &amp;amp;&amp;amp; chmod 644 /tmp/reemote-hello.txt &amp;amp;&amp;amp; rm -rf /tmp/reemote-install-2e52d4f8373a608a'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;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 &lt;code&gt;run(...)&lt;/code&gt; starts its own throwaway container from &lt;code&gt;alpine:3.20&lt;/code&gt;, so both phases observe the same absent file; the demo is about the two-phase pattern, not idempotence.&lt;/p&gt;

&lt;p&gt;The inventory is a plain Python list of host dictionaries carrying connection information. Reemote is agentless: for SSH targets the options in that block are forwarded to &lt;a href="https://asyncssh.readthedocs.io/" rel="noopener noreferrer"&gt;asyncssh&lt;/a&gt;'s &lt;code&gt;connect()&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Deploys are generators, and the vocabulary is familiar
&lt;/h2&gt;

&lt;p&gt;A deploy is a generator that yields operation requests in order — in the &lt;code&gt;hello.py&lt;/code&gt; above, a single &lt;code&gt;files.install&lt;/code&gt;. In general these operations map closely to their Ansible counterparts, so the vocabulary will be familiar.&lt;/p&gt;

&lt;p&gt;The following deploy installs and starts nginx:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;reemote&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;modules&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;apt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;files&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;systemd&lt;/span&gt;

&lt;span class="no"&gt;PAGE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"&amp;lt;!doctype html&amp;gt;&amp;lt;h1&amp;gt;Hello from staging&amp;lt;/h1&amp;gt;\n"&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nf"&gt;op&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;apt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;packages&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Install nginx"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;packages&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"nginx"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sudo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nf"&gt;op&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;files&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;install&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Write landing page"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="no"&gt;PAGE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dest&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/var/www/html/index.html"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"0644"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sudo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nf"&gt;op&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;systemd&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;service&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Run nginx"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;service&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"nginx"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;running&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;enabled&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sudo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Read that against the Ansible tasks it corresponds to and the only differences are syntactic: a module becomes a function, a task name becomes a &lt;code&gt;name=&lt;/code&gt; argument, &lt;code&gt;become: true&lt;/code&gt; becomes &lt;code&gt;sudo=True&lt;/code&gt;, and a list of tasks becomes a generator that yields them.&lt;/p&gt;

&lt;p&gt;Point that deploy at your staging inventory with &lt;code&gt;dry=True&lt;/code&gt; 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 &lt;code&gt;dry=True&lt;/code&gt; to apply.&lt;/p&gt;

&lt;p&gt;Ansible offers a wide range of modules for package management and services. Reemote offers modules covering package management, files and version control, services, firewalls, system configuration, security, databases and containers — twenty-four of them, from &lt;code&gt;apt&lt;/code&gt;, &lt;code&gt;dnf&lt;/code&gt; and &lt;code&gt;apk&lt;/code&gt; through &lt;code&gt;files&lt;/code&gt;, &lt;code&gt;git&lt;/code&gt;, &lt;code&gt;systemd&lt;/code&gt;, &lt;code&gt;firewalld&lt;/code&gt;, &lt;code&gt;sysctl&lt;/code&gt;, &lt;code&gt;selinux&lt;/code&gt;, &lt;code&gt;mysql&lt;/code&gt;, &lt;code&gt;postgresql&lt;/code&gt; and &lt;code&gt;lxd&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Both the syntax and the semantics of Reemote operations are similar, and in many cases identical, to Ansible. Semantics matter more than syntax here: an operation reads the current state of the host, compares it against the state you described, and emits commands only when there is a real difference. That is why a second run of the nginx deploy above, against the same host, reports no change instead of reinstalling the package and restarting the service, and it is the same reason Ansible's tasks come out &lt;code&gt;ok&lt;/code&gt; rather than &lt;code&gt;changed&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The roles carry over too
&lt;/h2&gt;

&lt;p&gt;Ansible Galaxy contains many battle-tested roles that can be incorporated into your deployment.&lt;/p&gt;

&lt;p&gt;Reemote offers roles from Ansible Galaxy too. Reemote has incorporated many of Jeff Geerling's Ansible Galaxy roles and more roles are being added all the time — thirteen of his roles ship in the library today: Apache, Composer, Docker, Drush, Java, Memcached, NFS, nginx, NTP, PHP, PHP Xdebug, PostgreSQL and the EPEL repository role, alongside DataDog's official agent role. Each one is a Python module with typed role variables, not a directory of YAML loaded by convention, and each ships with a runnable example and an offline test that runs it twice against a simulated host and asserts the second pass reports zero changes.&lt;/p&gt;

&lt;p&gt;That is the migration argument in one line. You are not converting your playbooks into someone else's model of configuration management; you are expressing the same tasks, modules, role variables, handlers and change reporting in Python — which means your existing roles become code you can import, type-check and test with &lt;code&gt;pytest&lt;/code&gt;, and your team's Ansible knowledge stays current instead of obsolete.&lt;/p&gt;




&lt;ul&gt;
&lt;li&gt;Documentation and full guide: &lt;a href="https://reemote.org/" rel="noopener noreferrer"&gt;https://reemote.org/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Source: &lt;a href="https://github.com/kimjarvis/reemote" rel="noopener noreferrer"&gt;https://github.com/kimjarvis/reemote&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;PyPI: &lt;code&gt;pip install reemote&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;License: EPL-2.0&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>showdev</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Reemote: dry-run, then apply — no DSL required</title>
      <dc:creator>Kim Jarvis</dc:creator>
      <pubDate>Tue, 24 Nov 2026 18:37:59 +0000</pubDate>
      <link>https://dev.to/kimbofab/reemote-dry-run-then-apply-no-dsl-required-id5</link>
      <guid>https://dev.to/kimbofab/reemote-dry-run-then-apply-no-dsl-required-id5</guid>
      <description>&lt;p&gt;Reemote is a pure-Python configuration-management library built around one idea: &lt;strong&gt;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&lt;/strong&gt;. Same code, same inventory, same operations — the only difference is a &lt;code&gt;dry=True&lt;/code&gt; 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.&lt;/p&gt;

&lt;p&gt;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:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The intended diff.&lt;/strong&gt; For each operation the plan reports &lt;code&gt;changed&lt;/code&gt; or &lt;code&gt;no change&lt;/code&gt;, and when it changes it says why — &lt;code&gt;content /etc/nginx/nginx.conf differs, will install&lt;/code&gt;, &lt;code&gt;packages ('nginx',) missing, will install&lt;/code&gt;, &lt;code&gt;service nginx is not running, will start&lt;/code&gt;. You read the diff, not a promise that something will be fine.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The host scope.&lt;/strong&gt; 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 &lt;code&gt;hosts:&lt;/code&gt; glob.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The exact commands.&lt;/strong&gt; 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.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Try it in under a minute (docker connector)
&lt;/h2&gt;

&lt;p&gt;Reemote ships a &lt;strong&gt;docker connector&lt;/strong&gt; 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. &lt;strong&gt;Docker or Podman must be installed locally&lt;/strong&gt; — the connector shells out to whichever CLI you name in the inventory, and there is no default. Two steps:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;  &lt;span class="c"&gt;# 1. Install (Python 3.13+; pip works just as well as uv)&lt;/span&gt;
  uv venv .venv &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;source&lt;/span&gt; .venv/bin/activate &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; uv pip install reemote

  &lt;span class="c"&gt;# 2. Save the script below as hello.py, then run it&lt;/span&gt;
  python hello.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;  &lt;span class="c1"&gt;# hello.py&lt;/span&gt;
  &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;asyncio&lt;/span&gt;

  &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;reemote&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;files&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;format_log&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;format_plan&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;op&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;run&lt;/span&gt;

  &lt;span class="no"&gt;INVENTORY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="s2"&gt;"host"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"demo"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="s2"&gt;"family"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Alpine"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="s2"&gt;"connection"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="s2"&gt;"connector"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"docker"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="s2"&gt;"identifier"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"alpine:3.20"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="s2"&gt;"docker_cmd"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"podman"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;   &lt;span class="c1"&gt;# or "docker"&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;


  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nf"&gt;op&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;files&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;install&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
               &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Write a greeting"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
               &lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Hello from reemote!\n"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
               &lt;span class="n"&gt;dest&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/tmp/reemote-hello.txt"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
               &lt;span class="n"&gt;mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"0644"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


  &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="c1"&gt;# Dry run: facts are gathered for real, nothing is mutated.&lt;/span&gt;
      &lt;span class="n"&gt;plans&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;INVENTORY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dry&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"== Dry run: what would change =="&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;format_plan&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;plans&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

      &lt;span class="c1"&gt;# Apply: the same deploy, executed against a fresh container.&lt;/span&gt;
      &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;report&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;INVENTORY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"\n== Applied: what changed =="&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="n"&gt;report&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;
      &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;format_log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;report&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


  &lt;span class="n"&gt;asyncio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Reemote starts a throwaway &lt;code&gt;alpine:3.20&lt;/code&gt; 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:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  == 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 &amp;lt;files install&amp;gt; -&amp;gt; /tmp/reemote-install-2e52d4f8373a608a/content
      $ sh -c 'mkdir -p /tmp &amp;amp;&amp;amp; cp /tmp/reemote-install-2e52d4f8373a608a/content /tmp/reemote-hello.txt &amp;amp;&amp;amp; chmod 644 /tmp/reemote-hello.txt &amp;amp;&amp;amp; rm -rf /tmp/reemote-install-2e52d4f8373a608a'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;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 &lt;code&gt;run(...)&lt;/code&gt; starts its own throwaway container from &lt;code&gt;alpine:3.20&lt;/code&gt;, so both phases observe the same absent file; the demo is about the two-phase pattern, not idempotence.&lt;/p&gt;

&lt;p&gt;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 &lt;a href="https://asyncssh.readthedocs.io/" rel="noopener noreferrer"&gt;asyncssh&lt;/a&gt;.&lt;/p&gt;

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

&lt;p&gt;The following deploy installs and starts nginx:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nf"&gt;op&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;apt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;packages&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Install nginx"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
               &lt;span class="n"&gt;packages&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"nginx"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sudo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nf"&gt;op&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;files&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;install&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Write landing page"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
               &lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="no"&gt;PAGE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dest&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/var/www/html/index.html"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
               &lt;span class="n"&gt;mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"0644"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sudo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nf"&gt;op&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;systemd&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;service&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Run nginx"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
               &lt;span class="n"&gt;service&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"nginx"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;running&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;enabled&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sudo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Point that deploy at your staging inventory with &lt;code&gt;dry=True&lt;/code&gt; 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 &lt;code&gt;dry=True&lt;/code&gt; to apply.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;run(...)&lt;/code&gt; 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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;Reemote is inspired by &lt;a href="https://pyinfra.com/" rel="noopener noreferrer"&gt;Pyinfra&lt;/a&gt;, 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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Documentation and full guide: &lt;a href="https://reemote.org/" rel="noopener noreferrer"&gt;https://reemote.org/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Source: &lt;a href="https://github.com/kimjarvis/reemote" rel="noopener noreferrer"&gt;https://github.com/kimjarvis/reemote&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;PyPI: &lt;code&gt;pip install reemote&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;License: EPL-2.0&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>showdev</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Reemote: a pure-Python configuration-management library</title>
      <dc:creator>Kim Jarvis</dc:creator>
      <pubDate>Mon, 23 Nov 2026 20:15:21 +0000</pubDate>
      <link>https://dev.to/kimbofab/reemote-a-pure-python-configuration-management-library-1bjd</link>
      <guid>https://dev.to/kimbofab/reemote-a-pure-python-configuration-management-library-1bjd</guid>
      <description>&lt;p&gt;Python has had no configuration-management library — until now. Pulumi is an infrastructure-management library: it can provision servers and cloud instances, but the moment you want to configure those servers you have to switch to another language, usually Ansible. Reemote is a pure-Python configuration-management library. You describe the state of your servers from a Python program.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it in under a minute (docker connector)
&lt;/h2&gt;

&lt;p&gt;Reemote ships a &lt;strong&gt;docker connector&lt;/strong&gt; that runs your deploy inside a local container, so you need neither a remote host nor an SSH key to see it work. &lt;strong&gt;Docker or Podman must be installed locally&lt;/strong&gt; — the connector shells out to whichever CLI you name in the inventory, and there is no default. Two steps:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# 1. Install (Python 3.13+; pip works just as well as uv)&lt;/span&gt;
uv venv .venv &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;source&lt;/span&gt; .venv/bin/activate &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; uv pip install reemote

&lt;span class="c"&gt;# 2. Save the script below as hello.py, then run it&lt;/span&gt;
python hello.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# hello.py&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;asyncio&lt;/span&gt;

&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;reemote&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;files&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;format_log&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;format_plan&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;op&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;run&lt;/span&gt;

&lt;span class="no"&gt;INVENTORY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="s2"&gt;"host"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"demo"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"family"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Alpine"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"connection"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="s2"&gt;"connector"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"docker"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"identifier"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"alpine:3.20"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"docker_cmd"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"podman"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;   &lt;span class="c1"&gt;# or "docker"&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nf"&gt;op&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;files&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;install&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Write a greeting"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Hello from reemote!\n"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;dest&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/tmp/reemote-hello.txt"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"0644"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="c1"&gt;# Dry run: facts are gathered for real, nothing is mutated.&lt;/span&gt;
    &lt;span class="n"&gt;plans&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;INVENTORY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dry&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"== Dry run: what would change =="&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;format_plan&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;plans&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# Apply: the same deploy, executed against a fresh container.&lt;/span&gt;
    &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;report&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;INVENTORY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"\n== Applied: what changed =="&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="n"&gt;report&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;format_log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;report&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="n"&gt;asyncio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Reemote starts a throwaway &lt;code&gt;alpine:3.20&lt;/code&gt; 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:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;== 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 &amp;lt;files install&amp;gt; -&amp;gt; /tmp/reemote-install-2e52d4f8373a608a/content
    $ sh -c 'mkdir -p /tmp &amp;amp;&amp;amp; cp /tmp/reemote-install-2e52d4f8373a608a/content /tmp/reemote-hello.txt &amp;amp;&amp;amp; chmod 644 /tmp/reemote-hello.txt &amp;amp;&amp;amp; rm -rf /tmp/reemote-install-2e52d4f8373a608a'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As in Ansible, execution has two phases. The dry run reports the changes that would be made; the apply carries them out and records the exact commands that were sent. The two calls differ only in &lt;code&gt;dry=True&lt;/code&gt;, and in dry mode &lt;code&gt;report&lt;/code&gt; is &lt;code&gt;None&lt;/code&gt; because nothing was mutated. Each &lt;code&gt;run(...)&lt;/code&gt; starts its own throwaway container from &lt;code&gt;alpine:3.20&lt;/code&gt;, so both phases observe the same absent file — the point of the demo is the two-phase pattern, not idempotence.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

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

&lt;p&gt;The following deploy installs and starts nginx:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nf"&gt;op&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;apt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;packages&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Install nginx"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;packages&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"nginx"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sudo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nf"&gt;op&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;files&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;install&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Write landing page"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="no"&gt;PAGE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dest&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/var/www/html/index.html"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"0644"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sudo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nf"&gt;op&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;systemd&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;service&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Run nginx"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;service&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"nginx"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;running&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;enabled&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sudo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;run(...)&lt;/code&gt; returns the plans and the report as structured objects your program can inspect, giving you programmatic control over the entire configuration process.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;If you have ever wanted to configure servers in Python — the same language as the rest of your stack — Reemote is worth a look.&lt;/p&gt;

</description>
      <category>showdev</category>
      <category>opensource</category>
    </item>
    <item>
      <title>After `pulumi up`: configuring Pulumi's servers with reemote</title>
      <dc:creator>Kim Jarvis</dc:creator>
      <pubDate>Fri, 20 Nov 2026 15:35:24 +0000</pubDate>
      <link>https://dev.to/kimbofab/after-pulumi-up-configuring-pulumis-servers-with-reemote-35li</link>
      <guid>https://dev.to/kimbofab/after-pulumi-up-configuring-pulumis-servers-with-reemote-35li</guid>
      <description>&lt;p&gt;From Python I call Pulumi to provision my servers, and then I run an Ansible playbook to configure them. Why? Why is that the shape of it? The provisioning is real code — typed, reviewable, testable, importable — and then, the moment a machine exists and I need something done &lt;em&gt;inside&lt;/em&gt; it, I have to leave Python and write another language, with another mindset, in another file, run by another tool that needs to be told about the servers the first tool just created.&lt;/p&gt;

&lt;p&gt;Why can't I configure the servers in the same Python program? And I do not mean "call Python from the playbook", or "run the playbook from a post-create hook", or shell out to a CLI and scrape its stdout. I mean &lt;em&gt;in the same program&lt;/em&gt;: after the instance I just declared, using the address it just handed back, one &lt;code&gt;await&lt;/code&gt; deep. I have the hostname right there. I have the key right there in Python. Everything I need to know about that machine is at hand, but it all has to be re-encoded for Ansible. It's an impedance mismatch, like SQL to objects. The provision-configuration impedance mismatch.&lt;/p&gt;

&lt;p&gt;Why do I have to use Ansible at all? I do not want a controller, an inventory format of its own, a callback plugin API, or a DSL for saying what should be true. I want to &lt;code&gt;import&lt;/code&gt; a package, hand it a host, and get back what changed. So why has nobody written a configuration management &lt;em&gt;library&lt;/em&gt; in Python — one you &lt;code&gt;pip install&lt;/code&gt; and call from your own process, the way you would call anything else? How hard can it be? Somebody has to run &lt;code&gt;apt list --installed&lt;/code&gt;, compare it against what was asked for, and install the package only when the two disagree.&lt;/p&gt;

&lt;p&gt;It turns out that is most of it, and that it fits in a library. The mismatch is a habit, not a constraint.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Pulumi's job ends when the stack is applied: the instance exists, the network is wired, the DNS has propagated. The server is still empty. Reemote is a Python library that takes over at exactly that point — it installs the packages, writes the files, and runs the services inside the machines Pulumi built. This article is about that handoff: what reemote is, and how it picks up where&lt;/em&gt; &lt;code&gt;pulumi up&lt;/code&gt; &lt;em&gt;leaves off — quite possibly in the same program.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The handoff
&lt;/h2&gt;

&lt;p&gt;Start with the part that ought to have been obvious years ago. The handoff does not have to be a boundary between two programs, because there is only one language on either side of it: Pulumi's Python SDK and reemote are both ordinary Python running on an &lt;code&gt;asyncio&lt;/code&gt; event loop, so the code that builds a server and the code that configures it can sit in one module, in one process — the instance declared with a provider package, the deploy that fills it in just another coroutine on the same loop.&lt;/p&gt;

&lt;p&gt;What crosses from one half to the other is a reachable address — plus one thing to get right about a machine that has only just been created: it does not answer SSH the moment the provider API says it exists.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# __main__.py — one program: Pulumi builds the server, reemote configures it&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;pulumi&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;pulumi_aws&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;ec2&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;reemote&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nc"&gt;Host&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;WaitForConnection&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;apt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;files&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;gather_action&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;op&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;run&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;systemd&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;web&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ec2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Instance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"web"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;instance_type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"t3.small"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ami&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"ami-0c3d3ab1d1a0f4dc0"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;pulumi&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;export&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"webHost"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;web&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;public_dns&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="no"&gt;PAGE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"&amp;lt;html&amp;gt;&amp;lt;body&amp;gt;&amp;lt;h1&amp;gt;Deployed by reemote&amp;lt;/h1&amp;gt;&amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;\n"&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nf"&gt;op&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;apt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;packages&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Install nginx"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;packages&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"nginx"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sudo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nf"&gt;op&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;files&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;install&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Write landing page"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="no"&gt;PAGE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dest&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/var/www/html/index.html"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"0644"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sudo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nf"&gt;op&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;systemd&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;service&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Run nginx"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;service&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"nginx"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;running&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;enabled&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sudo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;configure&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;address&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;inventory&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"host"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"web"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"group"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"web"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                  &lt;span class="s2"&gt;"connection"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"connector"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"ssh"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                                 &lt;span class="s2"&gt;"address"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;address&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                                 &lt;span class="s2"&gt;"username"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"deploy"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="c1"&gt;# Cloud-init has to finish and sshd has to start before any of that works.&lt;/span&gt;
    &lt;span class="n"&gt;hosts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;Host&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;from_inventory&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;entry&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;inventory&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;gather_action&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hosts&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;WaitForConnection&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;600&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;retry&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;inventory&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# web.public_dns is a pulumi.Output: apply passes its plain value once the&lt;/span&gt;
&lt;span class="c1"&gt;# instance exists, and Output.from_input schedules the coroutine on the loop&lt;/span&gt;
&lt;span class="c1"&gt;# Pulumi already runs — asyncio.run would fail here, because a Pulumi program&lt;/span&gt;
&lt;span class="c1"&gt;# owns the event loop.&lt;/span&gt;
&lt;span class="n"&gt;web&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;public_dns&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;apply&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;lambda&lt;/span&gt; &lt;span class="n"&gt;address&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;pulumi&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Output&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;from_input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;configure&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;address&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note the ordering inside &lt;code&gt;configure&lt;/code&gt;, because it is the part people get wrong on a freshly provisioned host: the wait comes before the deploy, not inside it. Actions run immediately and sit outside the two-phase model, so &lt;code&gt;gather_action&lt;/code&gt; raises if you call it from a deploy generator; between the stack and the deploy is exactly where it belongs. It also closes the connections of the hosts it was handed, which is why the wait takes &lt;code&gt;Host&lt;/code&gt; objects and the deploy takes the inventory — &lt;code&gt;run&lt;/code&gt; materialises and tears down its own fresh hosts from the entries it is given.&lt;/p&gt;

&lt;p&gt;The same program can of course be split in two, and often should be: a platform team that runs &lt;code&gt;pulumi up&lt;/code&gt; in one pipeline and hands the stack to an application team will keep the deploy as its own script, run with &lt;code&gt;python&lt;/code&gt;, reading the address out of the stack. And the direction can be reversed: the Automation API — the &lt;code&gt;pulumi.automation&lt;/code&gt; namespace of the Pulumi SDK — wraps &lt;code&gt;pulumi up&lt;/code&gt; and friends as a typed SDK so a Pulumi program can run &lt;em&gt;without the CLI&lt;/em&gt;, driven from your own application, "your Python code controls Pulumi, rather than Pulumi controlling your code". A single script can then apply the stack, take the outputs back as plain data, and go straight into &lt;code&gt;run(...)&lt;/code&gt; — the same handoff, with the engine invocation made explicit instead of the resource declaration. Which direction you pick is a question about who owns the pipeline, not about what the tools allow.&lt;/p&gt;

&lt;p&gt;One caveat on running both halves in one program: a Pulumi &lt;code&gt;Output&lt;/code&gt; is only guaranteed to resolve when resources are really being created. Under &lt;code&gt;pulumi preview&lt;/code&gt; the engine reports what it &lt;em&gt;would&lt;/em&gt; do and many values stay unknown, so the configuration callback is a no-op there. That is the right behaviour — there is no server to configure yet — but it means the deploy's own preview comes from reemote instead: call &lt;code&gt;run(inventory, deploy, dry=True)&lt;/code&gt; against a host you already have.&lt;/p&gt;

&lt;h3&gt;
  
  
  Where the inventory comes from
&lt;/h3&gt;

&lt;p&gt;The example above also answers the line of the rant I find most irritating: another tool that has to be told about the servers the first tool just created. That step is the inventory, and it is where the mismatch gets rebuilt by habit — a second description of a fleet that already has one.&lt;/p&gt;

&lt;p&gt;A reemote inventory is a plain list of dictionaries, each with a &lt;code&gt;host&lt;/code&gt; name and a &lt;code&gt;connection&lt;/code&gt; mapping, optionally a &lt;code&gt;privilege&lt;/code&gt; mapping and the &lt;code&gt;group&lt;/code&gt; / &lt;code&gt;tags&lt;/code&gt; classifiers a script branches on. There is no inventory format to learn and no plugin to write between it and a Pulumi stack — the stack's exports are Python data, and building the list is that step of glue work your organisation already does somewhere:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;inventory_from_stack&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;project&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;stack&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;list&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="s2"&gt;"""Turn a Pulumi stack's exports into a reemote inventory."""&lt;/span&gt;
    &lt;span class="n"&gt;outputs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;loads&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;subprocess&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;check_output&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"pulumi"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"stack"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"output"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"--json"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;cwd&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"{project}/{stack}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"host"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
         &lt;span class="s2"&gt;"group"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"web"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
         &lt;span class="s2"&gt;"connection"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"connector"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"ssh"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"address"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;address&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"username"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
         &lt;span class="s2"&gt;"privilege"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"sudo_user"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"root"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;address&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;outputs&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"webHosts"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;items&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Three things are worth deciding at this seam rather than inheriting by accident.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;How many hosts you name.&lt;/strong&gt; One export per instance, or a map of them, is what lets a fleet grow without the deploy changing. &lt;code&gt;group&lt;/code&gt; and &lt;code&gt;tags&lt;/code&gt; then select the fan-out — &lt;code&gt;gather_action(hosts, WaitForConnection, group="web")&lt;/code&gt; waits for just that group — so the inventory carries the topology once and the scripts stay generic.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Where the address points.&lt;/strong&gt; A public DNS name is what Pulumi usually exports, but the inventory takes anything SSH-reachable, so a stack that builds a private subnet can export a private IP and the deploy runs from a jump host — &lt;code&gt;port&lt;/code&gt;, &lt;code&gt;proxy_command&lt;/code&gt; and &lt;code&gt;tunnel&lt;/code&gt; are all accepted in the &lt;code&gt;connection&lt;/code&gt; mapping, since it forwards to asyncssh.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;What happens to the host key.&lt;/strong&gt; A replaced instance answers the same address with a different host key, and a strict check turns that into a failure on the first deploy after a rebuild. The &lt;code&gt;connection&lt;/code&gt; mapping passes asyncssh's &lt;code&gt;known_hosts&lt;/code&gt; through, so the choice is explicit: a path to a known-hosts file to check against, or &lt;code&gt;None&lt;/code&gt; to skip the check for ephemeral hosts. Either is defensible; leaving it undecided is not, because you will find out on the rebuild you did not expect.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Whatever produced the list, &lt;code&gt;validate_inventory&lt;/code&gt; checks every entry against the schema, and &lt;code&gt;run&lt;/code&gt; calls it before a single host is materialised — so a stack output with a missing key fails on the control machine rather than as an SSH error halfway through a fleet.&lt;/p&gt;

&lt;h3&gt;
  
  
  Waiting for the machine to answer SSH
&lt;/h3&gt;

&lt;p&gt;Timing is the other thing the two-tool habit buries. A machine the API created thirty seconds ago does not answer SSH yet — cloud-init is still running, sshd may not be — and in the old shape of things you discovered that on a Friday afternoon. &lt;code&gt;WaitForConnection&lt;/code&gt; is the action that closes the gap between "the API created it" and "SSH works". Each attempt is a full SSH handshake and authentication — not a bare TCP probe — retried every &lt;code&gt;retry&lt;/code&gt; seconds until it succeeds or the host's &lt;code&gt;timeout&lt;/code&gt; budget runs out; hosts are waited for concurrently, and awaiting the &lt;code&gt;gather_action&lt;/code&gt; is the barrier that returns only once every selected host has connected. A host that never comes back raises a fatal &lt;code&gt;ConnectionTimeoutError&lt;/code&gt; naming it, which aborts before the deploy starts rather than half-configuring a fleet.&lt;/p&gt;

&lt;p&gt;That makes it useful for more than provisioning. It is the same action that sits between a deploy that changed kernel arguments, a &lt;code&gt;Shell&lt;/code&gt; action that reboots, and the deploy that finishes the job — and, at Pulumi's layer, between a stack that replaced an instance and the config that has to land on it again.&lt;/p&gt;

&lt;h2&gt;
  
  
  What reemote is
&lt;/h2&gt;

&lt;p&gt;Everything so far has been about the seam; this is what sits on this side of it. Reemote is &lt;code&gt;pip install reemote&lt;/code&gt; — a library with no CLI, no daemon, no agent, and no state file. Nothing installs on the target beyond SSH, and nothing persists between runs on yours. That is the answer to "why has nobody written a configuration management library": there was very little to write, provided nobody insisted on a controller.&lt;/p&gt;

&lt;p&gt;A deploy is a generator function that yields operation requests. The factory signature takes the host being deployed to — so the same function can branch on host data, and different hosts can share it. Requests name what they want ("Install nginx") and describe the desired end state; they say nothing about how to get there, because the engine works out whether anything must change at all.&lt;/p&gt;

&lt;p&gt;The module surface covers the configuration domain, package management for Debian, Red Hat and Alpine family systems; file contents, modes, owners, links and archives; services on systemd and OpenRC; users, groups and processes; databases through the MySQL and PostgreSQL modules; firewalls through iptables, firewalld and UFW; plus git, cron, sysctl and friends. Everything reaches the target over SSH — or over the docker connector, which runs the identical deploy inside a local container, which is how the examples in this repository are tested.&lt;/p&gt;

&lt;h2&gt;
  
  
  How the engine decides what to run
&lt;/h2&gt;

&lt;p&gt;The closing jab of that opening — &lt;em&gt;somebody has to run&lt;/em&gt; &lt;code&gt;apt list --installed&lt;/code&gt;&lt;em&gt;, compare it against what was asked for, and install the package only when the two disagree&lt;/em&gt; — was not a dismissal. It is the design.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;run(...)&lt;/code&gt; executes in two phases. It plans — reading &lt;strong&gt;live facts&lt;/strong&gt; from each target: what packages are installed, what this file contains, whether this unit is active — and derives whether each request needs any change. Then it applies, repeating the pass under a determinism guard that raises if the two passes disagree. Operations emit shell commands only when a real delta exists, so the second run against the same live server reports no change.&lt;/p&gt;

&lt;p&gt;The result is data: per-host plans, and a report whose entries carry &lt;code&gt;changed&lt;/code&gt;, a &lt;code&gt;reason&lt;/code&gt;, and the exact commands sent. &lt;code&gt;dry=True&lt;/code&gt; stops after the plan, giving you a genuine preview against live state — the natural thing to log in CI before letting the apply proceed.&lt;/p&gt;

&lt;p&gt;Three properties matter once this sits behind an infrastructure tool:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;There is no state to keep true.&lt;/strong&gt; Reemote stores nothing between runs; the server &lt;em&gt;is&lt;/em&gt; the state. Whatever Pulumi built — a fresh instance from an AMI, or one that has been running and drifting for a year — the deploy reads what is actually there and converges it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;It reaches anything SSH-reachable.&lt;/strong&gt; Cloud VMs, bare metal in a rack you own, VMs on a private OpenStack, containers via the docker connector. If your stack hands back a host, reemote can configure it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;It composes as a library.&lt;/strong&gt; Inventory built from a stack export or a database query, config text generated by the same Pydantic model the application uses, a deploy gated behind a webhook, pure generator functions tested with &lt;code&gt;pytest&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Where the handoff lands
&lt;/h2&gt;

&lt;p&gt;None of this moves the line between the two jobs; it only stops that line from being a border crossing. Reemote starts where the provider API stops. It cannot launch the instance, attach the volume or create the security group — it reaches machines that already exist, and it needs SSH to get in. Its scope is the Linux operating system: BSD, macOS and Windows are out of scope. It carries none of the collaboration primitives of an IaC backend — no stacks, no reviewable state — by design, since it keeps no state of its own.&lt;/p&gt;

&lt;p&gt;So the split stays exactly where operations teams put it: Pulumi guarantees the server exists and is networked; reemote guarantees the server is &lt;em&gt;useful&lt;/em&gt;. What changes is that the second half stops being a different language, a different repo and a different invocation. It is a library call away, in the program you were already writing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Reemote: &lt;code&gt;pip install reemote&lt;/code&gt; — docs at &lt;a href="https://reemote.org/" rel="noopener noreferrer"&gt;https://reemote.org/&lt;/a&gt;, source at &lt;a href="https://github.com/kimjarvis/reemote" rel="noopener noreferrer"&gt;https://github.com/kimjarvis/reemote&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Pulumi: &lt;a href="https://www.pulumi.com/docs/iac/guides/basics/how-pulumi-works/" rel="noopener noreferrer"&gt;https://www.pulumi.com/docs/iac/guides/basics/how-pulumi-works/&lt;/a&gt; for how stacks, exports and outputs work; &lt;a href="https://www.pulumi.com/docs/iac/languages-sdks/python/python-blocking-async/" rel="noopener noreferrer"&gt;https://www.pulumi.com/docs/iac/languages-sdks/python/python-blocking-async/&lt;/a&gt; for the event-loop rules the combined program above follows; and &lt;a href="https://www.pulumi.com/docs/iac/concepts/automation-api/" rel="noopener noreferrer"&gt;https://www.pulumi.com/docs/iac/concepts/automation-api/&lt;/a&gt; to drive the engine from your own Python program&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>showdev</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Ansible galaxy transpiled to python</title>
      <dc:creator>Kim Jarvis</dc:creator>
      <pubDate>Mon, 16 Nov 2026 19:36:09 +0000</pubDate>
      <link>https://dev.to/kimbofab/ansible-galaxy-transpiled-to-python-gj9</link>
      <guid>https://dev.to/kimbofab/ansible-galaxy-transpiled-to-python-gj9</guid>
      <description>&lt;p&gt;&lt;em&gt;Translating Ansible roles to Python turns infrastructure logic into ordinary code: unit-testable with &lt;code&gt;pytest&lt;/code&gt;, checkable with type checkers and linters, and free of the expressive ceiling of a YAML DSL with a templating dialect. Until now the problem has been intractable, because Python had no configuration-management library shaped like Ansible to translate into — an AI asked to rewrite a role improvises a different pile of &lt;code&gt;subprocess&lt;/code&gt; and SSH calls every time, losing idempotence, fleet orchestration, dry-run preview and change reporting along the way. Reemote is that library: a Python framework whose facts, operations and module vocabulary line up with Ansible's, giving the translation a bounded, reviewable destination. It is ready to use and download today, with documentation at &lt;a href="https://reemote.org/" rel="noopener noreferrer"&gt;reemote.org&lt;/a&gt; and the full source, examples and tests in the EPL-2.0 &lt;a href="https://github.com/kimjarvis/reemote" rel="noopener noreferrer"&gt;git repository&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem
&lt;/h2&gt;

&lt;p&gt;An Ansible role is not merely a list of commands. It inherits its operational guarantees from the engine that runs it: lock-step execution across the fleet, &lt;code&gt;--check&lt;/code&gt; mode previewing changes against live state, and per-task, per-host reporting of what actually changed. A translation into ordinary Python with no target framework loses all three. The generated script shells out to &lt;code&gt;apt-get&lt;/code&gt;, checks a return code, and wraps the sequence in a &lt;code&gt;try/except&lt;/code&gt; — it reproduces the role's happy path while discarding the machinery that made it safe to run on production infrastructure.&lt;/p&gt;

&lt;p&gt;The cause is structural, not a deficit of model capability. A large language model generates by matching patterns, and translation succeeds when a canonical target idiom exists to converge on. "Translate an Ansible role to Python" has had no such destination: what Python offered instead were wrappers that launch Ansible itself, general SSH-execution libraries, and raw building blocks. With no pattern to match, every generation re-derives a different arrangement of those primitives, and spending more tokens produces longer, better-commented output but not convergence.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why it is interesting
&lt;/h2&gt;

&lt;p&gt;The prize is real. In Python, infrastructure logic becomes testable with standard frameworks, analysable before deployment, and expressible without a DSL's limits — variables become typed data structures instead of a templating dialect, and complex computations live beside the deploy instead of being shelled out to a second toolchain.&lt;/p&gt;

&lt;p&gt;And the diagnosis points at a fix that is tractable. If the bottleneck is a missing target idiom rather than a weak model, then building the idiom changes the problem's shape: with a library whose vocabulary lines up one-to-one with Ansible's, translation collapses from "design a configuration-management system" to "map each task onto the operation that already does this." That second task is exactly what models are good at, and it is bounded enough that a human can review the output the way they would review any pull request. For this migration, the choice of library dominates the choice of model.&lt;/p&gt;

&lt;h2&gt;
  
  
  The solution
&lt;/h2&gt;

&lt;p&gt;Reemote is configuration management as a Python library rather than a CLI. A deploy is a plain synchronous generator yielding operation requests; &lt;code&gt;plans, report, hosts = await run(inventory, deploy)&lt;/code&gt; executes it. Five properties make it a translation target:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Async end to end on asyncssh&lt;/strong&gt; — the runtime supplies fleet-wide concurrency with per-host ordering, so the generated code never invents it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Structured results&lt;/strong&gt; — a run returns a plan and a per-operation report of what changed, why, and the exact commands sent; &lt;code&gt;dry=True&lt;/code&gt; restores the lost dry-run as data a program can assert on.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A one-to-one module vocabulary&lt;/strong&gt; — twenty modules cover package managers, files, services, firewalls, system configuration, keys, databases and containers, so &lt;code&gt;apt_repository&lt;/code&gt; maps to &lt;code&gt;apt.repo&lt;/code&gt;, &lt;code&gt;lineinfile&lt;/code&gt; to &lt;code&gt;files.edit&lt;/code&gt;, &lt;code&gt;get_url&lt;/code&gt; to &lt;code&gt;files.download&lt;/code&gt;, &lt;code&gt;service&lt;/code&gt; to &lt;code&gt;systemd.service&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pure functional deploys&lt;/strong&gt; — the runner executes every deploy twice, plan then apply, and raises if the passes disagree; typical model mistakes are caught at plan time, and the code is testable without servers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No awareness of the controller's file system&lt;/strong&gt; — content is an explicit string or a caller-opened stream, never a controller path, so a converted program is self-contained and portable.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It is ready to use, with the &lt;a href="https://reemote.org/migrating/" rel="noopener noreferrer"&gt;migration guide&lt;/a&gt; working through every construct that does not map one-to-one.&lt;/p&gt;

&lt;h2&gt;
  
  
  What follows from the solution's structure
&lt;/h2&gt;

&lt;p&gt;Because the target is a library with a fixed vocabulary and pure, testable deploys, every correct conversion becomes a reusable pattern — and the repository ships them. Alongside the library source, the EPL-2.0 repo contains close to four hundred runnable example programs, executed by the example runner and exercised by the test suite. You can read them, copy them, and hand them to a model as context without a licensing question hanging over the output.&lt;/p&gt;

&lt;p&gt;Ten of them are automated translations of Ansible Galaxy roles, under &lt;a href="https://github.com/kimjarvis/reemote/tree/main/examples/roles" rel="noopener noreferrer"&gt;&lt;code&gt;examples/roles/&lt;/code&gt;&lt;/a&gt;: Jeff Geerling's &lt;strong&gt;Apache&lt;/strong&gt;, &lt;strong&gt;Docker&lt;/strong&gt;, &lt;strong&gt;Java&lt;/strong&gt;, &lt;strong&gt;Memcached&lt;/strong&gt;, &lt;strong&gt;NFS&lt;/strong&gt;, &lt;strong&gt;nginx&lt;/strong&gt;, &lt;strong&gt;NTP&lt;/strong&gt;, &lt;strong&gt;PHP&lt;/strong&gt; and &lt;strong&gt;PHP Xdebug&lt;/strong&gt; roles, and DataDog's official &lt;strong&gt;agent&lt;/strong&gt; role. Each covers the role's default path on one operating-system family and ships with an offline test suite driving it end-to-end against a simulated host through the real execution driver; the central assertion is idempotence — a second run against the same state reports no changes and queues no handlers. All ten pass. Between them they demonstrate handlers as a second deploy pass, role variables in the inventory, pre-rendered templates, and a build-from-source branch.&lt;/p&gt;

&lt;p&gt;The practical consequence: when you migrate your own role, do not ask the model for "Python" — ask it for &lt;em&gt;the shape of the closest converted role&lt;/em&gt;. The model then imitates a verified, tested, in-repo program, and its job shrinks from designing an architecture to adapting one that already works. The same programs give a human reviewer a known-good standard to judge the output against.&lt;/p&gt;

&lt;p&gt;The structure also makes the conversion itself mechanisable, and &lt;strong&gt;Reemote Control&lt;/strong&gt;, the licensed edition, is where that is taken further. It contains Python equivalents of many programs from Ansible Galaxy — ready to run rather than ready to translate, for when the migration you want is to adopt a maintained equivalent, not to author it. And it ships &lt;strong&gt;skills that drive the conversion&lt;/strong&gt;: packaged agent workflows carrying the module vocabulary, the construct recipes, and the determinism discipline, which direct an agent to audit a role's tasks, map each onto an existing operation, prove and rank any capability gaps rather than paper over them with shell one-liners, shape the program on the converted roles, and verify it with offline idempotence tests. The conversion stops being a prompt you hope works and becomes a workflow you can run again on the next role.&lt;/p&gt;

&lt;p&gt;Ansible Galaxy's value was never the YAML — it was the accumulated, working configuration knowledge. Transpiled to Python, that knowledge carries over: the open repository proves the method and seeds the corpus, and Reemote Control is where much of the catalogue, and the machinery to grow it, lives.&lt;/p&gt;

&lt;h2&gt;
  
  
  More information
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Documentation:&lt;/strong&gt; &lt;a href="https://reemote.org/" rel="noopener noreferrer"&gt;https://reemote.org/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ansible role migration guide:&lt;/strong&gt; &lt;a href="https://reemote.org/migrating/" rel="noopener noreferrer"&gt;https://reemote.org/migrating/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Converted roles:&lt;/strong&gt; &lt;a href="https://github.com/kimjarvis/reemote/tree/main/examples/roles" rel="noopener noreferrer"&gt;https://github.com/kimjarvis/reemote/tree/main/examples/roles&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Source repository:&lt;/strong&gt; &lt;a href="https://github.com/kimjarvis/reemote" rel="noopener noreferrer"&gt;https://github.com/kimjarvis/reemote&lt;/a&gt; (EPL-2.0)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;PyPI:&lt;/strong&gt; &lt;code&gt;pip install reemote&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>showdev</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Managing LXD from Python: Reemote's `lxd` module</title>
      <dc:creator>Kim Jarvis</dc:creator>
      <pubDate>Sun, 15 Nov 2026 14:43:15 +0000</pubDate>
      <link>https://dev.to/kimbofab/managing-lxd-from-python-reemotes-lxd-module-1b8h</link>
      <guid>https://dev.to/kimbofab/managing-lxd-from-python-reemotes-lxd-module-1b8h</guid>
      <description>&lt;p&gt;&lt;em&gt;LXD turns one Ubuntu server into a fleet of system containers and VMs, and Canonical's first-steps tutorial shows how easily you can drive it by hand. This article walks the same first steps from Python: Reemote is a **library&lt;/em&gt;* that manages LXD over &lt;code&gt;sshd&lt;/code&gt; and the &lt;code&gt;lxc&lt;/code&gt; client, plans before it applies, and hands you every result as data you can &lt;code&gt;await&lt;/code&gt;, inspect, and test.*&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem: configuration management with LXD on Ubuntu
&lt;/h2&gt;

&lt;p&gt;Ubuntu plus LXD is a compelling shape. One box, LXD snap-installed and initialized in two commands, and suddenly you have a fleet of containers that behave like lightweight virtual machines — full Linux init systems you can launch, constrain, snapshot and roll back in seconds. Unlike Docker's single-application containers, an LXD container runs a whole userland: systemd, apt, sshd, the lot.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://canonical.com/lxd/docs/latest/tutorial/first_steps/" rel="noopener noreferrer"&gt;Canonical's first-steps tutorial&lt;/a&gt; covers the CLI moves: install and init, launch, exec, file push/pull, resource limits, snapshots. By hand, each is a one-liner. The pain starts when those moves need to live &lt;em&gt;inside a program&lt;/em&gt; — provisioning a container per tenant from an API, rebuilding a staging fleet from a database query, gating a rollout on what actually changed, rolling back automatically when a health check fails.&lt;/p&gt;

&lt;p&gt;That is the gap: &lt;strong&gt;there is no serious configuration-management library you can &lt;code&gt;import&lt;/code&gt; and point at an LXD host.&lt;/strong&gt; Ansible can drive LXD, but it is a CLI-shaped tool — a YAML playbook interpreted by an executable you shell out to, with results you scrape from stdout. Reemote is that library, and &lt;code&gt;lxd&lt;/code&gt; ships as a first-class namespace with facts, operations, and the same two-phase prepare-then-apply runner everything else uses.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Python has real advantages over Ansible
&lt;/h2&gt;

&lt;p&gt;Ansible chose YAML because it is readable and does not require knowing a programming language. That is a fair trade when your team does not write Python. When it does — and most automation teams today do — the trade costs more than it saves:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Your editor knows your code.&lt;/strong&gt; &lt;code&gt;lxd.instance&lt;/code&gt; and &lt;code&gt;lxd.instance_snapshot&lt;/code&gt; are functions: go-to-definition, rename, autocomplete, and a type check that catches a typo before it reaches a production host. A misspelled YAML module name surfaces at runtime, in the middle of a rollout.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No Jinja2 as a second language.&lt;/strong&gt; A container's CPU limit, a device property, an image reference — in reemote each is just a Python expression, evaluated by the interpreter you already trust, not a &lt;code&gt;{{ hostvars[...] }}&lt;/code&gt; string your IDE cannot see through.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Composition is &lt;code&gt;import&lt;/code&gt;, not directory layout.&lt;/strong&gt; A fleet is a loop over a list of tenants; a reusable chunk of provisioning is a generator you import and call. No &lt;code&gt;tasks/main.yml&lt;/code&gt;, &lt;code&gt;defaults/main.yml&lt;/code&gt;, &lt;code&gt;handlers/main.yml&lt;/code&gt; convention to memorise.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The result is data, not stdout.&lt;/strong&gt; If your application needs to know whether the snapshot was created, you read &lt;code&gt;report.entries[i].changed&lt;/code&gt; — you do not regex-scrape a terminal or depend on callback plugins to reshape the log.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Testing is &lt;code&gt;pytest&lt;/code&gt;.&lt;/strong&gt; A deploy function is a pure generator; you can inspect the requests it yields without touching a server. No molecule, no testinfra, no ansible-lint.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;await&lt;/code&gt; is your concurrency model.&lt;/strong&gt; Hosts progress in parallel because the transport is asyncssh, not because a CLI forked worker processes you have to configure.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The solution: Reemote is a library
&lt;/h2&gt;

&lt;p&gt;Reemote is a Python package (&lt;code&gt;pip install reemote&lt;/code&gt;) with two properties that separate it from every CLI-shaped tool.&lt;/p&gt;

&lt;h3&gt;
  
  
  Async end to end, on asyncssh
&lt;/h3&gt;

&lt;p&gt;The transport is &lt;a href="https://asyncssh.readthedocs.io/" rel="noopener noreferrer"&gt;asyncssh&lt;/a&gt;, and the entire execution path — connecting, gathering facts, sending commands, closing — is coroutines. You &lt;code&gt;await&lt;/code&gt; a deploy and hosts progress in parallel; network waits overlap across hosts while each host's commands stay in order. Your deploy script remains a plain synchronous generator, so you never write &lt;code&gt;async&lt;/code&gt; inside an operation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;plans&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;report&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;hosts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;inventory&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;run&lt;/code&gt; is the single entry point: it validates the inventory, opens connections lazily, plans and applies in two phases, then closes everything in a &lt;code&gt;finally&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  A library returning structured results, not a CLI
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;run(...)&lt;/code&gt; returns &lt;code&gt;(plans, report, hosts)&lt;/code&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;plans&lt;/code&gt;&lt;/strong&gt; — &lt;code&gt;{host_label: [PlannedOperation, ...]}&lt;/code&gt;, the proposed work per host.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;report&lt;/code&gt;&lt;/strong&gt; — an &lt;code&gt;ApplyReport&lt;/code&gt; with a &lt;code&gt;LogEntry&lt;/code&gt; per applied operation, each carrying &lt;code&gt;changed&lt;/code&gt;, &lt;code&gt;reason&lt;/code&gt;, and the exact commands sent. &lt;code&gt;None&lt;/code&gt; when &lt;code&gt;dry=True&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;hosts&lt;/code&gt;&lt;/strong&gt; — the materialised host objects.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The read side is data too. Facts return typed Python structures — the instance listing is a list of dicts with config, devices and profiles, not a parsed &lt;code&gt;lxc list&lt;/code&gt; table — and one-off commands run as &lt;em&gt;actions&lt;/em&gt; that return a &lt;code&gt;Result&lt;/code&gt; with &lt;code&gt;exit_status&lt;/code&gt;, &lt;code&gt;stdout&lt;/code&gt; and &lt;code&gt;stderr&lt;/code&gt; as separate fields. &lt;code&gt;format_plan&lt;/code&gt; and &lt;code&gt;format_log&lt;/code&gt; are convenience renderers for humans; your application consumes the objects directly.&lt;/p&gt;

&lt;h2&gt;
  
  
  The &lt;code&gt;lxd&lt;/code&gt; module: LXD's own vocabulary as Python
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;lxd&lt;/code&gt; pairs read-only &lt;strong&gt;facts&lt;/strong&gt; with &lt;strong&gt;operations&lt;/strong&gt; that converge the daemon toward a described state. An operation reads a fact, decides whether anything must change, and yields commands only when it must — so re-running against a stable host is a no-op.&lt;/p&gt;

&lt;p&gt;The operations cover the whole control surface: &lt;strong&gt;instance lifecycle&lt;/strong&gt; (create containers or VMs with profiles, config and devices, reconcile an existing instance non-destructively, drive started/stopped/frozen, delete), &lt;strong&gt;configuration reconciliation&lt;/strong&gt; (set only the config keys, devices and profiles that drifted), &lt;strong&gt;images and aliases&lt;/strong&gt; (cache from a remote, pin an alias), &lt;strong&gt;snapshots and copies&lt;/strong&gt; (create, delete, restore, copy locally or cross-remote), the &lt;strong&gt;surrounding resources&lt;/strong&gt; (projects, profiles, networks, storage pools and custom volumes), and &lt;strong&gt;background-operation control&lt;/strong&gt; (cancel or wait on a registered daemon operation).&lt;/p&gt;

&lt;p&gt;The facts cover the audit view: full instance listings, per-instance config, runtime state and snapshots, the image store and its aliases, networks, profiles, projects, pools and volumes, plus daemon metadata, hardware resources and the operations currently in flight. Everything runs through the &lt;code&gt;lxc&lt;/code&gt; client on the target host — JSON listings and &lt;code&gt;lxc query&lt;/code&gt; REST reads — and the CLI itself waits on the daemon's asynchronous mutations, so the library models no REST polling. Collections are project-scoped (default &lt;code&gt;"default"&lt;/code&gt;) and can address any remote in the host's &lt;code&gt;lxc remote&lt;/code&gt; list. The exhaustive API lives in the &lt;a href="//../modules/lxd.md"&gt;lxd module reference&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;One naming note the tutorial also makes: &lt;code&gt;lxd&lt;/code&gt; is the daemon, &lt;code&gt;lxc&lt;/code&gt; is the client. Reemote drives &lt;code&gt;lxc&lt;/code&gt; on the host — the same client you would type at — so every command below is one you could run yourself.&lt;/p&gt;

&lt;h2&gt;
  
  
  First steps with LXD, in Python
&lt;/h2&gt;

&lt;p&gt;The rest of this article follows Canonical's tutorial step by step, CLI on the left, Reemote on the right. Every output block was produced live against a real Ubuntu host running LXD 6.10.1 from the &lt;code&gt;6/stable&lt;/code&gt; snap channel.&lt;/p&gt;

&lt;p&gt;One structural difference from a container-based quickstart: &lt;strong&gt;LXD needs a real Linux kernel&lt;/strong&gt; — it does not nest inside a Docker container — so the SSH connector is the natural transport. Install reemote (Python 3.13+) and point an inventory entry at your Ubuntu host:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;uv venv .venv &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;source&lt;/span&gt; .venv/bin/activate &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; uv pip install reemote
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="no"&gt;INVENTORY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="s2"&gt;"host"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"ubuntu"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"connection"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="s2"&gt;"address"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"192.168.0.181"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;   &lt;span class="c1"&gt;# your Ubuntu host&lt;/span&gt;
        &lt;span class="s2"&gt;"username"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"supervisor"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"key_path"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"~/.ssh/id_ed25519"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  A. Installation and initialization
&lt;/h3&gt;

&lt;p&gt;The tutorial installs LXD from the snap store, adds your user to the &lt;code&gt;lxd&lt;/code&gt; group, and initializes the daemon:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sudo snap install lxd
sudo usermod -aG lxd &lt;span class="s2"&gt;"$USER"&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; newgrp lxd
lxd init --minimal   &lt;span class="c"&gt;# default storage pool and bridge networking&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In reemote the first two are ordinary operations — &lt;code&gt;snap.package&lt;/code&gt; from the snap namespace, &lt;code&gt;server.user&lt;/code&gt; from the server namespace — composed in one deploy:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;reemote&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;op&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;run&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;server&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;snap&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;bootstrap&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nf"&gt;op&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;snap&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;package&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Install LXD"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;packages&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"lxd"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;channel&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"6/stable"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sudo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nf"&gt;op&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;server&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Login user in the lxd group"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"supervisor"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;groups&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"lxd"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;append&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sudo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Verified output against the demo host, where both are already in place:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ubuntu: Install LXD              [no change: all packages present]
ubuntu: Login user in the lxd group [no change: user supervisor already as requested; directory /home/supervisor already exists]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two honesty notes. First, &lt;code&gt;channel="6/stable"&lt;/code&gt; pins the LXD 6 LTS track — the tutorial's own advice for production; omit it for &lt;code&gt;latest/stable&lt;/code&gt;. Second, the &lt;code&gt;lxd&lt;/code&gt; group grants root-equivalent access to the daemon, so treat membership as the security decision the tutorial says it is. Operations ride &lt;code&gt;sudo=True&lt;/code&gt; and do not need the group, but unprivileged &lt;em&gt;fact reads&lt;/em&gt; do — and group membership applies to new login sessions, which reemote's next connection picks up automatically.&lt;/p&gt;

&lt;p&gt;Initialization is the one step with no dedicated operation: &lt;code&gt;lxd init&lt;/code&gt; is a one-time bootstrap, not a desired state. The library-shaped answer is to gate it on a fact — ask the daemon what storage pools exist, and run the init only where the answer is empty:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;asyncio&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;reemote&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;Host&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;LxdStoragePools&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Shell&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;gather_action&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;gather_fact&lt;/span&gt;

&lt;span class="n"&gt;hosts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;Host&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;from_inventory&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;entry&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="no"&gt;INVENTORY&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;pools&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;gather_fact&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hosts&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;LxdStoragePools&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;asyncio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;gather&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;aclose&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;host&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;hosts&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;uninitialized&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;host&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;hosts&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;pools&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;uninitialized&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;gather_action&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;uninitialized&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Shell&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                        &lt;span class="n"&gt;command&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"lxd init --minimal"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sudo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On the demo host the fact returns &lt;code&gt;['default', 'fast']&lt;/code&gt;, so the init never runs. This is the structured-results property doing real work: the decision is a Python &lt;code&gt;if&lt;/code&gt; over typed data, not a shell guard scraped from &lt;code&gt;lxc&lt;/code&gt; output.&lt;/p&gt;

&lt;h3&gt;
  
  
  B. Launching your first container
&lt;/h3&gt;

&lt;p&gt;The tutorial launches an Ubuntu container named &lt;code&gt;web1&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;lxc launch ubuntu:24.04 web1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In reemote that is &lt;code&gt;lxd.instance&lt;/code&gt;, with the desired configuration attached:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;reemote&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;lxd&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;op&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nf"&gt;op&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lxd&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;instance&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Ensure web1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;instance&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"web1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;image&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"ubuntu:24.04"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"limits.cpu=2"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"limits.memory=1GiB"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;sudo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On a fresh host the operation plans &lt;code&gt;[changed: lxd instance web1 will be created]&lt;/code&gt; and the apply sends one command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sudo lxc launch ubuntu:24.04 web1 -c limits.cpu=2 -c limits.memory=1GiB --project default &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; /dev/null
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Three details worth noticing. The &lt;code&gt;--project default&lt;/code&gt; is explicit because the CLI's &lt;em&gt;current&lt;/em&gt; project can be switched interactively — a deploy never relies on it. The trailing &lt;code&gt;&amp;lt; /dev/null&lt;/code&gt; keeps a non-interactive SSH session from blocking on launch's prompts. And the image reference is the tutorial's &lt;code&gt;ubuntu:&lt;/code&gt; remote — the official Ubuntu cloud images — which LXD caches locally after the first download.&lt;/p&gt;

&lt;p&gt;An existing instance is reconciled &lt;strong&gt;non-destructively&lt;/strong&gt;: profiles assigned, drifted config keys set, drifted devices re-attached. Base-image drift is &lt;em&gt;reported&lt;/em&gt; in the reason, never recreated — destroying a container stays an explicit &lt;code&gt;present=False&lt;/code&gt; choice. The same operation launches VMs with &lt;code&gt;instance_type="vm"&lt;/code&gt;; a container/VM type mismatch raises rather than silently converting.&lt;/p&gt;

&lt;h3&gt;
  
  
  C. Interacting with the container
&lt;/h3&gt;

&lt;p&gt;The tutorial runs a one-off command inside the container, or opens a shell:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;lxc &lt;span class="nb"&gt;exec&lt;/span&gt; web1 -- apt update
lxc shell web1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Reemote is a library, so the one-off command is an &lt;strong&gt;action&lt;/strong&gt;: &lt;code&gt;Shell&lt;/code&gt; runs it on the host and returns the whole outcome as a &lt;code&gt;Result&lt;/code&gt;, fanned out across hosts with &lt;code&gt;gather_action&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;reemote&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;Host&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Shell&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;gather_action&lt;/span&gt;

&lt;span class="n"&gt;hosts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;Host&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;from_inventory&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;entry&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="no"&gt;INVENTORY&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;results&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;gather_action&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hosts&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Shell&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                              &lt;span class="n"&gt;command&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"lxc exec web1 -- apt update"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;results&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;items&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"exit:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"exit_status"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"stdout"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Verified output (excerpt):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ubuntu exit: 0
Ign:1 http://security.ubuntu.com/ubuntu noble-security InRelease
Ign:2 http://archive.ubuntu.com/ubuntu noble InRelease
Get:1 http://security.ubuntu.com/ubuntu noble-security InRelease [126 kB]
Hit:2 http://archive.ubuntu.com/ubuntu noble InRelease
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;Result&lt;/code&gt; keeps &lt;code&gt;stderr&lt;/code&gt; separate, and on this run it carried a familiar warning: &lt;code&gt;WARNING: apt does not have a stable CLI interface. Use with caution in scripts.&lt;/code&gt; That is the library shape paying off — the warning is a field you can inspect, not noise interleaved into a log you parse. (For scripted package work inside the container, prefer &lt;code&gt;apt-get&lt;/code&gt;, or point reemote's own &lt;code&gt;apt&lt;/code&gt; module at the container — more on that below.)&lt;/p&gt;

&lt;p&gt;The interactive &lt;code&gt;lxc shell&lt;/code&gt; stays what it is: a human tool. Reemote does not wrap it, and a deploy should not need it. But there is a deeper move the tutorial hints at. An LXD container is a full Linux system with its own IP on the bridge — the demo &lt;code&gt;web1&lt;/code&gt; holds &lt;code&gt;10.189.152.166&lt;/code&gt; on &lt;code&gt;eth0&lt;/code&gt;, and the stock image ships OpenSSH installed (though not running by default). Start sshd, inject an authorized key — cloud-init at launch or a one-off &lt;code&gt;lxc exec&lt;/code&gt; — and the container becomes &lt;strong&gt;just another inventory entry&lt;/strong&gt;. The same &lt;code&gt;apt&lt;/code&gt;, &lt;code&gt;systemd&lt;/code&gt; and &lt;code&gt;files&lt;/code&gt; modules that manage the host then manage the guest, over the same asyncssh transport. One library, both layers of the stack.&lt;/p&gt;

&lt;h3&gt;
  
  
  D. Moving files in and out
&lt;/h3&gt;

&lt;p&gt;The tutorial pushes a file into the container and pulls one out:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;lxc file push ./index.html web1/var/www/html/index.html
lxc file pull web1/etc/hostname ./hostname.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is no dedicated &lt;code&gt;lxd&lt;/code&gt; file operation, deliberately — transfers compose from primitives you already have. A file move from your control machine into a container is two hops: &lt;code&gt;files.put&lt;/code&gt; uploads control → host over the connection's scp channel (content-idempotent: it compares sha1 digests and transfers only on a difference), then a &lt;code&gt;Shell&lt;/code&gt; action runs &lt;code&gt;lxc file push&lt;/code&gt; host → container. Pulling is the mirror, with &lt;code&gt;files.get&lt;/code&gt; downloading host → control into a stream:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;io&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;reemote&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;Host&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Shell&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;files&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;gather_action&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;op&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;run&lt;/span&gt;

&lt;span class="c1"&gt;# Module level: the same stream object must reach both deploy phases.&lt;/span&gt;
&lt;span class="no"&gt;INDEX&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;io&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;StringIO&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"&amp;lt;h1&amp;gt;Hello from reemote&amp;lt;/h1&amp;gt;\n"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="no"&gt;HOSTNAME&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;io&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;BytesIO&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;stage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nf"&gt;op&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;files&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;put&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Stage index.html on the host"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;src&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="no"&gt;INDEX&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dest&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/tmp/index.html"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nf"&gt;op&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;files&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Fetch web1 hostname"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;src&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/tmp/web1-hostname.txt"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dest&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="no"&gt;HOSTNAME&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;INVENTORY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;stage&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;                    &lt;span class="c1"&gt;# control -&amp;gt; host&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;gather_action&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;Host&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;from_inventory&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="no"&gt;INVENTORY&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Shell&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;command&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"lxc file push /tmp/index.html web1/var/www/html/index.html"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;gather_action&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;Host&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;from_inventory&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="no"&gt;INVENTORY&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Shell&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;command&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"lxc file pull web1/etc/hostname /tmp/web1-hostname.txt"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;INVENTORY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;                    &lt;span class="c1"&gt;# host -&amp;gt; control&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;HOSTNAME&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getvalue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;                     &lt;span class="c1"&gt;# b'web1\n'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Verified output of the two transfers and the round-trip check:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ubuntu: Stage index.html on the host [changed: file /tmp/index.html missing or differs from the local source]
    $ scp &amp;lt;stream&amp;gt; -&amp;gt; /tmp/index.html
ubuntu: Fetch web1 hostname      [changed: local copy missing or differs from remote /tmp/web1-hostname.txt]
    $ scp /tmp/web1-hostname.txt -&amp;gt; &amp;lt;stream&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The push exited 0, and &lt;code&gt;lxc exec web1 -- cat /var/www/html/index.html&lt;/code&gt; returned exactly &lt;code&gt;&amp;lt;h1&amp;gt;Hello from reemote&amp;lt;/h1&amp;gt;&lt;/code&gt;. Re-running the staging deploy converges:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ubuntu: Stage index.html on the host [no change: file already up to date (/tmp/index.html)]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two practical notes. The tutorial's &lt;code&gt;/var/www/html&lt;/code&gt; path assumes a web-tier container; create it first if needed (&lt;code&gt;lxc exec web1 -- mkdir -p /var/www/html&lt;/code&gt;, itself a &lt;code&gt;Shell&lt;/code&gt; action). And the streams are defined at module level on purpose: reemote runs your deploy twice (prepare, then apply) and compares requests by identity, so a fresh &lt;code&gt;StringIO&lt;/code&gt; per phase would break the determinism guard.&lt;/p&gt;

&lt;h3&gt;
  
  
  E. Setting resource limits (CPU &amp;amp; RAM)
&lt;/h3&gt;

&lt;p&gt;The tutorial constrains the container like a VM:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;lxc config &lt;span class="nb"&gt;set&lt;/span&gt; web1 limits.cpu 2
lxc config &lt;span class="nb"&gt;set&lt;/span&gt; web1 limits.memory 1GiB
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In reemote the limits are already part of the &lt;code&gt;lxd.instance&lt;/code&gt; request above — creation carries them, and every later run reconciles them. The demo host's &lt;code&gt;web1&lt;/code&gt; had &lt;code&gt;limits.cpu=2&lt;/code&gt; but &lt;code&gt;limits.memory=2GB&lt;/code&gt;, so the verified plan flagged exactly the one drifted key:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ubuntu: Ensure web1              [changed: lxd instance web1 will be updated (config keys will be set: limits.memory)]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and the apply sent exactly one command — the CPU limit, already correct, was left alone:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    $ sudo lxc config set web1 limits.memory 1GiB --project default
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When you want the reconciliation half on its own — an instance that must already exist, no creation path — &lt;code&gt;lxd.instance_config&lt;/code&gt; does the same drift-only comparison of config keys, devices and profiles. Either way, limits are data in a tuple, not two shell lines you hope ran in order.&lt;/p&gt;

&lt;h3&gt;
  
  
  F. Snapshots and safety
&lt;/h3&gt;

&lt;p&gt;The tutorial takes a snapshot before a risky change and restores it if things break:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;lxc snapshot web1 before-upgrade
lxc restore web1 before-upgrade
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Creating the safety net is one more request in the same deploy:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;    &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nf"&gt;op&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lxd&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;instance_snapshot&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Safety net before changes"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;instance&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"web1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;snapshot&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"before-upgrade"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sudo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Verified plan and apply on a host where the snapshot did not exist yet:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ubuntu: Safety net before changes [changed: lxd snapshot web1/before-upgrade will be created]
    $ sudo lxc snapshot web1 before-upgrade --project default
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The operation is idempotent against the snapshot listing: once &lt;code&gt;before-upgrade&lt;/code&gt; exists, every later run reports &lt;code&gt;[no change: lxd snapshot web1/before-upgrade already exists]&lt;/code&gt; — a stable restore point, not a rolling one. &lt;code&gt;present=False&lt;/code&gt; deletes it; &lt;code&gt;stateful=True&lt;/code&gt; captures runtime state too.&lt;/p&gt;

&lt;p&gt;Restore is an &lt;strong&gt;action&lt;/strong&gt;, not a desired state — it always runs when you ask for it — and a non-stateful restore requires the instance to be stopped first. In reemote that sequence is ordinary composition:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;rollback&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nf"&gt;op&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lxd&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;instance_state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Stop web1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;instance&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"web1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"stopped"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sudo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nf"&gt;op&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lxd&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;instance_snapshot&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Roll back web1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;instance&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"web1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;snapshot&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"before-upgrade"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;restore&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sudo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nf"&gt;op&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lxd&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;instance_state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Start web1 again"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;instance&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"web1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"started"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sudo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Verified apply log:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ubuntu: Stop web1                [changed: lxd instance web1 will be stopped]
    $ sudo lxc stop web1 --project default
ubuntu: Roll back web1           [changed: lxd instance web1 will be restored to before-upgrade]
    $ sudo lxc restore web1 before-upgrade --project default
ubuntu: Start web1 again         [changed: lxd instance web1 will be started]
    $ sudo lxc start web1 --project default
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The dry-run plan of this same deploy shows the two-phase model earning its keep: &lt;code&gt;Stop web1&lt;/code&gt; and &lt;code&gt;Roll back web1&lt;/code&gt; plan as changes, but &lt;code&gt;Start web1 again&lt;/code&gt; plans as &lt;code&gt;[no change: lxd instance web1 already started]&lt;/code&gt; — because at plan time the container is still running. The apply phase advances all hosts in lockstep with a fresh fact cache per step, so by the time the start request is evaluated the stop has really happened, and it starts. Plan and apply agree on the &lt;em&gt;requests&lt;/em&gt;; the facts each phase sees are the honest ones.&lt;/p&gt;

&lt;h3&gt;
  
  
  Run it twice: convergence, verified
&lt;/h3&gt;

&lt;p&gt;Here is the whole first-steps deploy — launch-or-reconcile plus the safety net — as one script:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;asyncio&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;reemote&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;format_log&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;format_plan&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;lxd&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;op&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;run&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nf"&gt;op&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lxd&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;instance&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Ensure web1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;instance&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"web1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;image&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"ubuntu:24.04"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"limits.cpu=2"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"limits.memory=1GiB"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sudo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nf"&gt;op&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lxd&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;instance_snapshot&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Safety net before changes"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="n"&gt;instance&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"web1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;snapshot&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"before-upgrade"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sudo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;plans&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;report&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;INVENTORY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;format_plan&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;plans&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;report&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;format_log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;report&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;asyncio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first run produced the drift and snapshot output shown in E and F. Run the identical script again against the same host and it converges — verified:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ubuntu: Ensure web1              [no change: lxd instance web1 already exists as configured]
ubuntu: Safety net before changes [no change: lxd snapshot web1/before-upgrade already exists]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is the property the CLI tutorial cannot give you: &lt;code&gt;lxc launch&lt;/code&gt; fails on an existing name, &lt;code&gt;lxc snapshot&lt;/code&gt; fails on an existing snapshot, and a shell script accumulates &lt;code&gt;|| true&lt;/code&gt; guards. A reemote deploy describes the state you want and reports, per request, whether anything had to move.&lt;/p&gt;

&lt;h2&gt;
  
  
  What follows: Reemote can manage LXD instead of Ansible
&lt;/h2&gt;

&lt;p&gt;Once configuration management is a library, everything Python already has becomes available to your LXD deploys:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Deploy from your application.&lt;/strong&gt; &lt;code&gt;await run(inventory, deploy)&lt;/code&gt; inside a FastAPI handler, a Celery task, or a REPL — provision a container per tenant without shelling out to a playbook runner.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Compose with real code.&lt;/strong&gt; Build the inventory from a database query; generate per-container limits from a Pydantic model; loop a fleet into existence with a &lt;code&gt;for&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Test with &lt;code&gt;pytest&lt;/code&gt;.&lt;/strong&gt; Deploy functions are pure generators — assert on the requests they yield without a server in sight.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Consume structured results.&lt;/strong&gt; &lt;code&gt;report.entries[i].changed&lt;/code&gt;, &lt;code&gt;.reason&lt;/code&gt;, &lt;code&gt;.commands&lt;/code&gt; are data you can log, chart, feed to a webhook, or gate a rollout on. Snapshot → upgrade → restore-on-failure is an &lt;code&gt;if&lt;/code&gt;, not a handler syntax.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Two-phase execution for free.&lt;/strong&gt; Every &lt;code&gt;run&lt;/code&gt; prepares then applies; &lt;code&gt;dry=True&lt;/code&gt; is a real preview against live facts, not a simulation.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;One library for host and guest.&lt;/strong&gt; Manage the LXD host with &lt;code&gt;lxd&lt;/code&gt;, then point the same &lt;code&gt;apt&lt;/code&gt;/&lt;code&gt;systemd&lt;/code&gt;/&lt;code&gt;files&lt;/code&gt; modules at the containers it runs. The transport, the determinism guard and the report shape do not change.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Handlers as ordinary Python.&lt;/strong&gt; Read the first deploy's report, freeze the changed hosts with &lt;code&gt;reemote.handlers.changed_hosts&lt;/code&gt;, feed them into a second deploy.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can use reemote instead of Ansible whenever managing LXD is part of a Python program rather than a shell command in a CI job — and you keep LXD's own vocabulary (instances, profiles, projects, devices, snapshots) intact instead of flattening it through a lowest-common-denominator container module.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Reemote is not
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Not a deployment CLI.&lt;/strong&gt; There is no &lt;code&gt;reemote&lt;/code&gt; command; you write the script.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Not an inventory format.&lt;/strong&gt; Inventory is a Python list of dicts — load it from JSON, YAML, a database, or write it inline.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Not an LXD API client.&lt;/strong&gt; Reemote drives the &lt;code&gt;lxc&lt;/code&gt; CLI on the host, exactly as the tutorial does; it does not embed a REST SDK or poll the daemon's operations endpoint.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Not a role ecosystem.&lt;/strong&gt; Reemote ships modules for &lt;code&gt;apt&lt;/code&gt;, &lt;code&gt;systemd&lt;/code&gt;, &lt;code&gt;apk&lt;/code&gt;, &lt;code&gt;openrc&lt;/code&gt;, &lt;code&gt;dnf&lt;/code&gt;, &lt;code&gt;files&lt;/code&gt;, &lt;code&gt;server&lt;/code&gt;, &lt;code&gt;git&lt;/code&gt;, &lt;code&gt;mysql&lt;/code&gt;, &lt;code&gt;postgresql&lt;/code&gt;, &lt;code&gt;iptables&lt;/code&gt;, &lt;code&gt;firewalld&lt;/code&gt;, &lt;code&gt;ufw&lt;/code&gt;, &lt;code&gt;selinux&lt;/code&gt;, &lt;code&gt;lxd&lt;/code&gt;, &lt;code&gt;snap&lt;/code&gt;, &lt;code&gt;flatpak&lt;/code&gt;, &lt;code&gt;sysctl&lt;/code&gt;, &lt;code&gt;gpg&lt;/code&gt;, and &lt;code&gt;hardware&lt;/code&gt; — but there is no Ansible Galaxy equivalent.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Not a replacement for &lt;code&gt;lxc shell&lt;/code&gt;.&lt;/strong&gt; Interactive debugging stays interactive; reemote is for the programmable half.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Documentation and full guide: &lt;a href="https://reemote.org/" rel="noopener noreferrer"&gt;https://reemote.org/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;lxd&lt;/code&gt; module reference: &lt;a href="https://reemote.org/modules/lxd/" rel="noopener noreferrer"&gt;https://reemote.org/modules/lxd/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Source and runnable examples: &lt;a href="https://github.com/kimjarvis/reemote" rel="noopener noreferrer"&gt;https://github.com/kimjarvis/reemote&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;PyPI: &lt;code&gt;pip install reemote&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;License: EPL-2.0&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you have ever wanted Canonical's first-steps tutorial to be a program you can import, test and &lt;code&gt;await&lt;/code&gt; — with the launch, the limits, the snapshot and the rollback all reporting themselves as data — the walkthrough above is the whole onboarding. Give it an Ubuntu host and a minute.&lt;/p&gt;

</description>
      <category>showdev</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Migrating Ansible roles to Python: a library-level translation target</title>
      <dc:creator>Kim Jarvis</dc:creator>
      <pubDate>Sun, 15 Nov 2026 09:56:40 +0000</pubDate>
      <link>https://dev.to/kimbofab/migrating-ansible-roles-to-python-a-library-level-translation-target-58gc</link>
      <guid>https://dev.to/kimbofab/migrating-ansible-roles-to-python-a-library-level-translation-target-58gc</guid>
      <description>&lt;h2&gt;
  
  
  Abstract
&lt;/h2&gt;

&lt;p&gt;When a large language model rewrites an Ansible role in ordinary Python, the result typically executes but does not behave like the role it replaces: fleet-wide lock-step execution, dry-run capability, and per-host change reporting are lost. We argue that the cause is structural rather than a deficit of model capability: translation tasks succeed when a canonical target idiom exists, and Python has lacked a configuration-management library for the model to translate into. We survey prior Python-based approaches — programmatic control of Ansible, general remote-execution libraries, and Python-native configuration management — with particular attention to pyinfra, the closest existing analogue, which we find falls short as a translation target on five axes: its concurrency model is not built on asyncio, its results interface is oriented toward the command line rather than a typed return value, its module vocabulary covers a fraction of Ansible's, its deploys read mutable live state without a determinism guarantee, and its file operations depend on the controller's file system. We then describe Reemote, an open-source library designed against these five criteria, and report an evaluation in which two Ansible Galaxy roles were converted automatically and verified for idempotence in an offline simulation.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Introduction
&lt;/h2&gt;

&lt;p&gt;Ansible expresses server configuration as declarative playbooks and roles in YAML [1]. The language is widely deployed, but it offers limited support for the surrounding engineering practice: infrastructure logic is not unit-testable with ordinary Python test frameworks, is not checkable with static type analysis, and cannot directly express computations that exceed the limits of a declarative DSL with a templating dialect.&lt;/p&gt;

&lt;p&gt;Migrating roles to Python would recover these properties, and large language models make such a migration appear cheap: a role can be pasted into a model with the instruction to rewrite it in Python. The output, however, is typically a script that shells out to package managers and wraps the sequence in error handling — a program that reproduces the role's happy path while discarding the machinery that made the role operable.&lt;/p&gt;

&lt;p&gt;This paper examines why. Section 2 surveys prior work and analyses pyinfra, the closest prior approach, against five requirements of a translation target. Section 3 formulates the problem: the properties a translated program loses, and the motivation for reaching Python without losing them. Section 4 describes the design of Reemote [15], an open-source library that implements configuration management as a library rather than a command-line tool. Section 5 reports an evaluation in which two Galaxy roles were converted automatically, and Section 6 states the limitations of that evaluation.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Prior work
&lt;/h2&gt;

&lt;h3&gt;
  
  
  2.1 Programmatic control of Ansible
&lt;/h3&gt;

&lt;p&gt;The most direct approach to operating Ansible from Python is to keep Ansible. &lt;code&gt;ansible-runner&lt;/code&gt; [2] provides a stable interface for launching playbooks and consuming their events; Ansible's internal Python API exposes playbook parsing and execution. Neither removes Ansible from the execution path: the YAML, the state engine, and the CLI-shaped result all remain. These tools wrap Ansible; they do not provide a Python vocabulary of configuration operations that a translator could map roles onto.&lt;/p&gt;

&lt;h3&gt;
  
  
  2.2 Remote-execution libraries
&lt;/h3&gt;

&lt;p&gt;Fabric [3] and Paramiko [4] provide SSH connectivity and remote command execution. They operate at the level of shell commands: there are no facts that describe host state, no operations that compare desired and actual state, and no change reporting beyond command exit status. They are the primitives that an improvised translation reaches for, not a target idiom for one.&lt;/p&gt;

&lt;h3&gt;
  
  
  2.3 Python-native configuration management
&lt;/h3&gt;

&lt;p&gt;Salt [5] implements configuration management in Python, but as a distributed system — a daemon on each managed host (or an agentless SSH mode) driven by a CLI and its own state and pillar subsystems. It is not designed to be imported and called as a library, and its state language is a domain-specific system of its own rather than an idiom an arbitrary model can map Ansible tasks onto.&lt;/p&gt;

&lt;p&gt;pyinfra [6] is the closest existing analogue to the missing target. Deploys are Python files; operations are Python functions that compare desired state against facts and yield commands only when a change is required; execution is two-phase, with a preparation phase that gathers facts and an execution phase that applies commands, which enables a &lt;code&gt;--dry&lt;/code&gt; flag [7]. pyinfra is agentless and Python-native, and its operation functions are generator functions that read facts and yield commands [8] — a shape recognisably similar to the one this paper argues for.&lt;/p&gt;

&lt;h3&gt;
  
  
  2.4 pyinfra as a translation target
&lt;/h3&gt;

&lt;p&gt;Despite this similarity, five documented characteristics of pyinfra limit its suitability as the destination for an automated Ansible-to-Python translation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Concurrency model.&lt;/strong&gt; pyinfra's concurrency is built on gevent and its SSH transport on Paramiko [9]. Neither belongs to the asyncio ecosystem: a pyinfra run cannot be awaited from an asyncio event loop, and a program already built on asyncio must bridge between the two concurrency models or delegate the run to a subprocess.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Results interface.&lt;/strong&gt; pyinfra's primary interface is a CLI that writes results to the terminal [7]. A program that needs to know what changed consumes either human-readable output or, in pyinfra 3, the &lt;code&gt;--json&lt;/code&gt; serialisation of that CLI output [10]. When pyinfra is used in API mode, results are accumulated in the global &lt;code&gt;State&lt;/code&gt; object during the run rather than returned by the call that performs it. There is no typed, per-operation report returned from a library call, with each entry recording whether it changed anything, why, and the exact commands sent.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Module vocabulary.&lt;/strong&gt; pyinfra bundles 46 operation modules [11]. Ansible's ecosystem spans several thousand modules across its collections [12], and Ansible roles routinely draw on domains that pyinfra does not cover: firewall management beyond &lt;code&gt;iptables&lt;/code&gt; (&lt;code&gt;firewalld&lt;/code&gt;, &lt;code&gt;ufw&lt;/code&gt;), kernel parameter configuration (&lt;code&gt;sysctl&lt;/code&gt;), GPG keyring management, and hardware inventory are absent from pyinfra's module list [11]. A role that touches such a domain has no destination operation; the translator must invent one, which is precisely the unbounded generation this paper argues against.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Purity and idempotence.&lt;/strong&gt; pyinfra's idempotence is a per-operation convention: an operation compares facts to arguments and yields commands only when needed [8]. It is not an enforced global property. Deploy code reads mutable live state as it is evaluated — facts are fetched from hosts while operation functions are called [7] — and the framework documents that operations depending on the changes of earlier operations observe stale facts on the first run, leaving them inoperative until a re-run or an explicit hint such as &lt;code&gt;assume_present&lt;/code&gt; [7]. Several bundled operations are documented as stateless and non-idempotent, including &lt;code&gt;apt.ppa&lt;/code&gt;, &lt;code&gt;apt.update&lt;/code&gt;, &lt;code&gt;files.get&lt;/code&gt;, and &lt;code&gt;files.rsync&lt;/code&gt; [11]. There is no mechanism that verifies a deploy would produce the same plan if evaluated again; the determinism of a deploy depends on the discipline of its author.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Controller file-system awareness.&lt;/strong&gt; pyinfra's file operations take paths on the machine running pyinfra: &lt;code&gt;files.put&lt;/code&gt; resolves &lt;code&gt;src&lt;/code&gt; relative to the deploy directory by default, &lt;code&gt;files.template&lt;/code&gt; reads a template file from the controller (the documented convention is a &lt;code&gt;templates/&lt;/code&gt; directory, with the current working directory as the default lookup path), and &lt;code&gt;files.get&lt;/code&gt; and &lt;code&gt;files.sync&lt;/code&gt; write to and read from controller directories [13]. A deploy's behaviour therefore depends on the disk layout of the controller, and a translator must reproduce these search-path rules to preserve meaning.&lt;/p&gt;

&lt;p&gt;None of the surveyed approaches provides a library that is asyncio-native, returns structured results, covers Ansible's module vocabulary, enforces deploy determinism, and is independent of the controller's file system. The remainder of this paper describes a design that does.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Problem statement
&lt;/h2&gt;

&lt;h3&gt;
  
  
  3.1 Properties lost in translation
&lt;/h3&gt;

&lt;p&gt;An Ansible role inherits three operational guarantees from the engine that runs it [1], and a translation into ordinary Python — with no target framework — loses all three.&lt;/p&gt;

&lt;p&gt;The first is lock-step execution across multiple hosts. Ansible advances a fleet through a playbook together, parallelising each task across hosts while preserving task order. A naive translation collapses this into a sequential loop or an improvised concurrency scheme that no longer preserves ordering.&lt;/p&gt;

&lt;p&gt;The second is dry-run capability. Ansible's &lt;code&gt;--check&lt;/code&gt; mode previews what would change against live infrastructure before anything is modified [1]. Ad-hoc generated scripts execute their mutations without a plan to inspect, because they never separated deciding from doing.&lt;/p&gt;

&lt;p&gt;The third is change identification. Ansible reports, per task and per host, whether state was modified, already correct, or failed. A translated script emits terminal text at best; recovering the same information from standard output is fragile and version-dependent.&lt;/p&gt;

&lt;h3&gt;
  
  
  3.2 Why Python
&lt;/h3&gt;

&lt;p&gt;The motivation for migration is that Python offers properties the YAML DSL does not, provided the three guarantees above are preserved. Infrastructure logic becomes ordinary code: testable with standard frameworks such as &lt;code&gt;pytest&lt;/code&gt;, analysable with type checkers and linters before deployment, and expressible without the ceiling of a declarative language. Variables become function arguments and typed data structures rather than a templating dialect, and complex data transformations can live beside deployment logic instead of being shelled out to a second toolchain.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Design of a translation target
&lt;/h2&gt;

&lt;p&gt;The design question is what architectural properties a Python library must have for an AI translation of an Ansible role to be bounded and reviewable. We implemented these properties in Reemote [15], and we argue each removes one class of decisions the translator would otherwise have to make.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Asynchronous execution on asyncssh.&lt;/strong&gt; The entire execution path — connecting, gathering facts, sending commands — is built on Python's &lt;code&gt;async&lt;/code&gt; machinery and the asyncssh transport [14]. Hosts progress concurrently, network waits overlap across the fleet, and each host's commands remain strictly ordered. The generated code does not handle this concurrency: a deploy is a plain synchronous generator, and the runtime supplies the parallelism. The translator therefore works within an existing concurrency framework rather than constructing one — and the result is directly composable with asyncio-based programs, addressing the first pyinfra limitation of Section 2.4.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Structured results.&lt;/strong&gt; A run returns data, not terminal output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;plans&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;report&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;hosts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;inventory&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The plans describe the proposed work per host; the report carries one entry per applied operation, each recording whether it changed anything, why, and the exact commands sent. A &lt;code&gt;dry=True&lt;/code&gt; flag stops after planning and returns the plan as data a program can assert on. Reading a field such as &lt;code&gt;entry.changed&lt;/code&gt; is a common data-access pattern in training data; parsing CLI output is not.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Module vocabulary mapped to Ansible.&lt;/strong&gt; Twenty modules cover package management (&lt;code&gt;apt&lt;/code&gt;, &lt;code&gt;dnf&lt;/code&gt;, &lt;code&gt;apk&lt;/code&gt;, &lt;code&gt;snap&lt;/code&gt;, &lt;code&gt;flatpak&lt;/code&gt;), files and version control, services (&lt;code&gt;systemd&lt;/code&gt;, &lt;code&gt;openrc&lt;/code&gt;), firewalls (&lt;code&gt;firewalld&lt;/code&gt;, &lt;code&gt;iptables&lt;/code&gt;, &lt;code&gt;ufw&lt;/code&gt;), system configuration (&lt;code&gt;server&lt;/code&gt;, &lt;code&gt;sysctl&lt;/code&gt;, &lt;code&gt;selinux&lt;/code&gt;, &lt;code&gt;hardware&lt;/code&gt;), keys (&lt;code&gt;gpg&lt;/code&gt;), databases (&lt;code&gt;mysql&lt;/code&gt;, &lt;code&gt;postgresql&lt;/code&gt;), and containers (&lt;code&gt;lxd&lt;/code&gt;). Each module implements its domain as operations paired with the facts they read, so &lt;code&gt;apt_repository&lt;/code&gt; maps to &lt;code&gt;apt.repo&lt;/code&gt;, &lt;code&gt;lineinfile&lt;/code&gt; to &lt;code&gt;files.edit&lt;/code&gt;, &lt;code&gt;get_url&lt;/code&gt; to &lt;code&gt;files.download&lt;/code&gt;, and &lt;code&gt;service&lt;/code&gt; to &lt;code&gt;systemd.service&lt;/code&gt;. The vocabulary is the main enabler of translation: an Ansible task becomes a function call that already exists — a bounded mapping the model can perform and a human can review.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pure functional deploys.&lt;/strong&gt; Every deploy is a pure generator function of its host, and the runner executes it twice — once to plan against live facts, once to apply — raising a &lt;code&gt;DeterminismError&lt;/code&gt; if the two passes disagree. This addresses the fourth pyinfra limitation directly: purity is not left to author discipline but enforced by the runtime, and a deploy that reads mutable state (a stray &lt;code&gt;datetime.now()&lt;/code&gt;, a fact consulted at the wrong time) is rejected at plan time. The property also makes generated code testable without live servers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;No awareness of the controller's file system.&lt;/strong&gt; Deploys take content as explicit strings or caller-opened streams, never controller paths; file transfers between hosts are remote-to-remote. A converted program is self-contained and portable: it behaves identically regardless of where it is invoked from, and the translator does not need to reproduce any controller-side directory-search rules, addressing the fifth limitation.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Evaluation
&lt;/h2&gt;

&lt;p&gt;To examine whether these properties support automated conversion in practice, two Ansible Galaxy roles were converted with an AI agent given the library's module reference as context. The subjects were Jeff Geerling's Apache role [16], which installs and configures Apache across several operating-system families, and the agent role published by Datadog [17], a larger configuration spanning repositories, signing keys, templated configuration, and service handlers.&lt;/p&gt;

&lt;p&gt;The converted programs are publicly available in the Reemote repository under &lt;code&gt;examples/roles/&lt;/code&gt; [16]. The Apache conversion is an 887-line program expressing the role's Debian/Ubuntu path; the Datadog conversion runs to 1,558 lines. Both are sequences of small deploys rather than monoliths: where a role branches on a mutable read — a probed Apache version, an enumerated certificate directory — the conversion gathers the fact between runs, freezes the answer, and closes a deploy factory over it. Handlers become a second deploy pass filtered by the first pass's structured report, replacing Ansible's &lt;code&gt;notify&lt;/code&gt; keyword with ordinary Python.&lt;/p&gt;

&lt;p&gt;Each converted program is exercised end-to-end in an offline test suite against a simulated host, through the library's real execution driver. The central assertion is idempotence: after a complete first run, a second run against the same state must report no changes anywhere and queue no restart handlers. Both conversions pass.&lt;/p&gt;

&lt;p&gt;The conversion also served as a stress test of the library. Mapping the Datadog role exposed five capability gaps — additive import of multiple signing keys into a shared keyring, read-back of service-owned configuration files, idempotent "latest" upgrades, index refresh after repository changes, and provenance-aware repository removal. All five were closed in the library, and the converted program simplified as each fix landed; one remaining gap is confined to the offline test harness and is bridged by a documented test-local shim. We note this as a feedback loop between converter and target: each conversion exposed gaps, the gaps were closed in the library, and the conversion simplified in turn.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Limitations
&lt;/h2&gt;

&lt;p&gt;The evaluation is narrow. Each conversion covers the role's default path on a single operating-system family; the verification runs against simulated hosts rather than a live fleet; and the subject set is two roles. Reemote is the translation target, not the translator itself: the AI performs the mapping and a human reviews it. There is no Galaxy-equivalent ecosystem of third-party deploys, and choosing the correct module for the target operating system remains a manual step. The comparison in Section 2.4 rests on pyinfra's documented behaviour as of its 3.x release; pyinfra is actively developed, and individual limitations may narrow over time.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Conclusion
&lt;/h2&gt;

&lt;p&gt;For AI-assisted infrastructure migration, the properties of the target library matter more than the choice of model. Where the library's vocabulary lines up with Ansible's, the task reduces from designing a bespoke architecture to mapping each task onto an operation that already exists — a bounded mapping a human can review.&lt;/p&gt;

&lt;p&gt;The survey of prior work found no Python library meeting the five criteria of Section 4; the closest, pyinfra, provides the right conceptual shape but lacks asyncio-native execution, a typed results interface, Ansible-scale module coverage, enforced deploy determinism, and controller-independence. Reemote [15] is an implementation of those criteria, distributed via PyPI under the EPL-2.0 license. Within the scope of the evaluated paths, the converted roles indicate that package, file, service, and handler logic can survive translation with concurrency, dry-run preview, and structured change reporting supplied by the library rather than improvised by the model.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;a href="https://docs.ansible.com/" rel="noopener noreferrer"&gt;Ansible documentation&lt;/a&gt; — playbooks, check mode, and change reporting.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://ansible.readthedocs.io/projects/ansible-runner/" rel="noopener noreferrer"&gt;ansible-runner&lt;/a&gt; — a stable Python interface for launching and consuming Ansible runs.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.fabfile.org/" rel="noopener noreferrer"&gt;Fabric&lt;/a&gt; — remote SSH command execution in Python.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.paramiko.org/" rel="noopener noreferrer"&gt;Paramiko&lt;/a&gt; — a Python SSH library.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://docs.saltproject.io/" rel="noopener noreferrer"&gt;Salt documentation&lt;/a&gt; — Python-implemented, daemon-based configuration management.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://pyinfra.com/" rel="noopener noreferrer"&gt;pyinfra&lt;/a&gt; — agentless infrastructure automation in Python.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://docs.pyinfra.com/en/3.x/deploy-process.html" rel="noopener noreferrer"&gt;pyinfra: Deploy Execution&lt;/a&gt; — two-phase execution, fact gathering at operation-definition time, and the interdependent-operations limitation.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://docs.pyinfra.com/en/3.x/api/operations.html" rel="noopener noreferrer"&gt;pyinfra: Writing Operations&lt;/a&gt; — operations as generator functions that read facts and yield commands.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/pyinfra-dev/pyinfra" rel="noopener noreferrer"&gt;pyinfra source repository&lt;/a&gt; — the 3.x branch declares gevent and paramiko as dependencies.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://docs.pyinfra.com/en/3.x/cli.html" rel="noopener noreferrer"&gt;pyinfra: Using the CLI&lt;/a&gt; — terminal output and the &lt;code&gt;--json&lt;/code&gt; serialisation flag.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://docs.pyinfra.com/en/3.x/operations.html" rel="noopener noreferrer"&gt;pyinfra: Operations Index&lt;/a&gt; — the bundled module list and the stateless/non-idempotent annotations.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://docs.ansible.com/ansible/latest/collections/index.html" rel="noopener noreferrer"&gt;Ansible collection index&lt;/a&gt; — the scale and breadth of Ansible's module ecosystem.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://docs.pyinfra.com/en/3.x/operations/files.html" rel="noopener noreferrer"&gt;pyinfra: files Operations&lt;/a&gt; — controller-side paths in &lt;code&gt;files.put&lt;/code&gt;, &lt;code&gt;files.template&lt;/code&gt;, &lt;code&gt;files.get&lt;/code&gt;, and &lt;code&gt;files.sync&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://asyncssh.readthedocs.io/" rel="noopener noreferrer"&gt;asyncssh&lt;/a&gt; — asynchronous SSH for Python.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://reemote.org/" rel="noopener noreferrer"&gt;Reemote&lt;/a&gt; — documentation; source at &lt;a href="https://github.com/kimjarvis/reemote" rel="noopener noreferrer"&gt;github.com/kimjarvis/reemote&lt;/a&gt;; &lt;code&gt;pip install reemote&lt;/code&gt; (EPL-2.0).&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/geerlingguy/ansible-role-apache" rel="noopener noreferrer"&gt;geerlingguy/ansible-role-apache&lt;/a&gt; — the Apache role; its converted form lives at &lt;a href="https://github.com/kimjarvis/reemote/tree/main/examples/roles" rel="noopener noreferrer"&gt;examples/roles/ansible-role-apache&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/DataDog/ansible-datadog" rel="noopener noreferrer"&gt;DataDog/ansible-datadog&lt;/a&gt; — the Datadog agent role; its converted form lives at &lt;a href="https://github.com/kimjarvis/reemote/tree/main/examples/roles" rel="noopener noreferrer"&gt;examples/roles/ansible-datadog&lt;/a&gt;.&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>showdev</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Why AI translations of Ansible roles fail — and the Python library designed to fix them</title>
      <dc:creator>Kim Jarvis</dc:creator>
      <pubDate>Sun, 15 Nov 2026 09:19:34 +0000</pubDate>
      <link>https://dev.to/kimbofab/why-ai-translations-of-ansible-roles-fail-and-the-python-library-designed-to-fix-them-5bbf</link>
      <guid>https://dev.to/kimbofab/why-ai-translations-of-ansible-roles-fail-and-the-python-library-designed-to-fix-them-5bbf</guid>
      <description>&lt;h1&gt;
  
  
  Why AI translations of Ansible roles fail — and the Python library designed to fix them
&lt;/h1&gt;

&lt;p&gt;&lt;em&gt;A study of AI-driven code translation finds that converting Ansible configuration roles into Python systematically loses the properties that made them safe to run on production infrastructure. The cause is structural rather than a deficit of model capability: Python has lacked a configuration-management library for the model to translate into. An open-source library, Reemote, is presented as that target, and the approach is evaluated through an automated conversion of popular Ansible Galaxy roles — including Jeff Geerling's canonical roles — into Python.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;When a large language model is asked to rewrite an Ansible role in Python, the result typically runs: it imports &lt;code&gt;subprocess&lt;/code&gt;, shells out to &lt;code&gt;apt-get&lt;/code&gt;, checks a return code, and wraps the sequence in a &lt;code&gt;try/except&lt;/code&gt;. What it does not do is behave like the role it replaced. A new evaluation of AI-driven configuration-code translation examines this gap, identifies its structural cause, and reports an experiment in which supplying a dedicated target library yields bounded, reviewable programs rather than improvised scripts.&lt;/p&gt;

&lt;h2&gt;
  
  
  Lost in translation
&lt;/h2&gt;

&lt;p&gt;Ansible is not merely a list of commands. It is a declarative orchestration engine, and a role inherits a set of operational guarantees from the engine that runs it. The study finds that when an AI translates a role into ordinary Python without a specialised target framework, three of these guarantees are systematically lost.&lt;/p&gt;

&lt;p&gt;The first is &lt;strong&gt;lock-step execution across multiple hosts&lt;/strong&gt;. Ansible advances a fleet of machines through a playbook together, parallelising each task across hosts while keeping the task order intact. A naive translation collapses this into a sequential loop, or into an improvised concurrency scheme that no longer preserves the ordering the role depended on.&lt;/p&gt;

&lt;p&gt;The second is &lt;strong&gt;dry-run capability&lt;/strong&gt;. Ansible's &lt;code&gt;--check&lt;/code&gt; mode previews what would change against live infrastructure before anything is touched. Ad-hoc generated scripts execute their mutations blind; there is no plan to inspect, because the script never separated deciding from doing.&lt;/p&gt;

&lt;p&gt;The third is &lt;strong&gt;change identification&lt;/strong&gt;. Ansible reports, per task and per host, whether state was actually modified, already correct, or failed. A translated script emits terminal text at best. Recovering the same information means scraping standard output with regular expressions — fragile, version-dependent, and rarely attempted by generated code.&lt;/p&gt;

&lt;p&gt;The result is a program that reproduces the role's happy path while discarding the machinery that made it operable: no fleet orchestration, no preview, no reliable account of what changed.&lt;/p&gt;

&lt;h2&gt;
  
  
  A missing pattern, not a missing capability
&lt;/h2&gt;

&lt;p&gt;The root cause, the work argues, is neither model capacity nor context length. Large language models generate by matching patterns they have seen, and translation tasks succeed when a canonical target idiom exists to converge on. Compiling C to assembly or converting JSON to a dataclass works because the destination shape appears millions of times in training data.&lt;/p&gt;

&lt;p&gt;"Translate an Ansible role to Python" has no such destination. Historically, Python has lacked a dedicated configuration-management library mirroring Ansible's conceptual shape — typed facts, idempotent operations, a unified module vocabulary. What exists instead are wrappers that launch Ansible itself, general SSH-automation frameworks, and raw building blocks such as &lt;code&gt;paramiko&lt;/code&gt; and &lt;code&gt;subprocess&lt;/code&gt;. None of them is a configuration-management idiom.&lt;/p&gt;

&lt;p&gt;With no pattern to match, the model improvises from the nearest primitives it knows, reinventing a flawed configuration engine with every generation. Repeated runs, or different models, produce different arrangements. The authors report that spending more tokens produces longer, better-commented output but not convergence: prompting cannot supply an idiom that does not yet exist.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Python is worth the effort
&lt;/h2&gt;

&lt;p&gt;The motivation for the work is that Python offers advantages over Ansible's YAML-based domain-specific language, provided the operational guarantees can be preserved.&lt;/p&gt;

&lt;p&gt;Infrastructure logic becomes ordinary code: testable with standard frameworks such as &lt;code&gt;pytest&lt;/code&gt;, analysable with type checkers and linters that catch errors at development time rather than on production nodes. Complex data transformations, API integrations, and machine-learning pipelines can live beside deployment logic instead of being shelled out to. Variables become function arguments and typed data structures rather than a templating dialect with its own precedence rules. Logic that exceeds the expressive limits of a declarative DSL can be written directly in the host language.&lt;/p&gt;

&lt;p&gt;What has been missing is a way to reach those advantages without surrendering idempotence, orchestration, and change reporting on the way.&lt;/p&gt;

&lt;h2&gt;
  
  
  Five properties of a translation target
&lt;/h2&gt;

&lt;p&gt;The solution examined in the work is &lt;strong&gt;Reemote&lt;/strong&gt;, an open-source Python package that implements configuration management as a library rather than a command-line tool. The study characterises five architectural properties that make it a viable destination for AI translation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Asynchronous execution on asyncssh.&lt;/strong&gt; The entire execution path — connecting, gathering facts, sending commands — is built on Python's &lt;code&gt;async&lt;/code&gt; machinery and the &lt;code&gt;asyncssh&lt;/code&gt; transport. Hosts progress concurrently, network waits overlap across the fleet, and each host's commands remain strictly ordered. The generated code does not handle this complexity directly: a deploy is a plain synchronous generator, and the runtime supplies the concurrency. The model therefore works within an existing concurrency framework rather than constructing one.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Structured results instead of a CLI.&lt;/strong&gt; A run returns data, not terminal output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;plans&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;report&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;hosts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;inventory&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The plans describe the proposed work per host; the report carries one entry per applied operation, each recording whether it changed anything, why, and the exact commands sent. The authors describe structured returns as essential for automation, and for translation: reading a field such as &lt;code&gt;entry.changed&lt;/code&gt; is a common data-access pattern in training data, whereas parsing Ansible's callback output is not. A &lt;code&gt;dry=True&lt;/code&gt; flag stops after planning, restoring the lost dry-run capability as a return value a program can assert on.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Comprehensive modules with a one-to-one Ansible vocabulary.&lt;/strong&gt; Twenty modules cover package management (&lt;code&gt;apt&lt;/code&gt;, &lt;code&gt;dnf&lt;/code&gt;, &lt;code&gt;apk&lt;/code&gt;, &lt;code&gt;snap&lt;/code&gt;, &lt;code&gt;flatpak&lt;/code&gt;), files and version control, services, firewalls, system configuration, keys, databases, and containers. Each implements its domain as operations paired with the facts they read, so &lt;code&gt;apt_repository&lt;/code&gt; maps to &lt;code&gt;apt.repo&lt;/code&gt;, &lt;code&gt;lineinfile&lt;/code&gt; to &lt;code&gt;files.edit&lt;/code&gt;, &lt;code&gt;get_url&lt;/code&gt; to &lt;code&gt;files.download&lt;/code&gt;, and &lt;code&gt;service&lt;/code&gt; to &lt;code&gt;systemd.service&lt;/code&gt;. The work identifies this vocabulary as the main enabler of translation: Ansible tasks become Python routine and function calls — a bounded mapping the model can perform and a human can review — instead of an architecture the model must design.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pure functional deploys.&lt;/strong&gt; Every deploy is a pure generator function of its host, and the runner executes it twice — once to plan against live facts, once to apply — raising a determinism error if the two passes disagree. For AI-generated code, this makes the output testable without live servers, and typical model mistakes such as a stray &lt;code&gt;datetime.now()&lt;/code&gt; are caught at plan time rather than in production.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;No awareness of the controller's file system.&lt;/strong&gt; Ansible resolves &lt;code&gt;copy&lt;/code&gt; and &lt;code&gt;template&lt;/code&gt; sources through implicit search paths relative to the role's directories, coupling a playbook to the disk layout of the machine running it. Reemote deploys take content as explicit strings or caller-opened streams, never controller paths. A converted program is therefore self-contained and portable: it behaves identically regardless of where it is invoked from, and the translator does not need to reproduce Ansible's implicit directory-search rules.&lt;/p&gt;

&lt;h2&gt;
  
  
  The experiment: Galaxy roles, converted
&lt;/h2&gt;

&lt;p&gt;To validate the approach, an empirical evaluation was conducted in which popular Ansible Galaxy roles were converted automatically, with an AI agent given the library's module reference as context. The subjects included Jeff Geerling's widely used Apache role — which installs and configures Apache across four operating-system families — and DataDog's official agent role, a larger configuration spanning repositories, signing keys, templated configuration, and service handlers.&lt;/p&gt;

&lt;p&gt;The resulting Python programs are publicly available in the Reemote git repository, under &lt;code&gt;examples/roles/&lt;/code&gt;. The Apache conversion is an 888-line program expressing the role's Debian/Ubuntu path; the DataDog conversion runs to 1,559 lines. Both are sequences of small deploys rather than monoliths: where a role branches on a mutable read — a probed Apache version, an enumerated certificate directory — the conversion gathers the fact between runs, freezes the answer, and closes a deploy factory over it. Handlers become a second deploy pass filtered by the first pass's structured report, replacing Ansible's &lt;code&gt;notify&lt;/code&gt; keyword with ordinary Python.&lt;/p&gt;

&lt;p&gt;Each converted program is exercised end-to-end in an offline test suite against a simulated host, through the library's real execution driver. The central assertion is idempotence: after a complete first run, a second run against the same state must report no changes anywhere and queue no restart handlers. Both conversions pass.&lt;/p&gt;

&lt;p&gt;The experiment also functioned as a stress test of the library itself. Mapping the DataDog role exposed five capability gaps in the library — additive import of multiple signing keys into a shared keyring, read-back of service-owned configuration files, idempotent "latest" upgrades, index refresh after repository changes, and provenance-aware repository removal. All five were subsequently closed in the library, and the converted program simplified as each fix landed. One remaining gap is confined to the offline test harness rather than real execution, and is bridged by a documented test-local shim. The authors note a feedback loop in which each conversion exposed gaps, the gaps were closed in the library, and the converted program simplified in turn. The evaluation is scoped: each conversion covers the role's default path on a single operating-system family, and the reported verification runs against simulated hosts rather than a live fleet.&lt;/p&gt;

&lt;h2&gt;
  
  
  What follows
&lt;/h2&gt;

&lt;p&gt;The authors conclude that for AI-assisted infrastructure migration, the choice of Python library matters more than the choice of model. With a comprehensive configuration-management library whose vocabulary lines up with Ansible's, the task reduces from designing a bespoke architecture to mapping each task onto an operation that already exists — a bounded mapping that a human can review.&lt;/p&gt;

&lt;p&gt;Two consequences follow. First, &lt;strong&gt;Reemote is a library for configuration management using Python&lt;/strong&gt; — the category the cause analysis identified as missing — and is distributed via PyPI. Second, the authors position &lt;strong&gt;Reemote as an alternative to Ansible&lt;/strong&gt;. The converted roles indicate that package, file, service, and handler logic can survive translation with concurrency, dry-run preview, and structured change reporting supplied by the library rather than improvised by the model, within the scope of the evaluated paths.&lt;/p&gt;

&lt;p&gt;The work acknowledges several boundaries: Reemote is the translation target, not the translator itself. The AI performs the mapping and a human reviews it; there is no Galaxy-equivalent role ecosystem, and the right module must still be chosen for the target operating system. The broader implication, the authors suggest, is that improving AI-generated infrastructure code may depend less on larger prompts than on the existence of a suitable target library.&lt;/p&gt;

&lt;h2&gt;
  
  
  More information
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Documentation:&lt;/strong&gt; &lt;a href="https://reemote.org/" rel="noopener noreferrer"&gt;https://reemote.org/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ansible role migration guide:&lt;/strong&gt; &lt;a href="https://reemote.org/migrating/" rel="noopener noreferrer"&gt;https://reemote.org/migrating/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Converted roles:&lt;/strong&gt; &lt;a href="https://github.com/kimjarvis/reemote/tree/main/examples/roles" rel="noopener noreferrer"&gt;https://github.com/kimjarvis/reemote/tree/main/examples/roles&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Source repository:&lt;/strong&gt; &lt;a href="https://github.com/kimjarvis/reemote" rel="noopener noreferrer"&gt;https://github.com/kimjarvis/reemote&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;PyPI:&lt;/strong&gt; &lt;code&gt;pip install reemote&lt;/code&gt; (license: EPL-2.0)&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>showdev</category>
      <category>opensource</category>
    </item>
  </channel>
</rss>
