Repository: ansible/ansible

Issue:
1.8.1 not pulling library/ modules if core exists
Issue Type: "Bug Report"

Ansible Version: 1.8.1

Environment: OS X

Summary: I've got a modified version of rhn_channel in a library/ folder, after upgrading from 1.7.2 to 1.8.1 the un-modified version gets pulled instead of the modified version 

Steps To Reproduce: export ANSIBLE_KEEP_REMOTE_FILES=1, change rhn_channel module, copy into library/ folder and run a test playbook against rhn_channel. ssh into the target host, and take a look at the rhn_channel file in ~/.ansible/tmp.

Expected Results: Modified version gets used. 

Actual Results: shipped version gets used.



Discussion:
We can definitely investigate a precedence issue with the "./library" folder.   Can you verify that this "./library" directory is in the same directory of your playbook with a "ls" ?

Also, if not, I'm curious what ANSIBLE_LIBRARY might be set to.

Michael, at first ANSIBLE_LIBRARY was not set, I set it in an attempt to solve this issue, and it didn't seem to clear it up:
`% env | grep ANSIBLE_LIBRARY`
`ANSIBLE_LIBRARY=/Users/djb44/ansible-playbooks/provision-configs/library`

here, test.yml is the playbook i'm futzing with. please let me know if you need any more info

`[djb44@docbrown:~/ansible-playbooks/provision-configs on master]`
`% ls test.yml`
`test.yml`
`[djb44@docbrown:~/ansible-playbooks/provision-configs on master]`
`% ls library | grep rhn_channel`
`rhn_channel`
`[djb44@docbrown:~/ansible-playbooks/provision-configs on master]`
`% cat test.yml`
`- name: rhn_channel`
  `hosts: ansible-robot`
  `remote_user: root`

  `tasks:`
    `- name: register test`
        `rhn_channel: name=epel6_x86_64 sysname=ansible-robot url="{{rhn_url}}" user="{{rhn_user}}" password="{{rhn_pass}}" state=present`
      `when: ansible_os_family == 'RedHat'`

when i run ansible-playbook test.yml with 1.7.2 the modified version runs, with 1.8.1 it does not. 
Thanks!
Dann

Hi @whereismyjetpack, I think I see the issue: In 1.8 we moved modules to using `.py`. Doing so with your copy of the rhn_register module should resolve the issue for you.

If you have any further questions, please let us know by stopping by one of the two mailing lists, as appropriate:
- https://groups.google.com/forum/#!forum/ansible-project - for user questions, tips, and tricks
- https://groups.google.com/forum/#!forum/ansible-devel - for strategy, future planning, and questions about writing code

Because this project is very active, we're unlikely to see comments made on closed tickets, but the mailing list is a great way to ask questions, or post if you don't think this particular issue is resolved.

Thank you!

Hi,

This should definitely be a thing - we just need to consider everything in the configured and searchable paths before iterating on the extensions, so I'm reopening this ticket.

In the meantime, the above workaround definitely will solve it.

Thanks!


Resolving patch:
diff --git a/lib/ansible/utils/plugins.py b/lib/ansible/utils/plugins.py
--- a/lib/ansible/utils/plugins.py
+++ b/lib/ansible/utils/plugins.py
@@ -167,17 +167,20 @@ def find_plugin(self, name, suffixes=None, transport=''):
                 else:
                     suffixes = ['.py', '']
 
-        for suffix in suffixes:
-            full_name = '%s%s' % (name, suffix)
-            if full_name in self._plugin_path_cache:
-                return self._plugin_path_cache[full_name]
+        # loop over paths and then loop over suffixes to find plugin
+        for i in self._get_paths():
+            for suffix in suffixes:
+                full_name = '%s%s' % (name, suffix)
+
+                if full_name in self._plugin_path_cache:
+                    return self._plugin_path_cache[full_name]
 
-            for i in self._get_paths():
                 path = os.path.join(i, full_name)
                 if os.path.isfile(path):
                     self._plugin_path_cache[full_name] = path
                     return path
 
+        # if nothing is found, try finding alias/deprecated
         if not name.startswith('_'):
             return self.find_plugin('_' + name, suffixes, transport)
 


Test patch: