Skip to content

Commit 5c5af77

Browse files
Merge branch 'main' of github.com:netscaler/ansible-collection-netscaleradc into bgp
2 parents a48c004 + 1442475 commit 5c5af77

File tree

6 files changed

+11
-88
lines changed

6 files changed

+11
-88
lines changed

plugins/module_utils/client.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ def __init__(self, module, resource_name):
4141
self._module.params.get("nitro_user"),
4242
self._module.params.get("nitro_pass"),
4343
)
44-
4544
# Prioritize token over user/pass
4645
if have_token:
4746
self._headers["Cookie"] = (

plugins/module_utils/module_executor.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,16 @@ def __init__(self, resource_name, supports_check_mode=True):
9191
argument_spec=argument_spec,
9292
supports_check_mode=supports_check_mode,
9393
mutually_exclusive=[
94+
(
95+
"nitro_pass", "nitro_auth_token"
96+
),
9497
(
9598
"managed_netscaler_instance_name",
9699
"managed_netscaler_instance_ip",
97100
"managed_netscaler_instance_id",
98101
),
99102
],
100103
required_together=[
101-
("nitro_user", "nitro_pass"),
102104
(
103105
"managed_netscaler_instance_username",
104106
"managed_netscaler_instance_password",
@@ -144,7 +146,7 @@ def __init__(self, resource_name, supports_check_mode=True):
144146
"logout",
145147
}:
146148
self.module.params["api_path"] = "nitro/v2/config"
147-
149+
self.have_token = self.module.params.get("nitro_auth_token", None)
148150
self.client = NitroAPIClient(self.module, self.resource_name)
149151
have_userpass = all([
150152
self.module.params.get("nitro_user"),
@@ -220,7 +222,7 @@ def return_success(self):
220222
# }
221223
if self.resource_name == "login":
222224
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:
224226
ok, response = adc_logout(self.client)
225227
if not ok:
226228
log("ERROR: Logout failed: %s" % response)
@@ -250,7 +252,7 @@ def update_diff_list(self, existing=None, desired=None, delete=False, **kwargs):
250252

251253
@trace
252254
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:
254256
ok, response = adc_logout(self.client)
255257
if not ok:
256258
log("ERROR: Logout failed: %s" % response)
@@ -1019,11 +1021,16 @@ def act_on_resource(self, action):
10191021
action=action,
10201022
)
10211023
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
10221027
if (
10231028
"status_code" in err
10241029
and err["status_code"] == HTTP_RESOURCE_ALREADY_EXISTS
10251030
):
10261031
self.module_result["changed"] = False
1032+
if action == "rename":
1033+
self.return_failure(err)
10271034
else:
10281035
self.return_failure(err)
10291036

tests/integration/targets/gslbservice/tasks/main.yaml

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -113,27 +113,6 @@
113113
that:
114114
- "result.failed==false"
115115
- "result.changed==true"
116-
- name: GSLBSERVICE | RENAME | idempotent
117-
delegate_to: localhost
118-
register: result
119-
check_mode: false
120-
tags: test
121-
netscaler.adc.gslbservice:
122-
state: renamed
123-
nsip: "{{ nsip }}"
124-
nitro_user: "{{ nitro_user }}"
125-
nitro_pass: "{{ nitro_pass }}"
126-
nitro_protocol: "{{ nitro_protocol }}"
127-
validate_certs: "{{ validate_certs }}"
128-
save_config: "{{ save_config }}"
129-
servicename: test-gslb-service
130-
newname: test-gslb-service-renamed
131-
- name: Assert | GSLBSERVICE | RENAME | idempotent
132-
tags: test
133-
ansible.builtin.assert:
134-
that:
135-
- "result.failed==false"
136-
- "result.changed==false"
137116
- name: GSLBSERVICE | DELETE | --check
138117
delegate_to: localhost
139118
register: result

tests/integration/targets/lbvserver/tasks/main.yaml

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -381,27 +381,6 @@
381381
that:
382382
- "result.failed==false"
383383
- "result.changed==true"
384-
- name: LBVSERVER | RENAME | idempotent
385-
delegate_to: localhost
386-
register: result
387-
check_mode: false
388-
tags: test
389-
netscaler.adc.lbvserver:
390-
nsip: "{{ nsip }}"
391-
nitro_user: "{{ nitro_user }}"
392-
nitro_pass: "{{ nitro_pass }}"
393-
nitro_protocol: "{{ nitro_protocol }}"
394-
validate_certs: "{{ validate_certs }}"
395-
save_config: "{{ save_config }}"
396-
state: renamed
397-
name: lb1
398-
newname: lb2
399-
- name: Assert | LBVSERVER | RENAME | idempotent
400-
tags: test
401-
ansible.builtin.assert:
402-
that:
403-
- "result.failed==false"
404-
- "result.changed==false"
405384
- name: LBVSERVER | DELETE | --check
406385
delegate_to: localhost
407386
register: result

tests/integration/targets/service/tasks/main.yaml

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -108,27 +108,6 @@
108108
that:
109109
- "result.failed==false"
110110
- "result.changed==true"
111-
- name: SERVICE | RENAME | idempotent
112-
delegate_to: localhost
113-
register: result
114-
check_mode: false
115-
tags: test
116-
netscaler.adc.service:
117-
nsip: "{{ nsip }}"
118-
nitro_user: "{{ nitro_user }}"
119-
nitro_pass: "{{ nitro_pass }}"
120-
nitro_protocol: "{{ nitro_protocol }}"
121-
validate_certs: "{{ validate_certs }}"
122-
save_config: "{{ save_config }}"
123-
state: renamed
124-
name: test-service
125-
newname: test-service-renamed
126-
- name: Assert | SERVICE | RENAME | idempotent
127-
tags: test
128-
ansible.builtin.assert:
129-
that:
130-
- "result.failed==false"
131-
- "result.changed==false"
132111
- name: SERVICE | DELETE | --check
133112
delegate_to: localhost
134113
register: result

tests/integration/targets/servicegroup/tasks/main.yaml

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -334,26 +334,6 @@
334334
that:
335335
- "result.failed==false"
336336
- "result.changed==true"
337-
- name: SERVICEGROUP | RENAME | idempotent
338-
delegate_to: localhost
339-
register: result
340-
check_mode: false
341-
tags: test
342-
netscaler.adc.servicegroup:
343-
nsip: "{{ nsip }}"
344-
nitro_user: "{{ nitro_user }}"
345-
nitro_pass: "{{ nitro_pass }}"
346-
nitro_protocol: "{{ nitro_protocol }}"
347-
validate_certs: "{{ validate_certs }}"
348-
state: renamed
349-
servicegroupname: "{{ servicegroup_name }}_renamed"
350-
newname: "{{ servicegroup_name }}_renamed"
351-
- name: Assert | SERVICEGROUP | RENAME | idempotent
352-
tags: test
353-
ansible.builtin.assert:
354-
that:
355-
- "result.failed==false"
356-
- "result.changed==false"
357337
- name: SERVICEGROUP | DELETE | --check
358338
delegate_to: localhost
359339
register: result

0 commit comments

Comments
 (0)