Repository: ansible/ansible

Issue:
Handle blank lines and comments in galaxy spec files
`ansible.utils.role_spec_parse` (and v2 equivalent) already
handle when the roles file contains blank lines or comments

Make `ansible.utils.role_spec_parse` and
`ansible.playbook.role.requirement._role_spec_parse`
return a more appropriate result

Fix ansible-galaxy to make use of that information



Discussion:
@bcoca - inlclude for bin/ansible-galaxy update.

@willthames do you plan to rebase this to apply to current devel?

@amenonsen I have no such plans at present. @jimi-c has notified @bcoca that this should be in v2 galaxy. If v2 galaxy were stable and working, I'd consider revisiting this pull request.

this should not be an issue in devel, can you test against it or provide a test case?

@bcoca it is an issue in devel

```
$ ansible --version
ansible 2.0.0 (devel 63b54a3271) last updated 2015/07/30 09:13:09 (GMT +1000)
  lib/ansible/modules/core: (stable-1.9 18c8e06640) last updated 2015/07/22 14:06:14 (GMT +1000)
  lib/ansible/modules/extras: (detached HEAD 3c6707ada1) last updated 2015/07/23 14:15:44 (GMT +1000)
  v1/ansible/modules/core: (detached HEAD f8d8af17cd) last updated 2015/06/15 15:23:40 (GMT +1000)
  v1/ansible/modules/extras: (detached HEAD 495ad450e5) last updated 2015/06/15 15:23:47 (GMT +1000)
  config file = 
  configured module search path = None
```

rolesfile: 

```
# comment

geerlingguy.mysql
```

```
$ ansible-galaxy install -r rolesfile -p roles -f 
- downloading role '%23%20comment', owned by 
 [WARNING]: - sorry, # comment was not found on https://galaxy.ansible.com.

 [ERROR]: - you can use --ignore-errors to skip failed roles and finish
processing the list.

 [WARNING]: -  was NOT installed successfully.
```

Note that both the comment line and the blank line cause separate failures. 

Interestingly, it does carry on regardless, so that is slightly improved from before - but that does mean that the error message is redundant. 

```
 [ERROR]: - you can use --ignore-errors to skip failed roles and finish
processing the list.
```

weird, as my tests:

-- requirements.yml

```
# this is a comment

- src: chrismeyersfsu.ec2_server
```

do work:

```
#> ansible-galaxy install -p ~/work/envs/roles -r requirements.yml  -vvv
Using /etc/ansible/ansible.cfg as config file
- downloading role 'ec2_server', owned by chrismeyersfsu
- https://galaxy.ansible.com/api/v1/roles/?owner__username=chrismeyersfsu&name=ec2_server
- downloading role from https://github.com/chrismeyersfsu/role-ec2_server/archive/master.tar.gz
- extracting chrismeyersfsu.ec2_server to /home/bcoca/work/envs/roles/chrismeyersfsu.ec2_server
- chrismeyersfsu.ec2_server was installed successfully
```

nvmd, the yaml files are OK, its the non yaml

ok, now it should work


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
@@ -328,6 +328,8 @@ def execute_install(self):
                     self.display.deprecated("going forward only the yaml format will be supported")
                     # roles listed in a file, one per line
                     for rline in f.readlines():
+                        if rline.startswith("#") or rline.strip() == '':
+                            continue
                         self.display.debug('found role %s in text file' % str(rline))
                         role = RoleRequirement.role_yaml_parse(rline.strip())
                         roles_left.append(GalaxyRole(self.galaxy, **role))


Test patch:
diff --git a/test/integration/galaxy_rolesfile b/test/integration/galaxy_rolesfile
--- a/test/integration/galaxy_rolesfile
+++ b/test/integration/galaxy_rolesfile
@@ -1,4 +1,8 @@
+# deliberate non-empty whitespace line to follow
+    
+
 git+https://bitbucket.org/willthames/git-ansible-galaxy,v1.6
 hg+https://bitbucket.org/willthames/hg-ansible-galaxy
 https://bitbucket.org/willthames/http-ansible-galaxy/get/master.tar.gz,,http-role
+# comment
 git+git@github.com:geerlingguy/ansible-role-php.git