Repository: ansible/ansible

Issue:
ansible-galaxy mismatches unquoted single-dot version numbers in requirements.yml
##### Issue Type:  Bug Report
##### Ansible Version: 1.8.2
##### Environment: N/A / Ubuntu 14.04
##### Summary:

It seems that when a `requirements` file contains an _unquoted_ `version` tag with only a single `.` character, the parser coerces the version number to a floating-point value, causing `ansible-galaxy` to be unable to match the version id.

It is of course possible to work around the problem by surrounding the version with string delimiters, but this nevertheless looks like inconsistent behavior.
##### Steps To Reproduce:

Using [nsg-graphite](https://galaxy.ansible.com/list#/roles/1176) as an example, create the requirements file containing:

```
- src: nsg.graphite
  version: 1.2
```

And run `ansible-galaxy` with it.
##### Expected Results:

`ansible-galaxy` successfully installs the role, since the version exists.
##### Actual Results:

```
- downloading role 'graphite', owned by nsg
role is {'scm': None, 'src': 'nsg.graphite', 'version': 1.2, 'name': 'nsg.graphite'}
- the specified version (1.2) was not found in the list of available versions ([{u'release_date': u'2015-02-07T20:47:33Z', u'id': 3238, u'name': u'1.2'}, {u'release_date': u'2014-07-29T14:26:41Z', u'id': 1121, u'name': u'1.1'}, {u'release_date': u'2014-07-26T00:01:21Z', u'id': 1068, u'name': u'1.0.2'}, {u'release_date': u'2014-07-25T15:26:38Z', u'id': 1056, u'name': u'1.0.1'}, {u'release_date': u'2014-07-25T15:17:07Z', u'id': 1057, u'name': u'1.0'}]).
```

As you can see, `version` is an fp value in the first dict, whereas it's always a `unicode` object in the "version reference" dict.



Discussion:
Reproduced with devel ...

```
###################################
devel-02859a3
###################################
- downloading role 'graphite', owned by nsg
 [WARNING]: - nsg.graphite was NOT installed successfully: - the specified version (1.2) of
nsg.graphite was not found in the list of available versions ([{u'name': u'1.5', u'created':
u'2015-11-29T20:22:41.554Z', u'url': u'', u'release_date': None, u'modified':
u'2015-11-29T20:22:41.719Z', u'related': {}, u'id': 8259, u'active': True, u'summary_fields':
{u'role': {u'id': 1176, u'name': u'graphite'}}}, {u'name': u'1.4', u'created':
u'2015-11-29T20:22:41.736Z', u'url': u'', u'release_date': None, u'modified':
u'2015-11-29T20:22:41.840Z', u'related': {}, u'id': 8260, u'active': True, u'summary_fields':
{u'role': {u'id': 1176, u'name': u'graphite'}}}, {u'name': u'1.3', u'created':
u'2015-08-20T11:15:48.689Z', u'url': u'', u'release_date': None, u'modified':
u'2015-08-20T11:15:48.849Z', u'related': {}, u'id': 5922, u'active': True, u'summary_fields':
{u'role': {u'id': 1176, u'name': u'graphite'}}}, {u'name': u'1.2', u'created':
u'2015-02-08T21:17:32.653Z', u'url': u'', u'release_date': None, u'modified':
u'2015-02-08T21:17:32.805Z', u'related': {}, u'id': 3238, u'active': True, u'summary_fields':
{u'role': {u'id': 1176, u'name': u'graphite'}}}, {u'name': u'1.1', u'created':
u'2014-07-29T10:27:18.197Z', u'url': u'', u'release_date': None, u'modified':
u'2014-07-29T10:27:18.299Z', u'related': {}, u'id': 1121, u'active': True, u'summary_fields':
{u'role': {u'id': 1176, u'name': u'graphite'}}}, {u'name': u'1.0.2', u'created':
u'2014-07-25T20:02:28.894Z', u'url': u'', u'release_date': None, u'modified':
u'2014-07-25T20:02:28.994Z', u'related': {}, u'id': 1068, u'active': True, u'summary_fields':
{u'role': {u'id': 1176, u'name': u'graphite'}}}, {u'name': u'1.0.1', u'created':
u'2014-07-25T11:27:06.270Z', u'url': u'', u'release_date': None, u'modified':
u'2014-07-25T11:27:06.378Z', u'related': {}, u'id': 1056, u'active': True, u'summary_fields':
{u'role': {u'id': 1176, u'name': u'graphite'}}}, {u'name': u'1.0', u'created':
u'2014-07-25T11:27:06.408Z', u'url': u'', u'release_date': None, u'modified':
u'2014-07-25T11:27:06.533Z', u'related': {}, u'id': 1057, u'active': True, u'summary_fields':
{u'role': {u'id': 1176, u'name': u'graphite'}}}]).

ERROR! - you can use --ignore-errors to skip failed roles and finish processing the list.
## RC: 1
```


Resolving patch:
diff --git a/lib/ansible/galaxy/role.py b/lib/ansible/galaxy/role.py
--- a/lib/ansible/galaxy/role.py
+++ b/lib/ansible/galaxy/role.py
@@ -237,7 +237,7 @@ def install(self):
                     else:
                         self.version = 'master' 
                 elif self.version != 'master':
-                    if role_versions and self.version not in [a.get('name', None) for a in role_versions]:
+                    if role_versions and str(self.version) not in [a.get('name', None) for a in role_versions]:
                         raise AnsibleError("- the specified version (%s) of %s was not found in the list of available versions (%s)." % (self.version, self.name, role_versions))
 
                 tmp_file = self.fetch(role_data)


Test patch: