Skip to content

Commit

Permalink
Add a warning message if a user tries to checkin incorrect hosts
Browse files Browse the repository at this point in the history
Sometimes a user may pass incorrect host information to a checkin. In
those events, they won't receive feedback about the incorrect input.
This change collects hosts that aren't matched and reports them back to
the user in a warning message.
  • Loading branch information
JacobCallahan committed Jan 21, 2025
1 parent 81af39e commit 572d594
Showing 1 changed file with 18 additions and 2 deletions.
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

0 comments on commit 572d594

Please sign in to comment.