package/dnf action plugins: better facts failure msg (#83995) (#84013)

(cherry picked from commit 21fee95af7)
This commit is contained in:
Martin Krizek
2024-09-30 16:38:41 +02:00
committed by GitHub
parent a627b2411a
commit f9a11a3d6d
3 changed files with 14 additions and 9 deletions

View File

@ -0,0 +1,2 @@
bugfixes:
- "``package``/``dnf`` action plugins - provide the reason behind the failure to gather the ``ansible_pkg_mgr`` fact to identify the package backend"

View File

@ -41,6 +41,13 @@ class ActionModule(ActionBase):
facts = self._execute_module(
module_name="ansible.legacy.setup", module_args=dict(filter="ansible_pkg_mgr", gather_subset="!all"),
task_vars=task_vars)
if facts.get("failed", False):
raise AnsibleActionFail(
f"Failed to fetch ansible_pkg_mgr to determine the dnf action backend: {facts.get('msg')}",
result=facts,
)
display.debug("Facts %s" % facts)
module = facts.get("ansible_facts", {}).get("ansible_pkg_mgr", "auto")
if (not self._task.delegate_to or self._task.delegate_facts) and module != 'auto':
@ -75,9 +82,4 @@ class ActionModule(ActionBase):
result.update(self._execute_module(
module_name=module, module_args=new_module_args, task_vars=task_vars, wrap_async=self._task.async_val))
# Cleanup
if not self._task.async_val:
# remove a temporary path we created
self._remove_tmp_path(self._connection._shell.tmpdir)
return result

View File

@ -68,6 +68,11 @@ class ActionModule(ActionBase):
module_args=dict(filter='ansible_pkg_mgr', gather_subset='!all'),
task_vars=task_vars,
)
if facts.get("failed", False):
raise AnsibleActionFail(
f"Failed to fetch ansible_pkg_mgr to determine the package action backend: {facts.get('msg')}",
result=facts,
)
pmgr = 'ansible_pkg_mgr'
try:
@ -103,9 +108,5 @@ class ActionModule(ActionBase):
except AnsibleAction as e:
result.update(e.result)
finally:
if not self._task.async_val:
# remove a temporary path we created
self._remove_tmp_path(self._connection._shell.tmpdir)
return result