Repository: ansible/ansible

Issue:
Cannot load custom lookup plugin
<!---
Verify first that your issue/request is not already reported on GitHub.
THIS FORM WILL BE READ BY A MACHINE, COMPLETE ALL SECTIONS AS DESCRIBED.
Also test if the latest release, and devel branch are affected too.
ALWAYS add information AFTER (OUTSIDE) these html comments.
Otherwise it may end up being automatically closed by our bot. -->

##### SUMMARY
<!--- Explain the problem briefly -->
I have set in `ansible.cfg` a custom path for lookup plugins. There, I have a copy of the `password.py` plugin that accepts a seed parameter. Up until recently, I was able to load and use this plugin. But not anymore. The default one that ships with ansible is always loaded.

##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
<!--- Insert, BELOW THIS COMMENT, the name of the module, plugin, task or feature.
Do not include extra details here, e.g. "vyos_command" not "the network module vyos_command" or the full path-->
lookup_plugins

##### ANSIBLE VERSION
<!--- Paste, BELOW THIS COMMENT, verbatim output from "ansible --version" between quotes below -->
```
ansible 2.7.0.dev0 (devel f30e0b833d) last updated 2018/06/24 01:26:20 (GMT +200)
  config file = None
  configured module search path = ['/home/nikos/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/nikos/Projects/ansible/lib/ansible
  executable location = /home/nikos/Projects/ansible/bin/ansible
  python version = 3.6.5 (default, May 11 2018, 04:00:52) [GCC 8.1.0]
```

##### CONFIGURATION
<!--- If using Ansible 2.4 or above, paste, BELOW THIS COMMENT, the results of "ansible-config dump --only-changed"
Otherwise, mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).-->
```
ANSIBLE_FORCE_COLOR(project_path/ansible/ansible.cfg) = True                                        
ANSIBLE_NOCOWS(project_path/ansible/ansible.cfg) = True                                             
ANSIBLE_PIPELINING(project_path/ansible/ansible.cfg) = True                                         
ANSIBLE_SSH_ARGS(project_path/ansible/ansible.cfg) = -o ControlPath=/var/shm/control:%h:%p:%r       
ANY_ERRORS_FATAL(project_path/ansible/ansible.cfg) = True                                           
CACHE_PLUGIN(project_path/ansible/ansible.cfg) = yaml                                               
CACHE_PLUGIN_CONNECTION(project_path/ansible/ansible.cfg) = tmp/facts_cache                         
CACHE_PLUGIN_TIMEOUT(project_path/ansible/ansible.cfg) = 7200                                       
COLOR_DEBUG(project_path/ansible/ansible.cfg) = magenta                                             
DEFAULT_CALLBACK_PLUGIN_PATH(project_path/ansible/ansible.cfg) = ['project_path/ansible/lib/plugins/callback']
DEFAULT_CALLBACK_WHITELIST(project_path/ansible/ansible.cfg) = ['timer', 'log_plays_overwrite']     
DEFAULT_EXECUTABLE(project_path/ansible/ansible.cfg) = /bin/bash                                    
DEFAULT_FILTER_PLUGIN_PATH(project_path/ansible/ansible.cfg) = ['project_path/ansible/lib/plugins/filter']
DEFAULT_GATHERING(project_path/ansible/ansible.cfg) = explicit                                      
DEFAULT_GATHER_SUBSET(project_path/ansible/ansible.cfg) = !hardware,!ohai,!facter                   
DEFAULT_HOST_LIST(project_path/ansible/ansible.cfg) = ['project_path/vars/active/inventory.yml']    
DEFAULT_INVENTORY_PLUGIN_PATH(project_path/ansible/ansible.cfg) = ['project_path/ansible/lib/plugins/inventory']
DEFAULT_LOOKUP_PLUGIN_PATH(project_path/ansible/ansible.cfg) = ['project_path/ansible/lib/plugins/lookup']
DEFAULT_MANAGED_STR(project_path/ansible/ansible.cfg) = Ansible managed (do not edit, changes may be overwritten)
DEFAULT_MODULE_PATH(project_path/ansible/ansible.cfg) = ['project_path/ansible/lib/modules']        
DEFAULT_MODULE_UTILS_PATH(project_path/ansible/ansible.cfg) = ['project_path/ansible/lib/module_utils']
DEFAULT_PRIVATE_KEY_FILE(project_path/ansible/ansible.cfg) = project_path/gce/ssh_key                              
DEFAULT_ROLES_PATH(project_path/ansible/ansible.cfg) = ['project_path/roles', 'project_path/rol>    
DEFAULT_STDOUT_CALLBACK(project_path/ansible/ansible.cfg) = dense_with_book                         
DEFAULT_STRATEGY(project_path/ansible/ansible.cfg) = linear                                         
DEFAULT_TIMEOUT(project_path/ansible/ansible.cfg) = 30                                              
DEFAULT_UNDEFINED_VAR_BEHAVIOR(project_path/ansible/ansible.cfg) = True                             
DEFAULT_VARS_PLUGIN_PATH(project_path/ansible/ansible.cfg) = ['project_path/ansible/lib/plugins/vars']
DEPRECATION_WARNINGS(project_path/ansible/ansible.cfg) = False                                      
DISPLAY_ARGS_TO_STDOUT(project_path/ansible/ansible.cfg) = True                                     
DISPLAY_SKIPPED_HOSTS(project_path/ansible/ansible.cfg) = False                                     
HOST_KEY_CHECKING(project_path/ansible/ansible.cfg) = False                                         
RETRY_FILES_ENABLED(project_path/ansible/ansible.cfg) = False                                       
USE_PERSISTENT_CONNECTIONS(project_path/ansible/ansible.cfg) = True                                 
```

##### OS / ENVIRONMENT
<!--- Mention, BELOW THIS COMMENT, the OS you are running Ansible from, and the OS you are
managing, or say "N/A" for anything that is not platform-specific.
Also mention the specific version of what you are trying to control,
e.g. if this is a network bug the version of firmware on the network device.-->
Arch linux latest

##### STEPS TO REPRODUCE
<!--- For bugs, show exactly how to reproduce the problem, using a minimal test-case.
For new features, show how the feature would be used. -->

<!--- Paste example playbooks or commands between quotes below -->
This is how I use the lookup:
```yaml
random_pass_10: "{{ lookup('password', '/dev/null length=10 seed=' + seed) }}"
```
Then I try to save it in a file with the `copy` module.

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->
The password would be generated and be the same every time.

##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->
I get an error:

<!--- Paste verbatim command output between quotes below -->
```
"msg": "An unhandled exception occurred while templating <the template here, more lines like the one I posted above>. Error was a <class 'ansible.errors.AnsibleError'>, original message: An unhandled exception occurred while templating '{{ lookup('password', '/dev/null length=20 seed=' + seed) }}'. Error was a <class 'ansible.errors.AnsibleError'>, original message: An unhandled exception occurred while running the lookup plugin 'password'. Error was a <class 'ansible.errors.AnsibleError'>, original message: Unrecognized parameter(s) given to password lookup: seed"
```



Discussion:
Files identified in the description:
None

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](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
This issue was introduced in https://github.com/ansible/ansible/commit/dd02a4e9433f467aec5a4921fe2928bc651e47eb

This is due to the addition of the following in `lib/ansible/plugins/filter/network.py`

```
from ansible.plugins.lookup import password as ansible_password
```

The above seems to break the plugin loader.
I've submitted a PR to resolve this issue: https://github.com/ansible/ansible/pull/41907

Resolving patch:
diff --git a/lib/ansible/plugins/filter/network.py b/lib/ansible/plugins/filter/network.py
--- a/lib/ansible/plugins/filter/network.py
+++ b/lib/ansible/plugins/filter/network.py
@@ -28,11 +28,11 @@
 from collections import Mapping
 from xml.etree.ElementTree import fromstring
 
+from ansible.module_utils._text import to_text
 from ansible.module_utils.network.common.utils import Template
 from ansible.module_utils.six import iteritems, string_types
 from ansible.errors import AnsibleError, AnsibleFilterError
 from ansible.utils.encrypt import random_password
-from ansible.plugins.lookup import password as ansible_password
 
 
 try:
@@ -362,7 +362,11 @@ def type5_pw(password, salt=None):
     if not isinstance(password, string_types):
         raise AnsibleFilterError("type5_pw password input should be a string, but was given a input of %s" % (type(password).__name__))
 
-    salt_chars = ansible_password._gen_candidate_chars(['ascii_letters', 'digits', './'])
+    salt_chars = u''.join((
+        to_text(string.ascii_letters),
+        to_text(string.digits),
+        u'./'
+    ))
     if salt is not None and not isinstance(salt, string_types):
         raise AnsibleFilterError("type5_pw salt input should be a string, but was given a input of %s" % (type(salt).__name__))
     elif not salt:


Test patch: