diff --git a/plugins/module_utils/module_executor.py b/plugins/module_utils/module_executor.py index 7c8e7a8ca..5a6e047d4 100644 --- a/plugins/module_utils/module_executor.py +++ b/plugins/module_utils/module_executor.py @@ -409,16 +409,27 @@ def create_or_update(self): ) else: self.module_result["changed"] = True - log( - "INFO: Resource %s:%s exists. Will be UPDATED." - % ( - self.resource_name, - self.resource_id, + if self.resource_name.endswith("_binding"): + # Generally bindings are not updated. They are removed and added again. + log( + "INFO: Resource %s:%s exists and is different. Will be REMOVED and ADDED." + % (self.resource_name, self.resource_id) + ) + self.delete() + ok, err = create_resource( + self.client, self.resource_name, self.resource_module_params + ) + else: + log( + "INFO: Resource %s:%s exists. Will be UPDATED." + % ( + self.resource_name, + self.resource_id, + ) + ) + ok, err = update_resource( + self.client, self.resource_name, self.resource_module_params ) - ) - ok, err = update_resource( - self.client, self.resource_name, self.resource_module_params - ) if not ok: self.return_failure(err) diff --git a/plugins/modules/lbvserver_servicegroup_binding.py b/plugins/modules/lbvserver_servicegroup_binding.py index 78ed8b8ea..a253768dd 100644 --- a/plugins/modules/lbvserver_servicegroup_binding.py +++ b/plugins/modules/lbvserver_servicegroup_binding.py @@ -72,6 +72,22 @@ """ EXAMPLES = r""" +- name: Create a lb + delegate_to: localhost + netscaler.adc.lbvserver: + name: test_lb + servicetype: SSL +- name: Create a servicegroup + delegate_to: localhost + netscaler.adc.servicegroup: + servicegroupname: test_sg + servicetype: SSL +- name: Create a servicegroup + delegate_to: localhost + netscaler.adc.lbvserver_servicegroup_binding: + weight: 1 + name: test_lb + servicename: test_sg """ RETURN = r""" diff --git a/tests/integration/targets/lbvserver_servicegroup_binding/aliases b/tests/integration/targets/lbvserver_servicegroup_binding/aliases new file mode 100644 index 000000000..28a231e46 --- /dev/null +++ b/tests/integration/targets/lbvserver_servicegroup_binding/aliases @@ -0,0 +1,3 @@ +gather_facts/no +netscaler/cpx/ +netscaler/vpx/ diff --git a/tests/integration/targets/lbvserver_servicegroup_binding/tasks/main.yaml b/tests/integration/targets/lbvserver_servicegroup_binding/tasks/main.yaml new file mode 100644 index 000000000..3a7e81156 --- /dev/null +++ b/tests/integration/targets/lbvserver_servicegroup_binding/tasks/main.yaml @@ -0,0 +1,135 @@ +--- +- name: Include prerequisite tasks + ansible.builtin.include_tasks: setup.yaml +- name: LBVSERVER_SERVICEGROUP_BINDING | ADD | --check + delegate_to: localhost + register: result + check_mode: true + tags: test + netscaler.adc.lbvserver_servicegroup_binding: + nsip: "{{ nsip }}" + nitro_user: "{{ nitro_user }}" + nitro_pass: "{{ nitro_pass }}" + nitro_protocol: "{{ nitro_protocol }}" + validate_certs: "{{ validate_certs }}" + save_config: "{{ save_config }}" + state: present + weight: 1 + name: "{{ lb_name }}" + servicename: "{{ servicegroup_name }}" +- name: Assert | LBVSERVER_SERVICEGROUP_BINDING | ADD | --check + tags: test + ansible.builtin.assert: + that: + - "result.failed==false" + - "result.changed==true" +- name: LBVSERVER_SERVICEGROUP_BINDING | ADD + delegate_to: localhost + register: result + check_mode: false + tags: test + netscaler.adc.lbvserver_servicegroup_binding: + nsip: "{{ nsip }}" + nitro_user: "{{ nitro_user }}" + nitro_pass: "{{ nitro_pass }}" + nitro_protocol: "{{ nitro_protocol }}" + validate_certs: "{{ validate_certs }}" + save_config: "{{ save_config }}" + state: present + weight: 1 + name: "{{ lb_name }}" + servicename: "{{ servicegroup_name }}" +- name: Assert | LBVSERVER_SERVICEGROUP_BINDING | ADD + ansible.builtin.assert: + that: + - "result.failed==false" + - "result.changed==true" +- name: LBVSERVER_SERVICEGROUP_BINDING | ADD | idempotent + delegate_to: localhost + register: result + check_mode: false + tags: test + netscaler.adc.lbvserver_servicegroup_binding: + nsip: "{{ nsip }}" + nitro_user: "{{ nitro_user }}" + nitro_pass: "{{ nitro_pass }}" + nitro_protocol: "{{ nitro_protocol }}" + validate_certs: "{{ validate_certs }}" + save_config: "{{ save_config }}" + state: present + weight: 1 + name: "{{ lb_name }}" + servicename: "{{ servicegroup_name }}" +- name: Assert | LBVSERVER_SERVICEGROUP_BINDING | ADD | idempotent + tags: test + ansible.builtin.assert: + that: + - "result.failed==false" + - "result.changed==true" +- name: LBVSERVER_SERVICEGROUP_BINDING | DELETE | --check + delegate_to: localhost + register: result + check_mode: true + tags: test + netscaler.adc.lbvserver_servicegroup_binding: + nsip: "{{ nsip }}" + nitro_user: "{{ nitro_user }}" + nitro_pass: "{{ nitro_pass }}" + nitro_protocol: "{{ nitro_protocol }}" + validate_certs: "{{ validate_certs }}" + save_config: "{{ save_config }}" + state: absent + weight: 1 + name: "{{ lb_name }}" + servicename: "{{ servicegroup_name }}" +- name: Assert | LBVSERVER_SERVICEGROUP_BINDING | DELETE | --check + tags: test + ansible.builtin.assert: + that: + - "result.failed==false" + - "result.changed==true" +- name: LBVSERVER_SERVICEGROUP_BINDING | DELETE + delegate_to: localhost + register: result + check_mode: false + tags: test + netscaler.adc.lbvserver_servicegroup_binding: + nsip: "{{ nsip }}" + nitro_user: "{{ nitro_user }}" + nitro_pass: "{{ nitro_pass }}" + nitro_protocol: "{{ nitro_protocol }}" + validate_certs: "{{ validate_certs }}" + save_config: "{{ save_config }}" + state: absent + weight: 1 + name: "{{ lb_name }}" + servicename: "{{ servicegroup_name }}" +- name: Assert | LBVSERVER_SERVICEGROUP_BINDING | DELETE + ansible.builtin.assert: + that: + - "result.failed==false" + - "result.changed==true" +- name: LBVSERVER_SERVICEGROUP_BINDING | DELETE | idempotent + delegate_to: localhost + register: result + check_mode: false + tags: test + netscaler.adc.lbvserver_servicegroup_binding: + nsip: "{{ nsip }}" + nitro_user: "{{ nitro_user }}" + nitro_pass: "{{ nitro_pass }}" + nitro_protocol: "{{ nitro_protocol }}" + validate_certs: "{{ validate_certs }}" + save_config: "{{ save_config }}" + state: absent + weight: 1 + name: "{{ lb_name }}" + servicename: "{{ servicegroup_name }}" +- name: Assert | LBVSERVER_SERVICEGROUP_BINDING | DELETE | idempotent + tags: test + ansible.builtin.assert: + that: + - "result.failed==false" + - "result.changed==false" +- name: Include prerequisite tasks + ansible.builtin.include_tasks: teardown.yaml diff --git a/tests/integration/targets/lbvserver_servicegroup_binding/tasks/setup.yaml b/tests/integration/targets/lbvserver_servicegroup_binding/tasks/setup.yaml new file mode 100644 index 000000000..37d2db0da --- /dev/null +++ b/tests/integration/targets/lbvserver_servicegroup_binding/tasks/setup.yaml @@ -0,0 +1,25 @@ +--- +- name: Create a lb + delegate_to: localhost + netscaler.adc.lbvserver: + nsip: "{{ nsip }}" + nitro_user: "{{ nitro_user }}" + nitro_pass: "{{ nitro_pass }}" + nitro_protocol: "{{ nitro_protocol }}" + validate_certs: "{{ validate_certs }}" + save_config: "{{ save_config }}" + state: present + name: "{{ lb_name }}" + servicetype: SSL +- name: Create a servicegroup + delegate_to: localhost + netscaler.adc.servicegroup: + nsip: "{{ nsip }}" + nitro_user: "{{ nitro_user }}" + nitro_pass: "{{ nitro_pass }}" + nitro_protocol: "{{ nitro_protocol }}" + validate_certs: "{{ validate_certs }}" + save_config: "{{ save_config }}" + state: present + servicegroupname: "{{ servicegroup_name }}" + servicetype: SSL diff --git a/tests/integration/targets/lbvserver_servicegroup_binding/tasks/teardown.yaml b/tests/integration/targets/lbvserver_servicegroup_binding/tasks/teardown.yaml new file mode 100644 index 000000000..a71473879 --- /dev/null +++ b/tests/integration/targets/lbvserver_servicegroup_binding/tasks/teardown.yaml @@ -0,0 +1,25 @@ +--- +- name: Create a servicegroup + delegate_to: localhost + netscaler.adc.servicegroup: + nsip: "{{ nsip }}" + nitro_user: "{{ nitro_user }}" + nitro_pass: "{{ nitro_pass }}" + nitro_protocol: "{{ nitro_protocol }}" + validate_certs: "{{ validate_certs }}" + save_config: "{{ save_config }}" + state: absent + servicegroupname: "{{ servicegroup_name }}" + servicetype: SSL +- name: Create a lb + delegate_to: localhost + netscaler.adc.lbvserver: + nsip: "{{ nsip }}" + nitro_user: "{{ nitro_user }}" + nitro_pass: "{{ nitro_pass }}" + nitro_protocol: "{{ nitro_protocol }}" + validate_certs: "{{ validate_certs }}" + save_config: "{{ save_config }}" + state: absent + name: "{{ lb_name }}" + servicetype: SSL diff --git a/tests/integration/targets/lbvserver_servicegroup_binding/vars/main.yaml b/tests/integration/targets/lbvserver_servicegroup_binding/vars/main.yaml new file mode 100644 index 000000000..247d17426 --- /dev/null +++ b/tests/integration/targets/lbvserver_servicegroup_binding/vars/main.yaml @@ -0,0 +1,3 @@ +--- +lb_name: test_lb +servicegroup_name: test_sg