@ -38,27 +38,33 @@ options:
use started / stopped to control it ' s availability.
use started / stopped to control it ' s availability.
cluster :
cluster :
required : false
required : false
default : null
description :
description :
- List of hosts to use for probing and brick setup
- List of hosts to use for probing and brick setup
host :
host :
required : false
required : false
default : null
description :
description :
- Override local hostname ( for peer probing purposes )
- Override local hostname ( for peer probing purposes )
replicas :
replicas :
required : false
required : false
default : null
description :
description :
- Replica count for volume
- Replica count for volume
stripes :
stripes :
required : false
required : false
default : null
description :
description :
- Stripe count for volume
- Stripe count for volume
transport :
transport :
required : false
required : false
choices : [ ' tcp ' , ' rdma ' , ' tcp,rdma ' ]
choices : [ ' tcp ' , ' rdma ' , ' tcp,rdma ' ]
default : ' tcp '
description :
description :
- Transport type for volume
- Transport type for volume
brick :
brick :
required : false
required : false
default : null
description :
description :
- Brick path on servers
- Brick path on servers
start_on_create :
start_on_create :
@ -69,22 +75,27 @@ options:
rebalance :
rebalance :
choices : [ ' yes ' , ' no ' ]
choices : [ ' yes ' , ' no ' ]
required : false
required : false
default : ' no '
description :
description :
- Controls whether the cluster is rebalanced after changes
- Controls whether the cluster is rebalanced after changes
directory :
directory :
required : false
required : false
default : null
description :
description :
- Directory for limit - usage
- Directory for limit - usage
options :
options :
required : false
required : false
default : null
description :
description :
- A dictionary / hash with options / settings for the volume
- A dictionary / hash with options / settings for the volume
quota :
quota :
required : false
required : false
default : null
description :
description :
- Quota value for limit - usage ( be sure to use 10.0 MB instead of 10 MB , see quota list )
- Quota value for limit - usage ( be sure to use 10.0 MB instead of 10 MB , see quota list )
force :
force :
required : false
required : false
default : null
description :
description :
- If brick is being created in the root partition , module will fail .
- If brick is being created in the root partition , module will fail .
Set force to true to override this behaviour
Set force to true to override this behaviour
@ -119,18 +130,19 @@ import shutil
import time
import time
import socket
import socket
def main ( ) :
def run_gluster ( gargs , * * kwargs ) :
def run_gluster ( gargs , * * kwargs ) :
args = [ glusterbin ]
args = [ glusterbin ]
args . extend ( gargs )
args . extend ( gargs )
try :
rc , out , err = module . run_command ( args , * * kwargs )
rc , out , err = module . run_command ( args , * * kwargs )
if rc != 0 :
if rc != 0 :
module . fail_json ( msg = ' error running gluster ( %s ) command (rc= %d ): %s ' % ( ' ' . join ( args ) , rc , out if out != ' ' else err ) )
module . fail_json ( msg = ' error running gluster ( %s ) command (rc= %d ): %s ' % ( ' ' . join ( args ) , rc , out if out != ' ' else err ) )
except Exception , e :
module . fail_json ( msg = ' error running gluster ( %s ) command: %s ' % ( ' ' . join ( args ) , str ( e ) )
return out
return out
def run_gluster_nofail ( gargs , * * kwargs ) :
def run_gluster_nofail ( gargs , * * kwargs ) :
args = [ glusterbin ]
args = [ glusterbin ]
args . extend ( gargs )
args . extend ( gargs )
rc , out , err = module . run_command ( args , * * kwargs )
rc , out , err = module . run_command ( args , * * kwargs )
@ -138,7 +150,7 @@ def main():
return None
return None
return out
return out
def run_gluster_yes ( gargs ) :
def run_gluster_yes ( gargs ) :
args = [ glusterbin ]
args = [ glusterbin ]
args . extend ( gargs )
args . extend ( gargs )
rc , out , err = module . run_command ( args , data = ' y \n ' )
rc , out , err = module . run_command ( args , data = ' y \n ' )
@ -146,7 +158,7 @@ def main():
module . fail_json ( msg = ' error running gluster ( %s ) command (rc= %d ): %s ' % ( ' ' . join ( args ) , rc , out if out != ' ' else err ) )
module . fail_json ( msg = ' error running gluster ( %s ) command (rc= %d ): %s ' % ( ' ' . join ( args ) , rc , out if out != ' ' else err ) )
return out
return out
def get_peers ( ) :
def get_peers ( ) :
out = run_gluster ( [ ' peer ' , ' status ' ] )
out = run_gluster ( [ ' peer ' , ' status ' ] )
i = 0
i = 0
peers = { }
peers = { }
@ -165,7 +177,7 @@ def main():
peers [ hostname ] = [ uuid , state ]
peers [ hostname ] = [ uuid , state ]
return peers
return peers
def get_volumes ( ) :
def get_volumes ( ) :
out = run_gluster ( [ ' volume ' , ' info ' ] )
out = run_gluster ( [ ' volume ' , ' info ' ] )
volumes = { }
volumes = { }
@ -201,7 +213,7 @@ def main():
volume = { }
volume = { }
return volumes
return volumes
def get_quotas ( name , nofail ) :
def get_quotas ( name , nofail ) :
quotas = { }
quotas = { }
if nofail :
if nofail :
out = run_gluster_nofail ( [ ' volume ' , ' quota ' , name , ' list ' ] )
out = run_gluster_nofail ( [ ' volume ' , ' quota ' , name , ' list ' ] )
@ -215,7 +227,7 @@ def main():
quotas [ q [ 0 ] ] = q [ 1 ]
quotas [ q [ 0 ] ] = q [ 1 ]
return quotas
return quotas
def wait_for_peer ( host ) :
def wait_for_peer ( host ) :
for x in range ( 0 , 4 ) :
for x in range ( 0 , 4 ) :
peers = get_peers ( )
peers = get_peers ( )
if host in peers and peers [ host ] [ 1 ] . lower ( ) . find ( ' peer in cluster ' ) != - 1 :
if host in peers and peers [ host ] [ 1 ] . lower ( ) . find ( ' peer in cluster ' ) != - 1 :
@ -223,20 +235,20 @@ def main():
time . sleep ( 1 )
time . sleep ( 1 )
return False
return False
def probe ( host ) :
def probe ( host ) :
run_gluster ( [ ' peer ' , ' probe ' , host ] )
run_gluster ( [ ' peer ' , ' probe ' , host ] )
if not wait_for_peer ( host ) :
if not wait_for_peer ( host ) :
module . fail_json ( msg = ' failed to probe peer %s ' % host )
module . fail_json ( msg = ' failed to probe peer %s ' % host )
changed = True
changed = True
def probe_all_peers ( hosts , peers , myhostname ) :
def probe_all_peers ( hosts , peers , myhostname ) :
for host in hosts :
for host in hosts :
if host not in peers :
if host not in peers :
# dont probe ourselves
# dont probe ourselves
if myhostname != host :
if myhostname != host :
probe ( host )
probe ( host )
def create_volume ( name , stripe , replica , transport , hosts , brick , force ) :
def create_volume ( name , stripe , replica , transport , hosts , brick , force ) :
args = [ ' volume ' , ' create ' ]
args = [ ' volume ' , ' create ' ]
args . append ( name )
args . append ( name )
if stripe :
if stripe :
@ -253,31 +265,32 @@ def main():
args . append ( ' force ' )
args . append ( ' force ' )
run_gluster ( args )
run_gluster ( args )
def start_volume ( name ) :
def start_volume ( name ) :
run_gluster ( [ ' volume ' , ' start ' , name ] )
run_gluster ( [ ' volume ' , ' start ' , name ] )
def stop_volume ( name ) :
def stop_volume ( name ) :
run_gluster_yes ( [ ' volume ' , ' stop ' , name ] )
run_gluster_yes ( [ ' volume ' , ' stop ' , name ] )
def set_volume_option ( name , option , parameter ) :
def set_volume_option ( name , option , parameter ) :
run_gluster ( [ ' volume ' , ' set ' , name , option , parameter ] )
run_gluster ( [ ' volume ' , ' set ' , name , option , parameter ] )
def add_brick ( name , brick , force ) :
def add_brick ( name , brick , force ) :
args = [ ' volume ' , ' add-brick ' , name , brick ]
args = [ ' volume ' , ' add-brick ' , name , brick ]
if force :
if force :
args . append ( ' force ' )
args . append ( ' force ' )
run_gluster ( args )
run_gluster ( args )
def rebalance( name ) :
def do_ rebalance( name ) :
run_gluster ( [ ' volume ' , ' rebalance ' , name , ' start ' ] )
run_gluster ( [ ' volume ' , ' rebalance ' , name , ' start ' ] )
def enable_quota ( name ) :
def enable_quota ( name ) :
run_gluster ( [ ' volume ' , ' quota ' , name , ' enable ' ] )
run_gluster ( [ ' volume ' , ' quota ' , name , ' enable ' ] )
def set_quota ( name , directory , value ) :
def set_quota ( name , directory , value ) :
run_gluster ( [ ' volume ' , ' quota ' , name , ' limit-usage ' , directory , value ] )
run_gluster ( [ ' volume ' , ' quota ' , name , ' limit-usage ' , directory , value ] )
def main ( ) :
### MAIN ###
### MAIN ###
module = AnsibleModule (
module = AnsibleModule (
@ -403,7 +416,7 @@ def main():
if changed :
if changed :
volumes = get_volumes ( )
volumes = get_volumes ( )
if rebalance :
if rebalance :
rebalance( volume_name )
do_ rebalance( volume_name )
facts = { }
facts = { }
facts [ ' glusterfs ' ] = { ' peers ' : peers , ' volumes ' : volumes , ' quotas ' : quotas }
facts [ ' glusterfs ' ] = { ' peers ' : peers , ' volumes ' : volumes , ' quotas ' : quotas }