Skip to content
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

Closed
geerlingguy opened this issue Sep 16, 2019 · 6 comments · Fixed by #69296
Closed

Feature or bug? yum module falls back to apt on Debian #62362

geerlingguy opened this issue Sep 16, 2019 · 6 comments · Fixed by #69296
Labels
affects_2.8 This issue/PR affects Ansible v2.8 bug This issue/PR relates to a bug. easyfix This issue is considered easy to fix by aspiring contributors. hacktoberfest has_pr This issue has an associated PR. module This issue/PR relates to a module. P3 Priority 3 - Approved, No Time Limitation packaging Packaging category support:core This issue/PR relates to code supported by the Ansible Engineering Team. verified This issue has been verified/reproduced by maintainer

Comments

@geerlingguy
Copy link
Contributor

geerlingguy commented Sep 16, 2019

SUMMARY

I was working on an example of what not to do—namely, using the yum module instead of package for something meant to be platform agnostic... but then I realized my example (using the yum module on Debian) actually worked.

When I ran the yum task with -vvvv I found:

Running apt as the backend for the yum action plugin
Using module file /usr/local/lib/python2.7/dist-packages/ansible/modules/packaging/os/apt.py

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
  • Bug Report
COMPONENT NAME

yum

ANSIBLE VERSION
ansible 2.8.5
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/Users/jgeerling/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python2.7/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 2.7.16 (default, Apr 12 2019, 15:32:40) [GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.46.3)]
CONFIGURATION
N/A
OS / ENVIRONMENT

Debian 10

STEPS TO REPRODUCE
  1. Run a Docker image with Debian 10.

    docker run -it geerlingguy/docker-debian10-ansible /bin/bash
    
  2. Check if stress installed. Nothing listed.

    apt list --installed | grep stress
    
  3. Create a playbook for demonstration.

    cat << EOF > main.yml
    ---
    - hosts: localhost
      gather_facts: false
      connection: local
    
      tasks:
        - apt: update_cache=true
        - yum: name=stress state=present
    EOF
    
  4. Run the playbook.

    ansible-playbook main.yml
    
  5. Check if stress installed.

    apt list --installed | grep stress
    stress/stable,now 1.0.4-4 amd64 [installed]
    

When run with -vvvv, the yum task gives: https://pastebin.com/Q4SSduVH

EXPECTED RESULTS

I expected a task failure, saying something like "yum or dnf 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.

@ansibot
Copy link
Contributor

ansibot commented Sep 16, 2019

Files identified in the description:

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibot
Copy link
Contributor

ansibot commented Sep 16, 2019

@ansibot ansibot added affects_2.8 This issue/PR affects Ansible v2.8 bug This issue/PR relates to a bug. module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. packaging Packaging category support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Sep 16, 2019
@geerlingguy
Copy link
Contributor Author

ansible -m setup output inside the test environment (run where ansible-playbook was run): https://gist.github.com/geerlingguy/be571359470883b83f66b49eb2dbcc0b

@sivel
Copy link
Member

sivel commented Sep 16, 2019

We probably need some change like the following to ensure only yum like backends will work:

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

@ansibot ansibot removed the needs_triage Needs a first human triage before being processed. label Sep 16, 2019
@sivel sivel added easyfix This issue is considered easy to fix by aspiring contributors. P3 Priority 3 - Approved, No Time Limitation verified This issue has been verified/reproduced by maintainer labels Sep 16, 2019
@luigizhou
Copy link

Hi, I would like to work on this. Has this been fixed already?
Also, this would be my first contribution and I might need some guidance

@ansibot ansibot added the has_pr This issue has an associated PR. label Sep 30, 2019
@maxamillion
Copy link
Contributor

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.8 This issue/PR affects Ansible v2.8 bug This issue/PR relates to a bug. easyfix This issue is considered easy to fix by aspiring contributors. hacktoberfest has_pr This issue has an associated PR. module This issue/PR relates to a module. P3 Priority 3 - Approved, No Time Limitation packaging Packaging category support:core This issue/PR relates to code supported by the Ansible Engineering Team. verified This issue has been verified/reproduced by maintainer
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants