From 90bd31142c3f5960cb99fc7faf24b50545303b6b Mon Sep 17 00:00:00 2001 From: Evgeni Golov Date: Thu, 5 Dec 2024 11:34:38 +0100 Subject: [PATCH] drop fallback to Host API when Reports API fails 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. --- changelogs/fragments/drop-host-api-fallback.yml | 2 ++ plugins/inventory/foreman.py | 11 ++++------- 2 files changed, 6 insertions(+), 7 deletions(-) create mode 100644 changelogs/fragments/drop-host-api-fallback.yml diff --git a/changelogs/fragments/drop-host-api-fallback.yml b/changelogs/fragments/drop-host-api-fallback.yml new file mode 100644 index 0000000000..1624517cc3 --- /dev/null +++ b/changelogs/fragments/drop-host-api-fallback.yml @@ -0,0 +1,2 @@ +bugfixes: + - inventory - Drop fallback to Host API when Reports API fails, as this leads to possibly wrong data being used diff --git a/plugins/inventory/foreman.py b/plugins/inventory/foreman.py index 076bf21718..459196141f 100644 --- a/plugins/inventory/foreman.py +++ b/plugins/inventory/foreman.py @@ -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')