Skip to content

Commit

Permalink
drop fallback to Host API when Reports API fails
Browse files Browse the repository at this point in the history
The results the Host API returns are different from the Reports API, so
when the user asks for Reports API (via `use_reports_api`), they should
get exactly that, as otherwise their Playbooks/Roles might miss-behave
given different data is fed into them.
  • Loading branch information
evgeni committed Dec 5, 2024
1 parent 1235433 commit 2f3bb41
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/drop-host-api-fallback.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- inventory - Drop fallback to Host API when Reports API fails, as this leads to possibly wrong data being used
11 changes: 4 additions & 7 deletions plugins/inventory/foreman.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,13 +474,10 @@ def _get_hostname(self, properties, hostnames, strict=False):
def _populate_report_api(self):
self.groups = dict()
self.hosts = dict()
try:
# We need a deep copy of the data, as we modify it below and this would also modify the cache
host_data = copy.deepcopy(self._post_request())
except Exception as exc:
self.display.warning("Failed to use Reports API, falling back to Hosts API: {0}".format(exc))
self._populate_host_api()
return

# We need a deep copy of the data, as we modify it below and this would also modify the cache
host_data = copy.deepcopy(self._post_request())

self.group_prefix = self.get_option('group_prefix')

hostnames = self.get_option('hostnames')
Expand Down

0 comments on commit 2f3bb41

Please sign in to comment.