Skip to content

Exclude localhost from Ansible facts freshness check#2409

Open
berendt wants to merge 1 commit into
mainfrom
fix/stale-facts-localhost
Open

Exclude localhost from Ansible facts freshness check#2409
berendt wants to merge 1 commit into
mainfrom
fix/stale-facts-localhost

Conversation

@berendt

@berendt berendt commented Jun 19, 2026

Copy link
Copy Markdown
Member

Problem

osism apply <role> warns about stale Ansible facts for localhost:

WARNING  | Ansible facts in Redis are stale for 1 host(s) (older than 43200 seconds). Run 'osism sync facts' to update facts.
WARNING  |   Host 'localhost': facts are 82075 seconds old

The suggested remedy osism sync facts never clears it.

Root cause

check_ansible_facts() scans all ansible_facts* keys in Redis, including ansible_factslocalhost. That cache entry is a byproduct of locally executed or delegated plays — localhost is not a regular inventory host. The refresh path (osism sync facts and the periodic gather_facts task) only targets inventory hosts, so the localhost entry is never refreshed, ages past FACTS_MAX_AGE (12h default), and produces a permanent, unactionable warning.

Fix

Skip localhost, 127.0.0.1, and ::1 in check_ansible_facts(). The freshness check for real inventory hosts is unchanged.

Tests

  • test_check_ansible_facts_local_hosts_never_stale (parametrized over localhost/127.0.0.1/::1): far-overaged local facts produce no warning.
  • test_check_ansible_facts_local_host_skipped_real_host_still_stale: a real inventory host is still reported; localhost is excluded.

Closes #2267

Cached facts for localhost (and 127.0.0.1/::1) are a byproduct of
locally executed or delegated plays, not regular inventory hosts.
They are never refreshed by 'osism sync facts', which only targets
inventory hosts, so they age past FACTS_MAX_AGE and trigger a stale
warning that the suggested remedy can never clear.

Skip these hosts in check_ansible_facts() so the freshness check no
longer emits permanent, unactionable warnings for them.

Closes #2267

Assisted-by: Claude:claude-opus-4-8[1m]
Signed-off-by: Christian Berendt <berendt@osism.tech>

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@berendt berendt requested a review from ideaship June 19, 2026 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Ready

Development

Successfully merging this pull request may close these issues.

stale facts for localhost

2 participants