@ -67,7 +67,7 @@ options:
- Pool member state
- Pool member state
required : true
required : true
default : present
default : present
choices : [ ' present ' , ' absent ' ]
choices : [ ' present ' , ' absent ' , ' enabled ' , ' disabled ' ]
aliases : [ ]
aliases : [ ]
partition :
partition :
description :
description :
@ -78,7 +78,7 @@ options:
aliases : [ ]
aliases : [ ]
name :
name :
description :
description :
- " Node name "
- " Node name . Required when state=enabled/disabled "
required : false
required : false
default : null
default : null
choices : [ ]
choices : [ ]
@ -145,6 +145,11 @@ EXAMPLES = '''
partition = matthite
partition = matthite
name = " {{ ansible_default_ipv4[ " address " ] }} "
name = " {{ ansible_default_ipv4[ " address " ] }} "
- name : Disable node
bigip_node : server = lb . mydomain . com user = admin password = mysecret
state = disabled name = mynodename
delegate_to : localhost
'''
'''
try :
try :
@ -158,6 +163,13 @@ else:
# bigip_node module specific
# bigip_node module specific
#
#
# map of state values
STATES = { ' enabled ' : ' STATE_ENABLED ' ,
' disabled ' : ' STATE_DISABLED ' }
STATUSES = { ' enabled ' : ' SESSION_STATUS_ENABLED ' ,
' disabled ' : ' SESSION_STATUS_DISABLED ' ,
' offline ' : ' SESSION_STATUS_FORCED_DISABLED ' }
def bigip_api ( bigip , user , password ) :
def bigip_api ( bigip , user , password ) :
api = bigsuds . BIGIP ( hostname = bigip , username = user , password = password )
api = bigsuds . BIGIP ( hostname = bigip , username = user , password = password )
return api
return api
@ -220,6 +232,25 @@ def set_node_description(api, name, description):
def get_node_description ( api , name ) :
def get_node_description ( api , name ) :
return api . LocalLB . NodeAddressV2 . get_description ( nodes = [ name ] ) [ 0 ]
return api . LocalLB . NodeAddressV2 . get_description ( nodes = [ name ] ) [ 0 ]
def set_node_disabled ( api , name ) :
set_node_session_enabled_state ( api , name , STATES [ ' disabled ' ] )
result = True
desc = " "
return ( result , desc )
def set_node_enabled ( api , name ) :
set_node_session_enabled_state ( api , name , STATES [ ' enabled ' ] )
result = True
desc = " "
return ( result , desc )
def set_node_session_enabled_state ( api , name , state ) :
api . LocalLB . NodeAddressV2 . set_session_enabled_state ( nodes = [ name ] ,
states = [ state ] )
def get_node_session_status ( api , name ) :
return api . LocalLB . NodeAddressV2 . get_session_status ( nodes = [ name ] ) [ 0 ]
def main ( ) :
def main ( ) :
module = AnsibleModule (
module = AnsibleModule (
argument_spec = dict (
argument_spec = dict (
@ -227,7 +258,8 @@ def main():
user = dict ( type = ' str ' , required = True ) ,
user = dict ( type = ' str ' , required = True ) ,
password = dict ( type = ' str ' , required = True ) ,
password = dict ( type = ' str ' , required = True ) ,
validate_certs = dict ( default = ' yes ' , type = ' bool ' ) ,
validate_certs = dict ( default = ' yes ' , type = ' bool ' ) ,
state = dict ( type = ' str ' , default = ' present ' , choices = [ ' present ' , ' absent ' ] ) ,
state = dict ( type = ' str ' , default = ' present ' ,
choices = [ ' present ' , ' absent ' , ' disabled ' , ' enabled ' ] ) ,
partition = dict ( type = ' str ' , default = ' Common ' ) ,
partition = dict ( type = ' str ' , default = ' Common ' ) ,
name = dict ( type = ' str ' , required = True ) ,
name = dict ( type = ' str ' , required = True ) ,
host = dict ( type = ' str ' , aliases = [ ' address ' , ' ip ' ] ) ,
host = dict ( type = ' str ' , aliases = [ ' address ' , ' ip ' ] ) ,
@ -302,6 +334,32 @@ def main():
set_node_description ( api , address , description )
set_node_description ( api , address , description )
result = { ' changed ' : True }
result = { ' changed ' : True }
elif state in ( ' disabled ' , ' enabled ' ) :
if name is None :
module . fail_json ( msg = " name parameter required when " \
" state=enabled/disabled " )
if not module . check_mode :
if not node_exists ( api , name ) :
module . fail_json ( msg = " node does not exist " )
status = get_node_session_status ( api , name )
if state == ' disabled ' :
if status not in ( STATUSES [ ' disabled ' ] , STATUSES [ ' offline ' ] ) :
disabled , desc = set_node_disabled ( api , name )
if not disabled :
module . fail_json ( msg = " unable to disable: %s " % desc )
else :
result = { ' changed ' : True }
else :
if status != STATUSES [ ' enabled ' ] :
enabled , desc = set_node_enabled ( api , name )
if not enabled :
module . fail_json ( msg = " unable to enable: %s " % desc )
else :
result = { ' changed ' : True }
else :
# check-mode return value
result = { ' changed ' : True }
except Exception , e :
except Exception , e :
module . fail_json ( msg = " received exception: %s " % e )
module . fail_json ( msg = " received exception: %s " % e )