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

pull/83450/merge
Martin Krizek 2 months ago committed by GitHub
parent facf9186b4
commit 21fee95af7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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"

@ -41,6 +41,13 @@ class ActionModule(ActionBase):
facts = self._execute_module( facts = self._execute_module(
module_name="ansible.legacy.setup", module_args=dict(filter="ansible_pkg_mgr", gather_subset="!all"), module_name="ansible.legacy.setup", module_args=dict(filter="ansible_pkg_mgr", gather_subset="!all"),
task_vars=task_vars) 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) display.debug("Facts %s" % facts)
module = facts.get("ansible_facts", {}).get("ansible_pkg_mgr", "auto") module = facts.get("ansible_facts", {}).get("ansible_pkg_mgr", "auto")
if (not self._task.delegate_to or self._task.delegate_facts) and module != '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( result.update(self._execute_module(
module_name=module, module_args=new_module_args, task_vars=task_vars, wrap_async=self._task.async_val)) 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 return result

@ -68,6 +68,11 @@ class ActionModule(ActionBase):
module_args=dict(filter='ansible_pkg_mgr', gather_subset='!all'), module_args=dict(filter='ansible_pkg_mgr', gather_subset='!all'),
task_vars=task_vars, 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' pmgr = 'ansible_pkg_mgr'
try: try:
@ -103,9 +108,5 @@ class ActionModule(ActionBase):
except AnsibleAction as e: except AnsibleAction as e:
result.update(e.result) 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 return result

Loading…
Cancel
Save