@@ -90,14 +90,16 @@ def __init__(self, resource_name, supports_check_mode=True):
9090 argument_spec = argument_spec ,
9191 supports_check_mode = supports_check_mode ,
9292 mutually_exclusive = [
93+ (
94+ "nitro_pass" , "nitro_auth_token"
95+ ),
9396 (
9497 "managed_netscaler_instance_name" ,
9598 "managed_netscaler_instance_ip" ,
9699 "managed_netscaler_instance_id" ,
97100 ),
98101 ],
99102 required_together = [
100- ("nitro_user" , "nitro_pass" ),
101103 (
102104 "managed_netscaler_instance_username" ,
103105 "managed_netscaler_instance_password" ,
@@ -143,7 +145,7 @@ def __init__(self, resource_name, supports_check_mode=True):
143145 "logout" ,
144146 }:
145147 self .module .params ["api_path" ] = "nitro/v2/config"
146-
148+ self . have_token = self . module . params . get ( "nitro_auth_token" , None )
147149 self .client = NitroAPIClient (self .module , self .resource_name )
148150 have_userpass = all ([
149151 self .module .params .get ("nitro_user" ),
@@ -219,7 +221,7 @@ def return_success(self):
219221 # }
220222 if self .resource_name == "login" :
221223 self .module_result ["sessionid" ] = self .sessionid
222- if self .client ._headers .get ("Cookie" , None ) not in (None , "" ) and not self .module .check_mode :
224+ if self .client ._headers .get ("Cookie" , None ) not in (None , "" ) and not self .module .check_mode and not self . have_token :
223225 ok , response = adc_logout (self .client )
224226 if not ok :
225227 log ("ERROR: Logout failed: %s" % response )
@@ -249,7 +251,7 @@ def update_diff_list(self, existing=None, desired=None, delete=False, **kwargs):
249251
250252 @trace
251253 def return_failure (self , msg ):
252- if self .client ._headers [ "Cookie" ] != "" and not self .module .check_mode :
254+ if self .client ._headers . get ( "Cookie" , None ) not in ( None , "" ) and not self .module .check_mode and not self . have_token :
253255 ok , response = adc_logout (self .client )
254256 if not ok :
255257 log ("ERROR: Logout failed: %s" % response )
0 commit comments