Repository: ansible/ansible-modules-extras

Issue:
gluster_volume should add replica and stripe arguments when adding bricks
##### ISSUE TYPE
- Bug Report
##### COMPONENT NAME

gluster_volume
##### ANSIBLE VERSION

```
ansible 2.1.1.0 (stable-2.1 137385059c) last updated 2016/07/13 17:51:42 (GMT +300)
  lib/ansible/modules/core: (detached HEAD 887e7cf145) last updated 2016/07/13 17:51:49 (GMT +300)
  lib/ansible/modules/extras: (detached HEAD e9c30f811f) last updated 2016/07/13 17:51:49 (GMT +300)
  config file = /Users/cqx874/ansible/w7k-spb-lab-ansible/ansible.cfg
  configured module search path = Default w/o overrides
```
##### CONFIGURATION

<!---
Mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).
-->
##### OS / ENVIRONMENT

OS: Mac OS X 10.11.6

```
$ cat ansible.cfg 
[defaults]
roles_path = ./roles
retry_files_enabled = False

[ssh_connection]
pipelining=False
```

```
$ env | grep ANSIBLE
ANSIBLE_VAULT_PASSWORD_FILE=/Users/cqx874/.vault
ANSIBLE_HOME=/Users/cqx874/ansible/ansible
```
##### SUMMARY

`gluster_volume` module fails to add brick to a gluster volume as it issues gluster command without reconfiguration of stripes and replicas:
`gluster volume add-brick XXX HOST:PATH force`
instead of
`gluster volume add-brick XXX replica N HOST:PATH force`
##### STEPS TO REPRODUCE

Role has the following task

```
- name: Configure gluster volume
  gluster_volume:
    state=present
    name="{{__gluster_volume_name}}"
    brick="/home/gluster/{{__gluster_volume_name}}/brick"
    replicas="{{__gluster_replica}}"
    cluster="{{__gluster_servers | join(',') }}"
    host="{{inventory_hostname}}"
    start_on_create=yes
    transport=tcp
    force=yes
  run_once: true
```

Initial situation: gluster has a volume with two bricks and replica=2
I've added a new host to the inventory.
##### EXPECTED RESULTS

I've expected the role would add a new brick.
##### ACTUAL RESULTS

`gluster_volume` failed:

```
error running gluster (/usr/sbin/gluster volume add-brick engine node3:/home/gluster/engine/brick force) command (rc=1): volume add-brick: failed: Incorrect number of bricks supplied 1 with count 2\n
```



Discussion:
The patch for whoever may be interested:

```
--- ../ansible/lib/ansible/modules/extras/system/gluster_volume.py  2016-03-14 14:37:19.000000000 +0300
+++ library/cqx874_gluster_volume.py    2016-08-18 16:28:37.000000000 +0300
@@ -288,8 +288,14 @@ def stop_volume(name):
 def set_volume_option(name, option, parameter):
     run_gluster([ 'volume', 'set', name, option, parameter ])

-def add_bricks(name, new_bricks, force):
+def add_bricks(name, new_bricks, stripe, replica, force):
     args = [ 'volume', 'add-brick', name ]
+    if stripe:
+        args.append('stripe')
+        args.append(str(stripe))
+    if replica:
+        args.append('replica')
+        args.append(str(replica))
     args.extend(new_bricks)
     if force:
         args.append('force')
@@ -412,7 +418,7 @@ def main():
                     removed_bricks.append(brick)

             if new_bricks:
-                add_bricks(volume_name, new_bricks, force)
+                add_bricks(volume_name, new_bricks, stripes, replicas, force)
                 changed = True

             # handle quotas
```

@rosmo, ping. This issue is waiting on your response.
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)

<!--- boilerplate: issue_notify_maintainer --->


Resolving patch:
diff --git a/system/gluster_volume.py b/system/gluster_volume.py
--- a/system/gluster_volume.py
+++ b/system/gluster_volume.py
@@ -291,8 +291,14 @@ def stop_volume(name):
 def set_volume_option(name, option, parameter):
     run_gluster([ 'volume', 'set', name, option, parameter ])
 
-def add_bricks(name, new_bricks, force):
+def add_bricks(name, new_bricks, stripe, replica, force):
     args = [ 'volume', 'add-brick', name ]
+    if stripe:
+        args.append('stripe')
+        args.append(str(stripe))
+    if replica:
+        args.append('replica')
+        args.append(str(replica))
     args.extend(new_bricks)
     if force:
         args.append('force')
@@ -415,7 +421,7 @@ def main():
                     removed_bricks.append(brick)
 
             if new_bricks:
-                add_bricks(volume_name, new_bricks, force)
+                add_bricks(volume_name, new_bricks, stripes, replicas, force)
                 changed = True
 
             # handle quotas


Test patch: