module

Krikri::FactCache

Ansible's fact_caching support (ANSIBLE_CACHE_PLUGIN/ ANSIBLE_CACHE_PLUGIN_CONNECTION env vars - no ansible.cfg INI parsing exists in this engine, matching the established pattern elsewhere, e.g. ssh_manager.cr's own host_key_checking handling). Only the jsonfile backend is implemented - by far the most common real-world choice (the built-in default backend, memory, caches only within a single process and needs no support here at all, since @facts already IS that in-run cache; redis/memcached would need real client libraries this project doesn't carry).

Ansible only ever CONSULTS the cache under gathering: smart (or explicit + a play that skips gather_facts:) - gathering: implicit (the default) always re-gathers regardless of a configured cache, verified live against ansible-core 2.19.12: a warm fact-cache with default implicit gathering still re-ran setup.py every play. So this module is only ever consulted from the executor's existing @smart_gathering path (see gather_facts_for_all_hosts), never for implicit/explicit gathering - that mirrors Ansible's own gating rather than reintroducing a second, independent on/off switch.

Constants

DEFAULT_TIMEOUT = 86400

Matches Ansible's fact_caching_timeout default (24h, in seconds). 0 means never expire, same as Ansible.

URI_REQUIRED_PLUGINS = {"jsonfile", "community.general.pickle"}

Cache plugins whose required _uri config (the fact_caching_connection) makes ansible-core warn at startup when it is missing - live-verified vs 2.19.11 for both: [WARNING]: Required config '_uri' for 'jsonfile' cache plugin not provided. The warning fires whenever the plugin is CONFIGURED without a connection, even when no play gathers facts (the plugin load is not gated on gathering), and a collection plugin renders fully qualified (ansible_collections.<ns>.<collection>.plugins.cache.<name>). Only these two are listed because they are the only plugins whose _uri requirement this engine has verified; other backends would need their own option specs to warn about correctly.

Class methods

enabled?
Source
read(host_name : String) : Hash(String, JSON::Any) | Nil

Returns the cached facts for host_name if the cache is enabled, a file exists, and it isn't older than the configured timeout - nil otherwise (cache miss, expired, disabled, or unreadable).

Source
reset_connection_warning

Test hook: forget that the warning was already emitted.

Source
warn_missing_connection(io : IO = STDERR) : Nil

Startup-time configuration warning, shared by both drivers (the ansible ad-hoc binary warns the same way). Idempotent per process. io injectable for specs.

Source
write(host_name : String, facts : Hash(String, JSON::Any)) : Nil

Persists facts for host_name. Best-effort: a cache write failure (unwritable connection dir, disk full, ...) must never fail the play - Ansible's own fact-cache writes are equally non-fatal.

Source