Repository: ansible/ansible

Issue:
roles_path does not use multiple locations
<!---
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 -->
The `roles_path` does not support multiple locations as suggested in the `ansible.cfg` comments:

```
# additional paths to search for roles in, colon separated
```

##### 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-->
ansible.cfg

##### ANSIBLE VERSION
<!--- Paste, BELOW THIS COMMENT, verbatim output from "ansible --version" between quotes below -->
```
ansible 2.6.1
  config file = /Users/pfiddes/Projects/gcloud-infrastructure/ansible/ansible.cfg
  configured module search path = ['/Users/pfiddes/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/pfiddes/Projects/gcloud-infrastructure/ansible/.env/lib/python3.7/site-packages/ansible
  executable location = /Users/pfiddes/Projects/gcloud-infrastructure/ansible/.env/bin/ansible
  python version = 3.7.0 (default, Jun 29 2018, 20:13:13) [Clang 9.1.0 (clang-902.0.39.2)]
```

##### 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).-->

I have only set the `roles_path` in ansible.cfg. During debugging I have also used the `ANSIBLE_ROLES_PATH` environment variable to see if it has the same effect.

##### 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.-->

Ansible running on MacOS High Sierra 10.13.6

##### 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 -->
1) Set something like the following in ansible.cfg - colon separated. Make sure you have roles in both locations you specify
```
roles_path = roles:~/.ansible/roles
```

2) run `ansible-galaxy list`

Alternatively use the environment variable:

```
ANSIBLE_ROLES_PATH="~/ansible_roles:roles" ansible-galaxy list
```

Note it has to be a colon as semi-colons and commas cause obvious errors.

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->

I expected a combined output of all roles available in both locations.

##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->

The output shows only roles in the first location specified.
For example when:
```
roles_path = roles:~/.ansible/roles
```
I see roles from the `roles` directory

When I set:
```
roles_path = ~/.ansible/roles:roles
```
I see roles from the `~/.ansible/roles` directory

<!--- Paste verbatim command output between quotes below -->
```

```

Perhaps I'm missing something obvious but I've tried a number of options without success.


Discussion:
Files identified in the description:
* [examples/ansible.cfg](https://github.com/ansible/ansible/blob/devel/examples/ansible.cfg)

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 --->
I am able to duplicate this in `devel`. Looks like only the first item in the path shows up in the output of `ansible-galaxy list`. 
Looks like we need to pass `path` to the GalaxyRole object in [`execute_task()`](https://github.com/ansible/ansible/blob/e756ef82659f333429ec4a655ade72cb28b9b34c/lib/ansible/cli/galaxy.py#L503-L503). Otherwise is defaults to using the first path in `roles_path`.

Resolving patch:
diff --git a/lib/ansible/cli/galaxy.py b/lib/ansible/cli/galaxy.py
--- a/lib/ansible/cli/galaxy.py
+++ b/lib/ansible/cli/galaxy.py
@@ -500,7 +500,7 @@ def execute_list(self):
                 path_files = os.listdir(role_path)
                 path_found = True
                 for path_file in path_files:
-                    gr = GalaxyRole(self.galaxy, path_file)
+                    gr = GalaxyRole(self.galaxy, path_file, path=path)
                     if gr.metadata:
                         install_info = gr.install_info
                         version = None


Test patch: