Session reuse
Sessions stay open between runs describes what you observe. This page describes how a worker decides to keep or replace a host's sessions.
What a worker keeps for each host
For each host it has run, a worker keeps:
- the Nornir
Hostobject, with its open sessions; - a lock, so one call runs for the host at a time;
- the fingerprint of the inventory data the
Hostobject was built from.
The fingerprint
Each call carries a copy of the host, without sessions, and a fingerprint of that copy. The
fingerprint is a blake2b hash of the serialized copy. Two copies with the same inventory data
have the same fingerprint.
- Same fingerprint. Nothing changed on the driver. The worker runs the task with the kept host and its open sessions.
- Different fingerprint. The host changed on the driver: for example a new address or new credentials. Sessions opened with the old data may be wrong, so the worker closes them and keeps the new copy.
- The call replaces the kept fingerprint. The difference comes from a change that the
previous task itself made to
host.dataon this worker. The worker already holds that change, so it keeps the host and its sessions.
When a worker forgets a host
A worker forgets a host, so the host's next call opens new sessions, when:
- a sync call for the host is abandoned;
- the host's worker is replaced or stops;
- the runner closes, or the driver process exits.
Broken sessions
The task runs on the worker with the kept Host object. When a connection plugin marks a
session as broken, Nornir handles it there, as it does in a script without the ray runner.