Repository: ansible/ansible-modules-extras

Issue:
gluster_volume: no replicas not possible
It's not possible to set up gluster without clusters. I always get the following error.
My ansible version is 1.9.2 on Mac os

failed: [fileserver] => {"failed": true, "parsed": false}
BECOME-SUCCESS-gzczujddrapqbuwwbbcknuyjaqorlryu
Traceback (most recent call last):
  File "/root/.ansible/tmp/ansible-tmp-1444394830.43-46504764465318/gluster_volume", line 2045, in <module>
    main()
  File "/root/.ansible/tmp/ansible-tmp-1444394830.43-46504764465318/gluster_volume", line 365, in main
    probe_all_peers(cluster, peers, myhostname)
  File "/root/.ansible/tmp/ansible-tmp-1444394830.43-46504764465318/gluster_volume", line 253, in probe_all_peers
    for host in hosts:
TypeError: 'NoneType' object is not iterable

Here is the code I use - but I can also just use state and name => Same error:
- name: Setup gluster volume
  gluster_volume:
    state: "present"
    name: "{{ gluster_brick_name }}"
    brick: "{{ gluster_brick_dir }}"
    force: yes
  run_once: true



Discussion:
[module: system/gluster_volume.py]

Hi @Bullettoothtobi -- thanks for submitting this bug report. 

@rosmo -- thanks in advance for taking a look at this bug report and for your ongoing work in maintaining this module.

@Bullettoothtobi, have you tried just passing one host to clusters?

Yes. But it didn’t work.

> Am 19.10.2015 um 22:05 schrieb Taneli Leppä notifications@github.com:
> 
> @Bullettoothtobi https://github.com/Bullettoothtobi, have you tried just passing one host to clusters?
> 
> —
> Reply to this email directly or view it on GitHub https://github.com/ansible/ansible-modules-extras/issues/1074#issuecomment-149331018.

@Bullettoothtobi, can you give me the module parameters you used?

@rosmo I'm having the same issue.

``` yaml
  - name: Gluster Test
    gluster_volume:
      name: "test_volume"
      brick: '/brick_test'
      force: True
      state: present
```

```
failed: [www-app-1.localhost] => {"failed": true, "parsed": false}
BECOME-SUCCESS-ygcjwqrafinyuzexahiuxlqvmwwnjkxt
Traceback (most recent call last):
  File "/home/vagrant/.ansible/tmp/ansible-tmp-1451768104.05-202266410922301/gluster_volume", line 2052, in <module>
    main()
  File "/home/vagrant/.ansible/tmp/ansible-tmp-1451768104.05-202266410922301/gluster_volume", line 365, in main
    probe_all_peers(cluster, peers, myhostname)
  File "/home/vagrant/.ansible/tmp/ansible-tmp-1451768104.05-202266410922301/gluster_volume", line 253, in probe_all_peers
    for host in hosts:
TypeError: 'NoneType' object is not iterable
```

``` yaml
  - name: Gluster Test
    gluster_volume:
      name: "test_volume"
      cluster: "{{ansible_fqdn}}"
      brick: '/brick_test'
      force: True
      state: present
```

```
failed: [www-app-1.localhost] => {"failed": true}
msg: failed to probe peer www-app-1.localhost
```


Resolving patch:
diff --git a/system/gluster_volume.py b/system/gluster_volume.py
--- a/system/gluster_volume.py
+++ b/system/gluster_volume.py
@@ -350,9 +350,12 @@ def main():
 
     # Clean up if last element is empty. Consider that yml can look like this:
     #   cluster="{% for host in groups['glusterfs'] %}{{ hostvars[host]['private_ip'] }},{% endfor %}"
-    if cluster != None and cluster[-1] == '':
+    if cluster != None and len(cluster) > 1 and cluster[-1] == '':
         cluster = cluster[0:-1]
 
+    if cluster == None or cluster[0] == '':
+        cluster = [myhostname]
+
     if brick_paths != None and "," in brick_paths:
         brick_paths = brick_paths.split(",")
     else:


Test patch: