Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a warning message if a user tries to checkin incorrect hosts #345

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions broker/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,26 @@ def checkin(hosts, background, all_, sequential, filter):
helpers.fork_broker()
inventory = helpers.load_inventory(filter=filter)
to_remove = []
unmatched = set(hosts) # Track unmatched hosts

for num, host in enumerate(inventory):
if str(num) in hosts or host.get("hostname") in hosts or host.get("name") in hosts or all_:
# Check if this host matches any of our criteria
if (
all_
or str(num) in unmatched
or host.get("hostname") in unmatched
or host.get("name") in unmatched
):
to_remove.append(Broker().reconstruct_host(host))
Broker(hosts=to_remove).checkin(sequential=sequential)
# Remove all possible match values for this host from unmatched
unmatched.discard(str(num))
unmatched.discard(host.get("hostname"))
unmatched.discard(host.get("name"))

if unmatched:
logger.warning(f"The following hosts were not found in inventory: {', '.join(unmatched)}")
if to_remove:
Broker(hosts=to_remove).checkin(sequential=sequential)


@loggedcli()
Expand Down
Loading