New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature or bug? yum module falls back to apt on Debian #62362
Comments
Files identified in the description: If these files are inaccurate, please update the |
ansible -m setup output inside the test environment (run where |
We probably need some change like the following to ensure only diff --git a/lib/ansible/plugins/action/yum.py b/lib/ansible/plugins/action/yum.py
index 468321a429..f1efd10bbd 100644
--- a/lib/ansible/plugins/action/yum.py
+++ b/lib/ansible/plugins/action/yum.py
@@ -22,6 +22,8 @@ from ansible.utils.display import Display
display = Display()
+VALID_PKG_MGRS = frozenset(("yum", "yum4", "dnf"))
+
class ActionModule(ActionBase):
@@ -56,7 +58,7 @@ class ActionModule(ActionBase):
except Exception:
pass # could not get it from template!
- if module not in ["yum", "yum4", "dnf"]:
+ if module not in VALID_PKG_MGRS:
facts = self._execute_module(module_name="setup", module_args=dict(filter="ansible_pkg_mgr", gather_subset="!all"), task_vars=task_vars)
display.debug("Facts %s" % facts)
module = facts.get("ansible_facts", {}).get("ansible_pkg_mgr", "auto")
@@ -68,7 +70,7 @@ class ActionModule(ActionBase):
if module == "yum4":
module = "dnf"
- if module not in self._shared_loader_obj.module_loader:
+ if module not in self._shared_loader_obj.module_loader or module not in VALID_PKG_MGRS:
result.update({'failed': True, 'msg': "Could not find a yum module backend for %s." % module})
else:
# run either the yum (yum3) or dnf (yum4) backend module |
Hi, I would like to work on this. Has this been fixed already? |
@luigizhou it has not, I would gladly review a patch for it though. I think @sivel's suggestion is a solid starting point. Thank you! |
SUMMARY
I was working on an example of what not to do—namely, using the
yum
module instead ofpackage
for something meant to be platform agnostic... but then I realized my example (using theyum
module on Debian) actually worked.When I ran the
yum
task with-vvvv
I found:Is this a bug? A feature? I found it can also lead to unexpected weird behavior that I believe is due to strange fallback behavior.
ISSUE TYPE
COMPONENT NAME
yum
ANSIBLE VERSION
CONFIGURATION
OS / ENVIRONMENT
Debian 10
STEPS TO REPRODUCE
Run a Docker image with Debian 10.
Check if stress installed. Nothing listed.
Create a playbook for demonstration.
Run the playbook.
Check if stress installed.
When run with
-vvvv
, theyum
task gives: https://pastebin.com/Q4SSduVHEXPECTED RESULTS
I expected a task failure, saying something like "
yum
ordnf
are not available on this system."ACTUAL RESULTS
The task worked. It said 'changed' or 'ok' and worked idempotently.
I was bewildered. Surprise was apparent. I even said something in IRC about it.
The text was updated successfully, but these errors were encountered: