@ -49,101 +49,95 @@ options:
description :
description :
- BIG - IP username
- BIG - IP username
required : true
required : true
default : null
choices : [ ]
aliases : [ ]
password :
password :
description :
description :
- BIG - IP password
- BIG - IP password
required : true
required : true
default : null
choices : [ ]
aliases : [ ]
validate_certs :
validate_certs :
description :
description :
- If C ( no ) , SSL certificates will not be validated . This should only be used
- If C ( no ) , SSL certificates will not be validated . This should only be used
on personally controlled sites using self - signed certificates .
on personally controlled sites using self - signed certificates .
required : false
required : false
default : ' yes '
default : ' yes '
choices : [ ' yes ' , ' no ' ]
choices :
version_added : 2.0
- yes
- no
state :
state :
description :
description :
- Virtual Server state
- Virtual Server state
- Absent , delete the VS if present
- Absent , delete the VS if present
- present ( and its synonym enabled ) , create if needed the VS and set state to enabled
- C ( present ) ( and its synonym enabled ) , create if needed the VS and set
- disabled , create if needed the VS and set state to disabled
state to enabled
- C ( disabled ) , create if needed the VS and set state to disabled
required : false
required : false
default : present
default : present
choices : [ ' present ' , ' absent ' , ' enabled ' , ' disabled ' ]
choices :
- present
- absent
- enabled
- disabled
aliases : [ ]
aliases : [ ]
partition :
partition :
description :
description :
- Partition
- Partition
required : false
required : false
default : ' Common '
default : ' Common '
choices : [ ]
aliases : [ ]
name :
name :
description :
description :
- " Virtual server name. "
- Virtual server name
required : true
required : true
aliases : [ ' vs ' ]
aliases :
- vs
destination :
destination :
description :
description :
- " Destination IP of the virtual server (only host is currently supported) . Required when state=present and vs does not exist. "
- Destination IP of the virtual server ( only host is currently supported ) .
Required when state = present and vs does not exist .
required : true
required : true
default : null
aliases :
choices : [ ]
- address
aliases : [ ' address ' , ' ip ' ]
- ip
port :
port :
description :
description :
- " Port of the virtual server . Required when state=present and vs does not exist "
- Port of the virtual server . Required when state = present and vs does not exist
required : false
required : false
default : None
default : None
all_profiles :
all_profiles :
description :
description :
- " List of all Profiles (HTTP,ClientSSL,ServerSSL,etc) that must be used by the virtual server "
- List of all Profiles ( HTTP , ClientSSL , ServerSSL , etc ) that must be used
by the virtual server
required : false
required : false
default : None
default : None
all_rules :
all_rules :
version_added : " 2.2 "
version_added : " 2.2 "
description :
description :
- " List of rules to be applied in priority order "
- List of rules to be applied in priority order
required : false
required : false
default : None
default : None
pool :
pool :
description :
description :
- " Default pool for the virtual server "
- Default pool for the virtual server
required : false
required : false
default : None
default : None
snat :
snat :
description :
description :
- " Source network address policy "
- Source network address policy
required : false
required : false
default : None
default : None
default_persistence_profile :
default_persistence_profile :
description :
description :
- " Default Profile which manages the session persistence "
- Default Profile which manages the session persistence
required : false
required : false
default : None
default : None
description :
description :
description :
description :
- " Virtual server description. "
- Virtual server description
required : false
required : false
default : None
default : None
'''
'''
EXAMPLES = '''
EXAMPLES = '''
- name : Add virtual server
## playbook task examples:
bigip_virtual_server :
- - -
# file bigip-test.yml
# ...
- name : Add VS
local_action :
module : bigip_virtual_server
server : lb . mydomain . net
server : lb . mydomain . net
user : admin
user : admin
password : secret
password : secret
@ -158,10 +152,10 @@ EXAMPLES = '''
all_profiles :
all_profiles :
- http
- http
- clientssl
- clientssl
delegate_to : localhost
- name : Modify Port of the Virtual Server
- name : Modify Port of the Virtual Server
local_action :
bigip_virtual_server :
module : bigip_virtual_server
server : lb . mydomain . net
server : lb . mydomain . net
user : admin
user : admin
password : secret
password : secret
@ -169,37 +163,41 @@ EXAMPLES = '''
partition : MyPartition
partition : MyPartition
name : myvirtualserver
name : myvirtualserver
port : 8080
port : 8080
delegate_to : localhost
- name : Delete virtual server
- name : Delete virtual server
local_action :
bigip_virtual_server :
module : bigip_virtual_server
server : lb . mydomain . net
server : lb . mydomain . net
user : admin
user : admin
password : secret
password : secret
state : absent
state : absent
partition : MyPartition
partition : MyPartition
name : myvirtualserver
name : myvirtualserver
delegate_to : localhost
'''
'''
RETURN = '''
RETURN = '''
- - -
- - -
deleted :
deleted :
description : Name of a virtual server that was deleted
description : Name of a virtual server that was deleted
returned : virtual server was successfully deleted on state = absent
returned : changed
type : string
type : string
sample : " my-virtual-server "
'''
'''
# ==========================
# bigip_virtual_server module specific
#
# map of state values
# map of state values
STATES = { ' enabled ' : ' STATE_ENABLED ' ,
STATES = {
' disabled ' : ' STATE_DISABLED ' }
' enabled ' : ' STATE_ENABLED ' ,
STATUSES = { ' enabled ' : ' SESSION_STATUS_ENABLED ' ,
' disabled ' : ' STATE_DISABLED '
}
STATUSES = {
' enabled ' : ' SESSION_STATUS_ENABLED ' ,
' disabled ' : ' SESSION_STATUS_DISABLED ' ,
' disabled ' : ' SESSION_STATUS_DISABLED ' ,
' offline ' : ' SESSION_STATUS_FORCED_DISABLED ' }
' offline ' : ' SESSION_STATUS_FORCED_DISABLED '
}
def vs_exists ( api , vs ) :
def vs_exists ( api , vs ) :
# hack to determine if pool exists
# hack to determine if pool exists
@ -207,7 +205,7 @@ def vs_exists(api, vs):
try :
try :
api . LocalLB . VirtualServer . get_object_status ( virtual_servers = [ vs ] )
api . LocalLB . VirtualServer . get_object_status ( virtual_servers = [ vs ] )
result = True
result = True
except bigsuds . OperationFailed , e :
except bigsuds . OperationFailed as e :
if " was not found " in str ( e ) :
if " was not found " in str ( e ) :
result = False
result = False
else :
else :
@ -215,8 +213,9 @@ def vs_exists(api, vs):
raise
raise
return result
return result
def vs_create ( api , name , destination , port , pool ) :
_profiles = [ [ { ' profile_context ' : ' PROFILE_CONTEXT_TYPE_ALL ' , ' profile_name ' : ' tcp ' } ] ]
def vs_create ( api , name , destination , port , pool ) :
_profiles = [ [ { ' profile_context ' : ' PROFILE_CONTEXT_TYPE_ALL ' , ' profile_name ' : ' tcp ' } ] ]
created = False
created = False
# a bit of a hack to handle concurrent runs of this module.
# a bit of a hack to handle concurrent runs of this module.
# even though we've checked the vs doesn't exist,
# even though we've checked the vs doesn't exist,
@ -225,211 +224,278 @@ def vs_create(api,name,destination,port,pool):
# about it!
# about it!
try :
try :
api . LocalLB . VirtualServer . create (
api . LocalLB . VirtualServer . create (
definitions = [ { ' name ' : [ name ] , ' address ' : [ destination ] , ' port ' : port , ' protocol ' : ' PROTOCOL_TCP ' } ] ,
definitions = [ { ' name ' : [ name ] , ' address ' : [ destination ] , ' port ' : port , ' protocol ' : ' PROTOCOL_TCP ' } ] ,
wildmasks = [ ' 255.255.255.255 ' ] ,
wildmasks = [ ' 255.255.255.255 ' ] ,
resources = [ { ' type ' : ' RESOURCE_TYPE_POOL ' , ' default_pool_name ' : pool } ] ,
resources = [ { ' type ' : ' RESOURCE_TYPE_POOL ' , ' default_pool_name ' : pool } ] ,
profiles = _profiles )
profiles = _profiles )
created = True
created = True
return created
return created
except bigsuds . OperationFailed , e :
except bigsuds . OperationFailed as e :
if " already exists " not in str ( e ) :
if " already exists " not in str ( e ) :
raise Exception ( ' Error on creating Virtual Server : %s ' % e )
raise Exception ( ' Error on creating Virtual Server : %s ' % e )
def vs_remove ( api , name ) :
api . LocalLB . VirtualServer . delete_virtual_server ( virtual_servers = [ name ] )
def vs_remove ( api , name ) :
api . LocalLB . VirtualServer . delete_virtual_server (
virtual_servers = [ name ]
)
def get_rules ( api , name ) :
return api . LocalLB . VirtualServer . get_rule ( virtual_servers = [ name ] ) [ 0 ]
def get_rules ( api , name ) :
return api . LocalLB . VirtualServer . get_rule (
virtual_servers = [ name ]
) [ 0 ]
def set_rules ( api , name , rules_list ) :
updated = False
def set_rules ( api , name , rules_list ) :
updated = False
if rules_list is None :
if rules_list is None :
return False
return False
rules_list = list ( enumerate ( rules_list ) )
rules_list = list ( enumerate ( rules_list ) )
try :
try :
current_rules = map ( lambda x : ( x [ ' priority ' ] , x [ ' rule_name ' ] ) , get_rules ( api , name ) )
current_rules = map ( lambda x : ( x [ ' priority ' ] , x [ ' rule_name ' ] ) , get_rules ( api , name ) )
to_add_rules = [ ]
to_add_rules = [ ]
for i , x in rules_list :
for i , x in rules_list :
if ( i , x ) not in current_rules :
if ( i , x ) not in current_rules :
to_add_rules . append ( { ' priority ' : i , ' rule_name ' : x } )
to_add_rules . append ( { ' priority ' : i , ' rule_name ' : x } )
to_del_rules = [ ]
to_del_rules = [ ]
for i , x in current_rules :
for i , x in current_rules :
if ( i , x ) not in rules_list :
if ( i , x ) not in rules_list :
to_del_rules . append ( { ' priority ' : i , ' rule_name ' : x } )
to_del_rules . append ( { ' priority ' : i , ' rule_name ' : x } )
if len ( to_del_rules ) > 0 :
if len ( to_del_rules ) > 0 :
api . LocalLB . VirtualServer . remove_rule ( virtual_servers = [ name ] , rules = [ to_del_rules ] )
api . LocalLB . VirtualServer . remove_rule (
updated = True
virtual_servers = [ name ] ,
if len ( to_add_rules ) > 0 :
rules = [ to_del_rules ]
api . LocalLB . VirtualServer . add_rule ( virtual_servers = [ name ] , rules = [ to_add_rules ] )
)
updated = True
updated = True
if len ( to_add_rules ) > 0 :
api . LocalLB . VirtualServer . add_rule (
virtual_servers = [ name ] ,
rules = [ to_add_rules ]
)
updated = True
return updated
return updated
except bigsuds . OperationFailed , e :
except bigsuds . OperationFailed as e :
raise Exception ( ' Error on setting profiles : %s ' % e )
raise Exception ( ' Error on setting profiles : %s ' % e )
def get_profiles ( api , name ) :
return api . LocalLB . VirtualServer . get_profile ( virtual_servers = [ name ] ) [ 0 ]
def get_profiles ( api , name ) :
return api . LocalLB . VirtualServer . get_profile (
virtual_servers = [ name ]
) [ 0 ]
def set_profiles ( api , name , profiles_list ) :
def set_profiles ( api , name , profiles_list ) :
updated = False
updated = False
try :
try :
if profiles_list is None :
if profiles_list is None :
return False
return False
current_profiles = map ( lambda x : x [ ' profile_name ' ] , get_profiles ( api , name ) )
current_profiles = map ( lambda x : x [ ' profile_name ' ] , get_profiles ( api , name ) )
to_add_profiles = [ ]
to_add_profiles = [ ]
for x in profiles_list :
for x in profiles_list :
if x not in current_profiles :
if x not in current_profiles :
to_add_profiles . append ( { ' profile_context ' : ' PROFILE_CONTEXT_TYPE_ALL ' , ' profile_name ' : x } )
to_add_profiles . append ( { ' profile_context ' : ' PROFILE_CONTEXT_TYPE_ALL ' , ' profile_name ' : x } )
to_del_profiles = [ ]
to_del_profiles = [ ]
for x in current_profiles :
for x in current_profiles :
if ( x not in profiles_list ) and ( x != " /Common/tcp " ) :
if ( x not in profiles_list ) and ( x != " /Common/tcp " ) :
to_del_profiles . append ( { ' profile_context ' : ' PROFILE_CONTEXT_TYPE_ALL ' , ' profile_name ' : x } )
to_del_profiles . append ( { ' profile_context ' : ' PROFILE_CONTEXT_TYPE_ALL ' , ' profile_name ' : x } )
if len ( to_del_profiles ) > 0 :
if len ( to_del_profiles ) > 0 :
api . LocalLB . VirtualServer . remove_profile ( virtual_servers = [ name ] , profiles = [ to_del_profiles ] )
api . LocalLB . VirtualServer . remove_profile (
updated = True
virtual_servers = [ name ] ,
if len ( to_add_profiles ) > 0 :
profiles = [ to_del_profiles ]
api . LocalLB . VirtualServer . add_profile ( virtual_servers = [ name ] , profiles = [ to_add_profiles ] )
)
updated = True
updated = True
if len ( to_add_profiles ) > 0 :
api . LocalLB . VirtualServer . add_profile (
virtual_servers = [ name ] ,
profiles = [ to_add_profiles ]
)
updated = True
return updated
return updated
except bigsuds . OperationFailed , e :
except bigsuds . OperationFailed as e :
raise Exception ( ' Error on setting profiles : %s ' % e )
raise Exception ( ' Error on setting profiles : %s ' % e )
def set_snat ( api , name , snat ) :
def set_snat ( api , name , snat ) :
updated = False
updated = False
try :
try :
current_state = get_snat_type ( api , name )
current_state = get_snat_type ( api , name )
if snat is None :
if snat is None :
return updated
return updated
elif snat == ' None ' and current_state != ' SRC_TRANS_NONE ' :
elif snat == ' None ' and current_state != ' SRC_TRANS_NONE ' :
api . LocalLB . VirtualServer . set_source_address_translation_none ( virtual_servers = [ name ] )
api . LocalLB . VirtualServer . set_source_address_translation_none (
virtual_servers = [ name ]
)
updated = True
updated = True
elif snat == ' Automap ' and current_state != ' SRC_TRANS_AUTOMAP ' :
elif snat == ' Automap ' and current_state != ' SRC_TRANS_AUTOMAP ' :
api . LocalLB . VirtualServer . set_source_address_translation_automap ( virtual_servers = [ name ] )
api . LocalLB . VirtualServer . set_source_address_translation_automap (
virtual_servers = [ name ]
)
updated = True
updated = True
return updated
return updated
except bigsuds . OperationFailed , e :
except bigsuds . OperationFailed as e :
raise Exception ( ' Error on setting snat : %s ' % e )
raise Exception ( ' Error on setting snat : %s ' % e )
def get_snat_type ( api , name ) :
return api . LocalLB . VirtualServer . get_source_address_translation_type ( virtual_servers = [ name ] ) [ 0 ]
def get_snat_type ( api , name ) :
return api . LocalLB . VirtualServer . get_source_address_translation_type (
virtual_servers = [ name ]
) [ 0 ]
def get_pool ( api , name ) :
return api . LocalLB . VirtualServer . get_default_pool_name (
virtual_servers = [ name ]
) [ 0 ]
def get_pool ( api , name ) :
return api . LocalLB . VirtualServer . get_default_pool_name ( virtual_servers = [ name ] ) [ 0 ]
def set_pool ( api , name , pool ) :
def set_pool ( api , name , pool ) :
updated = False
updated = False
try :
try :
current_pool = get_pool ( api , name )
current_pool = get_pool ( api , name )
if pool is not None and ( pool != current_pool ) :
if pool is not None and ( pool != current_pool ) :
api . LocalLB . VirtualServer . set_default_pool_name ( virtual_servers = [ name ] , default_pools = [ pool ] )
api . LocalLB . VirtualServer . set_default_pool_name (
updated = True
virtual_servers = [ name ] ,
default_pools = [ pool ]
)
updated = True
return updated
return updated
except bigsuds . OperationFailed , e :
except bigsuds . OperationFailed as e :
raise Exception ( ' Error on setting pool : %s ' % e )
raise Exception ( ' Error on setting pool : %s ' % e )
def get_destination ( api , name ) :
def get_destination ( api , name ) :
return api . LocalLB . VirtualServer . get_destination_v2 ( virtual_servers = [ name ] ) [ 0 ]
return api . LocalLB . VirtualServer . get_destination_v2 (
virtual_servers = [ name ]
) [ 0 ]
def set_destination ( api , name , destination ) :
def set_destination ( api , name , destination ) :
updated = False
updated = False
try :
try :
current_destination = get_destination ( api , name )
current_destination = get_destination ( api , name )
if destination is not None and destination != current_destination [ ' address ' ] :
if destination is not None and destination != current_destination [ ' address ' ] :
api . LocalLB . VirtualServer . set_destination_v2 ( virtual_servers = [ name ] , destinations = [ { ' address ' : destination , ' port ' : current_destination [ ' port ' ] } ] )
api . LocalLB . VirtualServer . set_destination_v2 (
updated = True
virtual_servers = [ name ] ,
destinations = [ { ' address ' : destination , ' port ' : current_destination [ ' port ' ] } ]
)
updated = True
return updated
return updated
except bigsuds . OperationFailed , e :
except bigsuds . OperationFailed as e :
raise Exception ( ' Error on setting destination : %s ' % e )
raise Exception ( ' Error on setting destination : %s ' % e )
def set_port ( api , name , port ) :
def set_port ( api , name , port ) :
updated = False
updated = False
try :
try :
current_destination = get_destination ( api , name )
current_destination = get_destination ( api , name )
if port is not None and port != current_destination [ ' port ' ] :
if port is not None and port != current_destination [ ' port ' ] :
api . LocalLB . VirtualServer . set_destination_v2 ( virtual_servers = [ name ] , destinations = [ { ' address ' : current_destination [ ' address ' ] , ' port ' : port } ] )
api . LocalLB . VirtualServer . set_destination_v2 (
updated = True
virtual_servers = [ name ] ,
destinations = [ { ' address ' : current_destination [ ' address ' ] , ' port ' : port } ]
)
updated = True
return updated
return updated
except bigsuds . OperationFailed , e :
except bigsuds . OperationFailed as e :
raise Exception ( ' Error on setting port : %s ' % e )
raise Exception ( ' Error on setting port : %s ' % e )
def get_state ( api , name ) :
return api . LocalLB . VirtualServer . get_enabled_state (
virtual_servers = [ name ]
) [ 0 ]
def get_state ( api , name ) :
return api . LocalLB . VirtualServer . get_enabled_state ( virtual_servers = [ name ] ) [ 0 ]
def set_state ( api , name , state ) :
def set_state ( api , name , state ) :
updated = False
updated = False
try :
try :
current_state = get_state ( api , name )
current_state = get_state ( api , name )
# We consider that being present is equivalent to enabled
# We consider that being present is equivalent to enabled
if state == ' present ' :
if state == ' present ' :
state = ' enabled '
state = ' enabled '
if STATES [ state ] != current_state :
if STATES [ state ] != current_state :
api . LocalLB . VirtualServer . set_enabled_state ( virtual_servers = [ name ] , states = [ STATES [ state ] ] )
api . LocalLB . VirtualServer . set_enabled_state (
updated = True
virtual_servers = [ name ] ,
states = [ STATES [ state ] ]
)
updated = True
return updated
return updated
except bigsuds . OperationFailed , e :
except bigsuds . OperationFailed as e :
raise Exception ( ' Error on setting state : %s ' % e )
raise Exception ( ' Error on setting state : %s ' % e )
def get_description ( api , name ) :
return api . LocalLB . VirtualServer . get_description ( virtual_servers = [ name ] ) [ 0 ]
def set_description ( api , name , description ) :
def get_description ( api , name ) :
updated = False
return api . LocalLB . VirtualServer . get_description (
virtual_servers = [ name ]
) [ 0 ]
def set_description ( api , name , description ) :
updated = False
try :
try :
current_description = get_description ( api , name )
current_description = get_description ( api , name )
if description is not None and current_description != description :
if description is not None and current_description != description :
api . LocalLB . VirtualServer . set_description ( virtual_servers = [ name ] , descriptions = [ description ] )
api . LocalLB . VirtualServer . set_description (
updated = True
virtual_servers = [ name ] ,
descriptions = [ description ]
)
updated = True
return updated
return updated
except bigsuds . OperationFailed , e :
except bigsuds . OperationFailed as e :
raise Exception ( ' Error on setting description : %s ' % e )
raise Exception ( ' Error on setting description : %s ' % e )
def get_persistence_profiles ( api , name ) :
return api . LocalLB . VirtualServer . get_persistence_profile ( virtual_servers = [ name ] ) [ 0 ]
def set_default_persistence_profiles ( api , name , persistence_profile ) :
def get_persistence_profiles ( api , name ) :
updated = False
return api . LocalLB . VirtualServer . get_persistence_profile (
virtual_servers = [ name ]
) [ 0 ]
def set_default_persistence_profiles ( api , name , persistence_profile ) :
updated = False
if persistence_profile is None :
if persistence_profile is None :
return updated
return updated
try :
try :
current_persistence_profiles = get_persistence_profiles ( api , name )
current_persistence_profiles = get_persistence_profiles ( api , name )
default = None
default = None
for profile in current_persistence_profiles :
for profile in current_persistence_profiles :
if profile [ ' default_profile ' ] :
if profile [ ' default_profile ' ] :
default = profile [ ' profile_name ' ]
default = profile [ ' profile_name ' ]
break
break
if default is not None and default != persistence_profile :
if default is not None and default != persistence_profile :
api . LocalLB . VirtualServer . remove_persistence_profile ( virtual_servers = [ name ] , profiles = [ [ { ' profile_name ' : default , ' default_profile ' : True } ] ] )
api . LocalLB . VirtualServer . remove_persistence_profile (
virtual_servers = [ name ] ,
profiles = [ [ { ' profile_name ' : default , ' default_profile ' : True } ] ]
)
if default != persistence_profile :
if default != persistence_profile :
api . LocalLB . VirtualServer . add_persistence_profile ( virtual_servers = [ name ] , profiles = [ [ { ' profile_name ' : persistence_profile , ' default_profile ' : True } ] ] )
api . LocalLB . VirtualServer . add_persistence_profile (
updated = True
virtual_servers = [ name ] ,
profiles = [ [ { ' profile_name ' : persistence_profile , ' default_profile ' : True } ] ]
)
updated = True
return updated
return updated
except bigsuds . OperationFailed , e :
except bigsuds . OperationFailed as e :
raise Exception ( ' Error on setting default persistence profile : %s ' % e )
raise Exception ( ' Error on setting default persistence profile : %s ' % e )
def main ( ) :
def main ( ) :
argument_spec = f5_argument_spec ( )
argument_spec = f5_argument_spec ( )
argument_spec . update ( dict (
argument_spec . update ( dict (
state = dict ( type = ' str ' , default = ' present ' ,
state = dict ( type = ' str ' , default = ' present ' ,
choices = [ ' present ' , ' absent ' , ' disabled ' , ' enabled ' ] ) ,
choices = [ ' present ' , ' absent ' , ' disabled ' , ' enabled ' ] ) ,
name = dict ( type = ' str ' , required = True , aliases = [ ' vs ' ] ) ,
name = dict ( type = ' str ' , required = True , aliases = [ ' vs ' ] ) ,
destination = dict ( type = ' str ' , aliases = [ ' address ' , ' ip ' ] ) ,
destination = dict ( type = ' str ' , aliases = [ ' address ' , ' ip ' ] ) ,
port = dict ( type = ' int ' ) ,
port = dict ( type = ' int ' ) ,
all_profiles = dict ( type = ' list ' ) ,
all_profiles = dict ( type = ' list ' ) ,
all_rules = dict ( type = ' list ' ) ,
all_rules = dict ( type = ' list ' ) ,
pool = dict ( type = ' str ' ) ,
pool = dict ( type = ' str ' ) ,
description = dict ( type = ' str ' ) ,
description = dict ( type = ' str ' ) ,
snat = dict ( type = ' str ' ) ,
snat = dict ( type = ' str ' ) ,
default_persistence_profile = dict ( type = ' str ' )
default_persistence_profile = dict ( type = ' str ' )
)
) )
)
module = AnsibleModule (
module = AnsibleModule (
argument_spec = argument_spec ,
argument_spec = argument_spec ,
supports_check_mode = True
supports_check_mode = True
)
)
@ -449,15 +515,15 @@ def main():
partition = module . params [ ' partition ' ]
partition = module . params [ ' partition ' ]
validate_certs = module . params [ ' validate_certs ' ]
validate_certs = module . params [ ' validate_certs ' ]
name = fq_name ( partition , module . params [ ' name ' ] )
name = fq_name ( partition , module . params [ ' name ' ] )
destination = module . params [ ' destination ' ]
destination = module . params [ ' destination ' ]
port = module . params [ ' port ' ]
port = module . params [ ' port ' ]
all_profiles = fq_list_names ( partition , module . params [ ' all_profiles ' ] )
all_profiles = fq_list_names ( partition , module . params [ ' all_profiles ' ] )
all_rules = fq_list_names ( partition , module . params [ ' all_rules ' ] )
all_rules = fq_list_names ( partition , module . params [ ' all_rules ' ] )
pool = fq_name ( partition , module . params [ ' pool ' ] )
pool = fq_name ( partition , module . params [ ' pool ' ] )
description = module . params [ ' description ' ]
description = module . params [ ' description ' ]
snat = module . params [ ' snat ' ]
snat = module . params [ ' snat ' ]
default_persistence_profile = fq_name ( partition , module . params [ ' default_persistence_profile ' ] )
default_persistence_profile = fq_name ( partition , module . params [ ' default_persistence_profile ' ] )
if 1 > port > 65535 :
if 1 > port > 65535 :
module . fail_json ( msg = " valid ports must be in range 1 - 65535 " )
module . fail_json ( msg = " valid ports must be in range 1 - 65535 " )
@ -468,15 +534,15 @@ def main():
if state == ' absent ' :
if state == ' absent ' :
if not module . check_mode :
if not module . check_mode :
if vs_exists ( api , name ) :
if vs_exists ( api , name ) :
# hack to handle concurrent runs of module
# hack to handle concurrent runs of module
# pool might be gone before we actually remove
# pool might be gone before we actually remove
try :
try :
vs_remove ( api , name )
vs_remove ( api , name )
result = { ' changed ' : True , ' deleted ' : name }
result = { ' changed ' : True , ' deleted ' : name }
except bigsuds . OperationFailed , e :
except bigsuds . OperationFailed as e :
if " was not found " in str ( e ) :
if " was not found " in str ( e ) :
result [ ' changed ' ] = False
result [ ' changed ' ] = False
else :
else :
raise
raise
else :
else :
@ -495,15 +561,15 @@ def main():
# this catches the exception and does something smart
# this catches the exception and does something smart
# about it!
# about it!
try :
try :
vs_create ( api , name , destination , port , pool )
vs_create ( api , name , destination , port , pool )
set_profiles ( api , name , all_profiles )
set_profiles ( api , name , all_profiles )
set_rules ( api , name , all_rules )
set_rules ( api , name , all_rules )
set_snat ( api , name , snat )
set_snat ( api , name , snat )
set_description ( api , name , description )
set_description ( api , name , description )
set_default_persistence_profiles ( api , name , default_persistence_profile )
set_default_persistence_profiles ( api , name , default_persistence_profile )
set_state ( api , name , state )
set_state ( api , name , state )
result = { ' changed ' : True }
result = { ' changed ' : True }
except bigsuds . OperationFailed , e :
except bigsuds . OperationFailed as e :
raise Exception ( ' Error on creating Virtual Server : %s ' % e )
raise Exception ( ' Error on creating Virtual Server : %s ' % e )
else :
else :
# check-mode return value
# check-mode return value
@ -516,23 +582,23 @@ def main():
# Have a transaction for all the changes
# Have a transaction for all the changes
try :
try :
api . System . Session . start_transaction ( )
api . System . Session . start_transaction ( )
result [ ' changed ' ] | = set_destination ( api , name , fq_name ( partition , destination ) )
result [ ' changed ' ] | = set_destination ( api , name , fq_name ( partition , destination ) )
result [ ' changed ' ] | = set_port ( api , name , port )
result [ ' changed ' ] | = set_port ( api , name , port )
result [ ' changed ' ] | = set_pool ( api , name , pool )
result [ ' changed ' ] | = set_pool ( api , name , pool )
result [ ' changed ' ] | = set_description ( api , name , description )
result [ ' changed ' ] | = set_description ( api , name , description )
result [ ' changed ' ] | = set_snat ( api , name , snat )
result [ ' changed ' ] | = set_snat ( api , name , snat )
result [ ' changed ' ] | = set_profiles ( api , name , all_profiles )
result [ ' changed ' ] | = set_profiles ( api , name , all_profiles )
result [ ' changed ' ] | = set_rules ( api , name , all_rules )
result [ ' changed ' ] | = set_rules ( api , name , all_rules )
result [ ' changed ' ] | = set_default_persistence_profiles ( api , name , default_persistence_profile )
result [ ' changed ' ] | = set_default_persistence_profiles ( api , name , default_persistence_profile )
result [ ' changed ' ] | = set_state ( api , name , state )
result [ ' changed ' ] | = set_state ( api , name , state )
api . System . Session . submit_transaction ( )
api . System . Session . submit_transaction ( )
except Exception , e :
except Exception as e :
raise Exception ( " Error on updating Virtual Server : %s " % e )
raise Exception ( " Error on updating Virtual Server : %s " % e )
else :
else :
# check-mode return value
# check-mode return value
result = { ' changed ' : True }
result = { ' changed ' : True }
except Exception , e :
except Exception as e :
module . fail_json ( msg = " received exception: %s " % e )
module . fail_json ( msg = " received exception: %s " % e )
module . exit_json ( * * result )
module . exit_json ( * * result )