@@ -91,14 +91,16 @@ def __init__(self, resource_name, supports_check_mode=True):
91
91
argument_spec = argument_spec ,
92
92
supports_check_mode = supports_check_mode ,
93
93
mutually_exclusive = [
94
+ (
95
+ "nitro_pass" , "nitro_auth_token"
96
+ ),
94
97
(
95
98
"managed_netscaler_instance_name" ,
96
99
"managed_netscaler_instance_ip" ,
97
100
"managed_netscaler_instance_id" ,
98
101
),
99
102
],
100
103
required_together = [
101
- ("nitro_user" , "nitro_pass" ),
102
104
(
103
105
"managed_netscaler_instance_username" ,
104
106
"managed_netscaler_instance_password" ,
@@ -144,7 +146,7 @@ def __init__(self, resource_name, supports_check_mode=True):
144
146
"logout" ,
145
147
}:
146
148
self .module .params ["api_path" ] = "nitro/v2/config"
147
-
149
+ self . have_token = self . module . params . get ( "nitro_auth_token" , None )
148
150
self .client = NitroAPIClient (self .module , self .resource_name )
149
151
have_userpass = all ([
150
152
self .module .params .get ("nitro_user" ),
@@ -220,7 +222,7 @@ def return_success(self):
220
222
# }
221
223
if self .resource_name == "login" :
222
224
self .module_result ["sessionid" ] = self .sessionid
223
- if self .client ._headers .get ("Cookie" , None ) not in (None , "" ) and not self .module .check_mode :
225
+ if self .client ._headers .get ("Cookie" , None ) not in (None , "" ) and not self .module .check_mode and not self . have_token :
224
226
ok , response = adc_logout (self .client )
225
227
if not ok :
226
228
log ("ERROR: Logout failed: %s" % response )
@@ -250,7 +252,7 @@ def update_diff_list(self, existing=None, desired=None, delete=False, **kwargs):
250
252
251
253
@trace
252
254
def return_failure (self , msg ):
253
- if self .client ._headers [ "Cookie" ] != "" and not self .module .check_mode :
255
+ if self .client ._headers . get ( "Cookie" , None ) not in ( None , "" ) and not self .module .check_mode and not self . have_token :
254
256
ok , response = adc_logout (self .client )
255
257
if not ok :
256
258
log ("ERROR: Logout failed: %s" % response )
@@ -1019,11 +1021,16 @@ def act_on_resource(self, action):
1019
1021
action = action ,
1020
1022
)
1021
1023
if ok :
1024
+ # For rename operations, always treat HTTP_RESOURCE_ALREADY_EXISTS as failure
1025
+ # This prevents false positives where we think a rename succeeded when it actually
1026
+ # failed due to a name conflict with a different existing resource
1022
1027
if (
1023
1028
"status_code" in err
1024
1029
and err ["status_code" ] == HTTP_RESOURCE_ALREADY_EXISTS
1025
1030
):
1026
1031
self .module_result ["changed" ] = False
1032
+ if action == "rename" :
1033
+ self .return_failure (err )
1027
1034
else :
1028
1035
self .return_failure (err )
1029
1036
0 commit comments