Repository: ansible/ansible

Issue:
ansible-doc misses inventory plugins in user-defined search path
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
`ansible-doc` CLI

##### ANSIBLE VERSION
```
ansible --version
ansible 2.5.0
  config file = None
  configured module search path = [u'/Users/alancoding/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/alancoding/.virtualenvs/ansible/lib/python2.7/site-packages/ansible-2.5.0-py2.7.egg/ansible
  executable location = /Users/alancoding/.virtualenvs/ansible/bin/ansible
  python version = 2.7.10 (default, Jul 13 2015, 12:05:58) [GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)]
```

##### CONFIGURATION
```
ansible-config dump --only-changed
ANSIBLE_NOCOWS(env: ANSIBLE_NOCOWS) = True
DEFAULT_INVENTORY_PLUGIN_PATH(env: ANSIBLE_INVENTORY_PLUGINS) = [u'/Users/alancoding/Documents/repos/ansible-inventory-file-examples/plugins/user_plugins']
INVENTORY_ENABLED(env: ANSIBLE_INVENTORY_ENABLED) = ['alan']
```

##### OS / ENVIRONMENT
Mac

##### SUMMARY
Custom inventory plugins in the path defined by `ANSIBLE_INVENTORY_PLUGINS` is not shown in the output of `ansible-doc -t inventory -l`. If I put the plugin in the current working directory in `inventory_plugins` folder, it is shown.

##### STEPS TO REPRODUCE
also documented in: https://github.com/AlanCoding/Ansible-inventory-file-examples/tree/master/plugins

Save the following file to `alan.py` somewhere.

```python
# Copyright (c) 2017 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

DOCUMENTATION = r'''
    inventory: alan
    version_added: "2.5"
    short_description: Returns string "alan" for values of stuff
    description:
        - Ignores whatever you give it
        - Returns inventory containing "alan"
'''

EXAMPLES = r'''
    # ansible -i 'host1.example.com, host2' -m user -a 'name=me state=absent' all
'''

import os

from ansible.errors import AnsibleError, AnsibleParserError
from ansible.module_utils._text import to_bytes, to_native
from ansible.parsing.utils.addresses import parse_address
from ansible.plugins.inventory import BaseInventoryPlugin


class InventoryModule(BaseInventoryPlugin):

    NAME = 'alan'

    def verify_file(self, host_list):
        return True  # looks good

    def parse(self, inventory, loader, host_list, cache=True):
        ''' doesnt parse the inventory file, but claims it did anyway '''
        super(InventoryModule, self).parse(inventory, loader, host_list)
        self.inventory.add_host('alan', group='ungrouped', port=8928)
```

Now put that path in the search path for inventory plugins. Example:

```
export export ANSIBLE_INVENTORY_PLUGINS=$(PWD)/alan.py
```

Enable it, or don't, makes no difference

```
export ANSIBLE_INVENTORY_ENABLED=alan
```

Now view available plugins.

```
ansible-doc -t inventory -l
```

##### EXPECTED RESULTS
That we find "alan" plugin in the list. If I put it in the adjacent `inventory_plugins` directory, and run the command, it _is_ listed.

https://github.com/AlanCoding/Ansible-inventory-file-examples/tree/master/plugins/user_plugins_rel

```
ansible-doc -t inventory -l
advanced_host_list Parses a 'host list' with ranges                                                                                                                             
alan               Returns string "alan" for values of stuff                                                                                                                    
constructed        Uses Jinja2 to construct vars and groups based on existing inventory.                                                                                        
host_list          Parses a 'host list' string                                                                                                                                  
ini                Uses an Ansible INI file as inventory source.                                                                                                                
openstack          OpenStack inventory source                                                                                                                                   
script             Executes an inventory script that returns JSON                                                                                                               
virtualbox         virtualbox inventory source                                                                                                                                  
yaml               Uses a specifically YAML file as inventory source.  
```

##### ACTUAL RESULTS
Not in list:

```
ansible-doc -t inventory -l
advanced_host_list Parses a 'host list' with ranges                                                                                                                             
constructed        Uses Jinja2 to construct vars and groups based on existing inventory.                                                                                        
host_list          Parses a 'host list' string                                                                                                                                  
ini                Uses an Ansible INI file as inventory source.                                                                                                                
openstack          OpenStack inventory source                                                                                                                                   
script             Executes an inventory script that returns JSON                                                                                                               
virtualbox         virtualbox inventory source                                                                                                                                  
yaml               Uses a specifically YAML file as inventory source. 
```

Alternatively:

```
ansible-doc -t inventory alan
 [WARNING]: inventory alan not found in: /Users/alancoding/Documents/repos/ansible-inventory-file-
examples/plugins/inventory_plugins:/Users/alancoding/.virtualenvs/ansible/lib/python2.7/site-packages/ansible-2.5.0-py2.7.egg/ansible/plugins/inventory
```


Discussion:
~dupe of #31743, fixed via #31744~

Resolving patch:
diff --git a/lib/ansible/cli/doc.py b/lib/ansible/cli/doc.py
--- a/lib/ansible/cli/doc.py
+++ b/lib/ansible/cli/doc.py
@@ -95,7 +95,7 @@ def run(self):
         elif plugin_type == 'vars':
             loader = vars_loader
         elif plugin_type == 'inventory':
-            loader = PluginLoader('InventoryModule', 'ansible.plugins.inventory', 'inventory_plugins', 'inventory_plugins')
+            loader = PluginLoader('InventoryModule', 'ansible.plugins.inventory', C.DEFAULT_INVENTORY_PLUGIN_PATH, 'inventory_plugins')
         else:
             loader = module_loader
 


Test patch: