summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--changelogs/fragments/package-dnf-action-plugins-facts-fail-msg.yml2
-rw-r--r--lib/ansible/plugins/action/dnf.py12
-rw-r--r--lib/ansible/plugins/action/package.py9
3 files changed, 14 insertions, 9 deletions
diff --git a/changelogs/fragments/package-dnf-action-plugins-facts-fail-msg.yml b/changelogs/fragments/package-dnf-action-plugins-facts-fail-msg.yml
new file mode 100644
index 0000000000..8dd037a4e0
--- /dev/null
+++ b/changelogs/fragments/package-dnf-action-plugins-facts-fail-msg.yml
@@ -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"
diff --git a/lib/ansible/plugins/action/dnf.py b/lib/ansible/plugins/action/dnf.py
index 52391a4c82..137fb13086 100644
--- a/lib/ansible/plugins/action/dnf.py
+++ b/lib/ansible/plugins/action/dnf.py
@@ -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
diff --git a/lib/ansible/plugins/action/package.py b/lib/ansible/plugins/action/package.py
index 6963b770c4..a20819a637 100644
--- a/lib/ansible/plugins/action/package.py
+++ b/lib/ansible/plugins/action/package.py
@@ -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