Recording Ansible runs
Every ansible-playbook run can write itself into Lemano’s history, with
no extra command: a callback plugin has Lemano read each host before the
play’s first task and again after the playbook. The generation read after
the run names the run, and each change in it is attributed to the task
that made it. You keep running Ansible as before; lemano history,
lemano diff and lemano summary then show what each run really changed
on each server, and what changed since.
Before you start
lemanoandlemano-ansibleon the controller (the machine that runsansible-playbook), installed side by side.- The Ansible collection
lemano.lemano, installed as the Install page shows.
Nothing else: no store to create, no target files to write and no first
lemano discover. If Ansible can reach a host over SSH, Lemano reaches it
the same way. The first recorded run creates the store, as lemano init
does, and says where its key is: back the key up, since without it the
history cannot be read. A store sealed by a passphrase needs
LEMANO_PASSPHRASE set for the runs; it is never replaced by another.
The loop, once enabled:
- every playbook run records itself;
- between runs, a timer runs
lemano ansible discover, which reads the hosts of the same inventory (see Scheduling); - to undo a change,
lemano ansible revert, andlemano ansible end-trialto end a trial left unfinished.
Enable it
Two lines in ansible.cfg:
[defaults]
callbacks_enabled = lemano.lemano.recordThe plugin is not a stdout callback, so your output does not change and
it runs beside any stdout callback you use. Without the collection, copy
integrations/ansible/collection/plugins/callback/record.py alone into a
callback_plugins/ folder next to your playbooks and enable it as
callbacks_enabled = record.
Its options, under [callback_lemano] in ansible.cfg or in the
environment:
| Option | Environment | Default | Meaning |
|---|---|---|---|
lemano | LEMANO_ANSIBLE_LEMANO | lemano on PATH | The lemano command. |
create_targets | LEMANO_ANSIBLE_CREATE_TARGETS | true | Give a host with no Lemano target one, made from the inventory. |
targets | LEMANO_ANSIBLE_TARGETS | the run’s inventory | A folder of target files to use instead of the inventory. |
baseline | LEMANO_ANSIBLE_BASELINE | true | Move the baseline after a successful run. |
timeout | LEMANO_ANSIBLE_TIMEOUT | 900 | Seconds one call of lemano may take; a host another lemano command is busy with is waited for up to half of it. |
Lemano itself is configured as usual, through its environment
(LEMANO_STORE, LEMANO_SSH_CONFIG, LEMANO_PASSPHRASE).
How Lemano reaches the hosts
Lemano reads the run’s own inventory again, with ansible-inventory, and
takes each host’s connection settings from it exactly as
lemano ansible import does:
address, port, user, key file, jump hosts and proxy command. A password
the inventory sets (vaulted or not) is asked of Ansible when Lemano
connects, and never stored. A host with no target gets one, named as the
import names it; a host that has one keeps its name, labels and
discovery settings.
Host keys. A host Lemano has never seen is checked against your own
known_hosts files, those your ssh uses: if they have the host, it must
present one of their keys. Otherwise its first key is pinned, and the
warning and the end line of the run show its fingerprint, so that you can
check it against the host. From then
on, a different key is always refused, even when Ansible itself runs with
host_key_checking = False; lemano target rekey NAME pins a new one
once you have checked it. See Security model.
What a run records
For each play, before its first task, Lemano reads the play’s hosts that
this playbook has not read yet (with --limit applied). A change that
pass finds is drift from before the run: a hand edit, an unattended
upgrade. It is attributed as any change Lemano finds, never to the run.
After the playbook, Lemano reads every host again. That generation has
trigger run; it records the run’s ID, the playbook, the plays, the local
user and, when the playbook is in a git repository, its commit and
whether the tree was clean. Every change it holds is attributed to the
run, and a change to a file, package, service, sysctl setting, user or
group that a changed task names carries the task’s name.
At the end of the run the plugin says, in one or two lines, what was recorded and what was not (here the first run ever, with no store yet):
lemano: created your Lemano store (/home/alice/.local/share/lemano/lemano.db) and its key (/home/alice/.config/lemano/key). Back up the key: without it this history cannot be read.
lemano: recorded rec (generation 1: 5 changes, 1 not matched to a task; new target; baseline moved), web-02 (nothing changed; new target; baseline moved)For each recorded host the line gives counts, never a path or a value:
5 changes: the objects the run’s generation added, removed or changed.1 not matched to a task: how many of those no changed task names. It is not an accusation. Only files, packages, services, sysctl settings, users and groups can be matched to a task, and a task’s side effects are not named by it: here, a command task set a sysctl value that no task names. Readlemano difffor which ones. When Lemano could not take a pass just before the run, the changes cannot be told from older ones and the line saysnot attributed to the runinstead.3 changes found before the run: what the pass before the run found. These are drift, attributed as any other change and never to the run; the line says nothing when there are none.
A host that cannot be recorded gets a line of its own, with the reason: here a host that Ansible reaches without SSH, and one whose host key changed:
lemano: not recorded: controller (not an SSH host), wrongkey (host key changed)A run after someone changed a file, added another and set the sysctl value by hand, whose playbook put the file right and set the value again:
lemano: recorded rec (generation 5: 2 changes, 1 not matched to a task; 3 changes found before the run; baseline moved)A run that changed nothing and found nothing keeps the short form,
web2 (nothing changed). With more than four hosts the line is one
summary (7 hosts: 14 changes, 3 not matched to a task (not matched: web1, web2, web3)), so that it stays one line.
A host the run did not finish well says so, and that its baseline stayed:
web1 (generation 3: 1 change; run failed, baseline not moved), or
host unreachable during the run when Ansible could not reach it. The
same outcome is in lemano history (the run is named “ansible run
site.yml by root (failed on the host)”), in its JSON (run.outcome), and
lemano summary lists a target whose run failed under “needs attention”.
A failed run that changed nothing writes no generation, but the pass after
it keeps the outcome: history lists it as a line without a number, named
with its outcome, and in JSON as an entry of runs with outcome. The
summary lists the target under “needs attention” in that case too.
Each host that is not recorded is also a warning, with the details and what to do about it:
[WARNING]: lemano: wrongkey not recorded: host key changed: host key for 192.168.128.13:22 has changed: pinned ssh-ed25519 SHA256:qaeR... in /home/alice/.config/lemano/known_hosts, presented ssh-ed25519 SHA256:g4SH...; refusing to connect; if the new key is right, run lemano target rekey wrongkeyHistory then reads, after the first run, a hand change and a second run that changed nothing:
$ lemano history rec
SEQ CREATED TRIGGER STATUS SUMMARY
0 2026-10-28T23:07:27Z discover complete first discovery
1 2026-10-28T23:07:53Z run complete ansible run site.yml by root: 2 added, 3 changed; all 5 by the run, 4 matched to the task that made them
2 2026-10-28T23:08:20Z discover complete no fact changed; objects: 1 added, 0 removed, 0 changed; who changed it: 1 unknown
- 2026-10-28T23:08:31Z run unchanged ansible run site.yml by root: nothing changedGeneration 0 is the first discovery, the pass before the first run.
Generation 1 is what site.yml changed. Generation 2 is the pass before
the second run: someone had added a file by hand. The last line is the
second run, which changed nothing: no generation was written, so it has
no number, but it was recorded. In -o json it is an entry of runs
with its passId, result: "unchanged" and no generation; a run that
was not recorded has no entry.
$ lemano diff rec 0 1
rec: generation 0 -> 1
Facts: no change
Objects:
+ File//etc/app/first.conf
+ File//etc/app/second.conf
~ File//etc/app/app.conf
~ content changed
--- /etc/app/app.conf (generation 0)
+++ /etc/app/app.conf (generation 1)
@@ -1 +1 @@
-one
+two
~ File//etc/sysctl.d/90-redirects.conf
~ content changed
...
~ Sysctl/net.ipv4.conf.lo.accept_redirects
~ status.live: "0" -> "1"
~ status.persisted: "0" -> "1"
~ status.sources.0.value: "0" -> "1"
Attribution:
File /etc/app/first.conf: added by ansible run site.yml
task "Write one file per host"
File /etc/app/second.conf: added by ansible run site.yml
task "Write one file per host"
File /etc/app/app.conf: changed by ansible run site.yml
task "Deploy app config"
File /etc/sysctl.d/90-redirects.conf: changed by ansible run site.yml
task "Set accept_redirects at boot"
Sysctl net.ipv4.conf.lo.accept_redirects: changed by ansible run site.ymlThe live sysctl value was set by a command task, which names nothing
Lemano can match: it is attributed to the run without a task. The daily
summary groups the changes by their cause, and names a run that changed
nothing (“ansible run site.yml by root: nothing changed”).
Drift since the last run
After a run in which no task failed on a host, the host’s baseline moves
to what the pass after the run read (set baseline = false to keep it
where it is). Every later change, a hand edit or an upgrade, then shows as
drift since that run:
lemano diff rec --baselineA failed or unreachable host is recorded when Lemano can read it, but its baseline stays.
Lemano never fails a playbook
Recording must never stand in the way of a deployment, and Ansible does not let a callback change the outcome of a play: an error in a callback becomes a warning. So every failure of Lemano is a warning, and the line at the end of the run names each host that was not recorded and why:
- a host that is not reached over SSH (
ansible_connectionlocal, docker, winrm, network_cli and the like); - a host whose key differs from the one pinned, or from your
known_hosts; - a host Lemano cannot reach or log in to (a password the inventory does not give, for example);
- a host added during the run (
add_host) that has no target; - a host another lemano command was busy with for too long;
- every host, when
lemanocannot be run or its store cannot be opened (a store sealed by a passphrase: setLEMANO_PASSPHRASE).
The end line gives each cause in a few words; the warning above it gives the details (fingerprints, files) and what to do.
Runs in check mode (--check) are not recorded: they change nothing.
Instead, the plugin compares each host with the playbook and prints the
comparison after the recap: see
Checking servers against your roles.
Between runs
A target made by a run lives in the store only, so lemano discover with
target files does not read it. lemano ansible discover does, with the
same inventory, and is what the hourly timer runs:
lemano ansible discover -i inventories/prod/hosts.ymlUndoing a run
The generation before the run is what the host looked like before it:
revert the run’s changes to it, for the kinds lemano revert covers (see
revert), with lemano ansible revert, which
reaches the host through the same inventory and is otherwise exactly
lemano revert:
lemano ansible revert -i inventories/prod/hosts.yml rec --to 0 /etc/app/app.confCost
Two passes per host per playbook, hosts read in parallel (a pass takes
about two seconds on a small server), and one ansible-inventory run
before each.
The passes around a run never run the package manager’s full check of
every package file (dpkg --verify, rpm -Va), which takes from seconds
to minutes: they check only the package files whose size, times, inode,
mode or owner changed since the previous pass (see the File kind’s
package files). The full
check runs on the passes of lemano discover or lemano ansible discover when it is due, once a day by default.
A host that never had a full check gets its first one in the background
when the playbook ends: the plugin starts lemano ansible discover --full-package-check on those hosts, in a session of its own with its
output dropped, and the playbook returns at once. The end line says so:
lemano: first full package check of web1, web2 running in the background (about a minute); see lemano summaryIts result is in lemano history and lemano summary when it ends. A
playbook started on the same host meanwhile waits for it (the timeout
option bounds the wait). A CI job that ends at once may stop it; the next
lemano discover then runs it. If you only record runs and never run
lemano discover, later full checks do not run: schedule lemano discover (see Scheduling) to have them.
AWX and Ansible Automation Platform
Not tested. A job runs in an execution environment, a container: the
lemano and lemano-ansible binaries and a store would have to be in a
custom execution environment, and that store is lost with the job’s
container. Recording AWX jobs into one lasting history needs a store that
outlives the job.
Reference
The exchange between the plugin and lemano-ansible is described in
lemano ansible record.