lemano ansible record (plugin protocol)
lemano ansible record begin (a JSON request on standard input)
lemano ansible record end (a JSON request on standard input)The two commands the lemano.lemano.record callback plugin runs around a
playbook. They are plumbing: not shown in the help, and not meant to be
run by hand. The guide
explains how to record runs; this page describes what the plugin and
lemano-ansible exchange, for those who write another plugin or debug
this one.
Each command reads one JSON request on standard input (at most 16 MiB), takes one discovery pass on the target of each host, and prints one JSON answer on standard output. Messages go to standard error. The exit code is 0 when the request could be run, even when a host could not be recorded (its entry says why); 2 for a malformed request; 1 when the store cannot be opened or the inventory cannot be read, with the cause and what to do on standard error. Nothing secret is in a request or an answer: no argument of a task is sent except those that name what it manages.
Where a host’s settings come from
By default, from the run’s own inventory: lemano-ansible runs
ansible-inventory --list with the run’s sources (inventories, read
against cwd), once per command, and maps each host exactly as
lemano ansible import does: address, port, user,
key file, connect limit, jump hosts, proxy command, and ansible://
references for the passwords the inventory sets, which Ansible answers at connection time.
Nothing of this is written to the store or to a file of yours: the
settings live in a temporary target file for the length of the command.
A host’s discovery settings (every spec.discovery setting, such as
the included and excluded paths, the gaps it accepts, the content limits
and the intervals) and its name come from its Lemano target when it has
one; the users’ own files the inventory names replace the target’s. A
host’s target is the one whose label ansible.lemano.host holds the host’s
inventory name, else the target named as the host.
A host with no target gets one, named as the import names it, unless
createTargets is false. A host the inventory does not have (added
during the run with add_host) is read from its stored target if it has
one; a stored target keeps no password reference or proxy command, so
such a host needs neither, or the targets folder.
With targets, the targets come from that folder of target files
instead, and the inventory is not read.
Host keys
A host whose key Lemano has never pinned is checked against your own
known_hosts files (those ssh -G names as UserKnownHostsFile and
GlobalKnownHostsFile): when they have the host, under its address or
the HostName your ssh configuration gives it, those keys are copied
into Lemano’s file and the host must present one of them. Otherwise the
first key it presents is pinned: a playbook run cannot stop to ask. The
pinned fingerprint is shown, so that it can be checked: a warning when
the pass takes it (lemano: web1: pinned its host key SHA256:... on first sight), the line lemano: pinned host keys on first sight: web1 SHA256:... at the end of the run, and the pinnedKey field of the host
in the JSON the plugin reads. This is the one place Lemano pins a key
nobody has checked; lemano ansible discover, check, codify and
export refuse such a host unless given --accept-new-host-key. A key
that differs from the pinned one is always refused; lemano target rekey NAME pins a new one.
A busy target
When another lemano command holds a target’s lock, the pass waits for it,
trying every two seconds for up to lockWait seconds (default 300), then
reports the host as busy.
begin
{
"run": {
"id": "6f1c2d4e-...",
"title": "site.yml",
"meta": {"playbook": "site.yml", "plays": "Web servers", "user": "alice",
"commit": "a1b2c3d...", "clean": "true"}
},
"inventories": ["/home/alice/infra/inventories/prod/hosts.yml"],
"cwd": "/home/alice/infra",
"targets": "",
"createTargets": true,
"lockWait": 450,
"hosts": ["web1", "web2", "db1"]
}Takes the pass before the run on the hosts’ targets. It is an ordinary discovery pass: a change it finds since the previous generation is drift from before the run, attributed as any other change, never to the run. For a target made now, it is the target’s first discovery.
end
{
"run": {"id": "6f1c2d4e-...", "title": "site.yml", "meta": {"...": "..."}},
"inventories": ["/home/alice/infra/inventories/prod/hosts.yml"],
"cwd": "/home/alice/infra",
"hosts": [
{
"host": "web1",
"failed": false,
"unreachable": false,
"tasks": [
{"name": "Deploy nginx config", "action": "ansible.builtin.template",
"args": {"dest": "/etc/nginx/nginx.conf"}, "changed": true},
{"name": "Install nginx", "action": "ansible.builtin.apt",
"args": {"name": "nginx"}},
{"name": "Reload", "action": "ansible.builtin.command", "skipped": true}
]
}
],
"baseline": true
}Takes the pass after the run on each host’s target. The run is recorded
with unit: "task", the noun history uses. When the pass finds changes,
its generation has trigger run and records the run: the tool
(ansible), its ID, title, unit and meta. When it finds none, it writes
no generation, but the pass is kept with the run, and history and the
summary show it (“nothing changed”). When the latest pass of the target
before it is the run’s own pass before, every change it finds is
attributed to the run, and a change to an object a changed task names
carries the task’s name:
| Task argument | Names |
|---|---|
path, dest, file, sysctl_file (an absolute path) | the object with that path, and every object under it |
name of apt, dnf, dnf5, yum, package | Package/NAME (a list of names: each) |
name of service, systemd, systemd_service | Service/NAME and Service/NAME.service |
name of sysctl | Sysctl/NAME |
name of user, group | User/NAME, Group/NAME |
Modules are matched by their short name in ansible.builtin,
ansible.legacy, ansible.posix and community.general; the path
arguments of any module count. When the pass before the run failed or was
not taken, the changes are attributed as any others: the period then
holds more than the run. When that pass read the host but not every kind
whole, only the changes in the kinds it did not read whole are attributed
as any others; the end line names those kinds, and a gap in a kind the
run did not change does not matter.
With baseline, the baseline of each host moves to what the pass after
the run read when the host ran at least one task that was not skipped,
no task failed on it, Ansible reached it, and the pass read it whole.
The answer
{
"hosts": [
{"host": "web1", "target": "web1", "recorded": true, "result": "changed",
"generation": 12, "added": 2, "changed": 3, "changes": 5, "unmatched": 1, "baseline": true},
{"host": "web2", "target": "web2", "recorded": true, "result": "unchanged",
"nothingChanged": true, "baseline": true},
{"host": "app3", "target": "app3", "recorded": false, "result": "unreachable",
"reason": "host key changed: ...", "fix": "if the new key is right, run lemano target rekey app3"},
{"host": "db1", "recorded": false, "reason": "not an SSH host: ansible_connection is local, not SSH"}
]
}| Field | Meaning |
|---|---|
recorded | The pass read the host, whole or in part (result says which). |
result | The pass’s result, as lemano discover gives it. |
created | The target was made by this command. |
generation, added, removed, changed | The generation the pass wrote and how many objects it added, removed and changed. |
changes | added, removed and changed together. |
unmatched | After a run: how many of the changes are attributed to the run but not named by any changed task. Only files, packages, services, sysctl settings, users and groups can be named by a task, and a task’s side effects are not named by it, so this is a count to look at, not a fault. |
notAttributed | Set instead of unmatched when the changes could not be attributed to the run, because no complete pass was taken just before it. |
notAttributedKinds | The kinds whose changes were left out of the run’s, because the pass taken just before the run did not read them whole. A gap in a kind the run did not change does not matter. |
nothingChanged | The pass found nothing changed and wrote no generation. |
baseline | The baseline moved to what the pass read. |
outcome | After a run: how Ansible ended on the host, ok, failed (a task failed, or a fatal error stopped the host) or unreachable. It is stored in the generation the pass wrote when it wrote one (run.outcome in history -o json; absent on generations recorded before it existed), and on the pass, so that a run which wrote no generation shows it as well (outcome of an entry of runs). A host that did not end ok keeps its baseline where it was. |
reason, fix | Why the host was not recorded, or what went wrong, in full (fingerprints, files), and what to do about it when there is something to do. |
cause | The reason in a few words, for a one-line report: host key changed, unreachable, login failed, not an SSH host, no target, busy. |
notes | What could not be used on a host that was recorded all the same, such as a known_hosts file that cannot be parsed. |
The answer also has storeCreated (store, key) when there was no
store and the command created one, as lemano init does. A store that
exists and cannot be opened (sealed by a passphrase that is not set) is an
error naming its fix, and no other store is made beside it.
The reasons a host is not recorded: not an SSH host (ansible_connection
local, docker, winrm, network_cli and the like); a value of the inventory
a target cannot hold; not in the inventory and no target; no target with
createTargets false; a refused host key; unreachable or a failed login
(a password the inventory does not give, for example); busy past
lockWait. A host whose escalation is not sudo is read as its login
user, as the import declares it (privilege: user), and recorded with
the gaps that brings.