diff options
Diffstat (limited to 'ansible_collections/community/zabbix/tests')
81 files changed, 12074 insertions, 0 deletions
diff --git a/ansible_collections/community/zabbix/tests/integration/targets/setup_zabbix/defaults/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/setup_zabbix/defaults/main.yml new file mode 100644 index 000000000..813b5c684 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/setup_zabbix/defaults/main.yml @@ -0,0 +1,4 @@ +--- +zabbix_api_server_url: http://127.0.0.1:8080 +zabbix_api_login_user: Admin +zabbix_api_login_pass: zabbix diff --git a/ansible_collections/community/zabbix/tests/integration/targets/setup_zabbix/tasks/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/setup_zabbix/tasks/main.yml new file mode 100644 index 000000000..ba4c30311 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/setup_zabbix/tasks/main.yml @@ -0,0 +1,74 @@ +--- +- name: get zabbix version + uri: + url: "{{ zabbix_api_server_url }}/api_jsonrpc.php" + method: POST + body: + jsonrpc: "2.0" + method: "apiinfo.version" + params: [] + id: "1" + body_format: json + status_code: 200 + retries: 60 + delay: 5 + until: zabbix_version_result is defined and 'json' in zabbix_version_result and 'result' in zabbix_version_result.json + register: zabbix_version_result + +- name: set zabbix_version variable + set_fact: + zabbix_version: >- + {{ [0,1] + | map('extract', zabbix_version_result.json.result.split('.')) + | list + | join('.') + }} + ansible_network_os: community.zabbix.zabbix + ansible_connection: httpapi + # ansible_zabbix_auth_key: 8ec0d52432c15c91fcafe9888500cf9a607f44091ab554dbee860f6b44fac895 + ansible_host: 127.0.0.1 + ansible_zabbix_url_path: '' + ansible_httpapi_port: 8080 + ansible_httpapi_use_ssl: false + ansible_httpapi_validate_certs: false + ansible_user: Admin + ansible_httpapi_pass: zabbix + +- debug: var=zabbix_version +- name: check login to zabbix for Zabbix < 6.4 + uri: + url: "{{ zabbix_api_server_url }}/api_jsonrpc.php" + method: POST + body: + jsonrpc: "2.0" + method: "user.login" + params: + user: "{{ zabbix_api_login_user }}" + password: "{{ zabbix_api_login_pass }}" + id: "1" + body_format: json + status_code: 200 + retries: 60 + delay: 5 + until: check_login_result is defined and 'json' in check_login_result and 'result' in check_login_result.json + register: check_login_result + when: zabbix_version is version('6.4', '<') + +- name: check login to zabbix for Zabbix >= 6.4 + uri: + url: "{{ zabbix_api_server_url }}/api_jsonrpc.php" + method: POST + body: + jsonrpc: "2.0" + method: "user.login" + params: + username: "{{ zabbix_api_login_user }}" + password: "{{ zabbix_api_login_pass }}" + id: "1" + body_format: json + status_code: 200 + retries: 60 + delay: 5 + until: check_login_result is defined and 'json' in check_login_result and 'result' in check_login_result.json + register: check_login_result + when: zabbix_version is version('6.4', '>=') diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_action/meta/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_action/meta/main.yml new file mode 100644 index 000000000..acdb704c8 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_action/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - setup_zabbix diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_action/tasks/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_action/tasks/main.yml new file mode 100644 index 000000000..6893dfd56 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_action/tasks/main.yml @@ -0,0 +1,1393 @@ +--- +- name: test - do not run tests for Zabbix 3.0 + meta: end_play + when: zabbix_version is version('3.0', '=') + +- name: test - prepare example template for zabbix_action module + zabbix_template: + server_url: "{{ zabbix_api_server_url }} " + login_user: "{{ zabbix_api_login_user }}" + login_password: "{{ zabbix_api_login_pass }}" + template_name: ExampleTemplateForActionModule + template_groups: + - Templates + state: present + register: zbxaction_prep_template + +- name: test - prepare example mediatype for zabbix_action module + zabbix_mediatype: + server_url: "{{ zabbix_api_server_url }} " + login_user: "{{ zabbix_api_login_user }}" + login_password: "{{ zabbix_api_login_pass }}" + name: ExampleMediaTypeForActionModule + smtp_email: zabbix@example.com + type: email + state: present + register: zbxaction_prep_mediatype + +- name: test - simple actions + module_defaults: + community.zabbix.zabbix_action: + state: present + status: enabled + name: ExampleTriggerAction + event_source: trigger + esc_period: 60 + conditions: + - type: trigger_severity + operator: '>=' + value: Information + operations: + - type: send_message + subject: ExampleSubject + message: ExampleMessage + media_type: ExampleMediaTypeForActionModule + send_to_users: + - Admin + + block: + - name: test - create new action + zabbix_action: + register: zbxaction_new + + - assert: + that: zbxaction_new.changed is sameas True + + - name: test - create new action (again) + zabbix_action: + register: zbxaction_new + + - assert: + that: zbxaction_new.changed is sameas False + + - when: zabbix_version is version('3.4', '>=') + block: + - name: test - update action with esc_period as string + zabbix_action: + esc_period: 2m + register: zbxaction_escperiod_str + + - assert: + that: zbxaction_escperiod_str.changed is sameas True + + - name: test - update action with esc_period as string (again) + zabbix_action: + esc_period: 2m + register: zbxaction_escperiod_str + + - assert: + that: zbxaction_escperiod_str.changed is sameas False + + - name: test - update action with esc_period as macro + zabbix_action: + esc_period: '{$MYMACRO}' + register: zbxaction_escperiod_macro + + - assert: + that: zbxaction_escperiod_macro.changed is sameas True + + - name: test - update action with esc_period as macro (again) + zabbix_action: + esc_period: '{$MYMACRO}' + register: zbxaction_escperiod_macro + + - assert: + that: zbxaction_escperiod_macro.changed is sameas False + + - name: test - update action with esc_period + zabbix_action: + esc_period: 120 + register: zbxaction_escperiod + + - assert: + that: zbxaction_escperiod.changed is sameas True + + - name: test - update action with esc_period (again) + zabbix_action: + esc_period: 120 + register: zbxaction_escperiod + + - assert: + that: zbxaction_escperiod.changed is sameas False + + - name: test - update action with pause_in_maintenance + zabbix_action: + esc_period: 120 + pause_in_maintenance: false + register: zbxaction_maintpause + + - assert: + that: zbxaction_maintpause.changed is sameas True + + - name: test - update action with pause_in_maintenance (again) + zabbix_action: + esc_period: 120 + pause_in_maintenance: false + register: zbxaction_maintpause + + - assert: + that: zbxaction_maintpause.changed is sameas False + + - name: test - reset action to default + zabbix_action: + register: zbxaction_reset + + - assert: + that: zbxaction_reset.changed is sameas True + + - when: zabbix_version is version('5.0', '<') + block: + - name: test - update action with default_subject and default_message + zabbix_action: + default_subject: Example default subject + default_message: Example default message + register: zbxaction_def_msgsubj + + - assert: + that: zbxaction_def_msgsubj.changed is sameas True + + - name: test - update action with default_subject and default_message (again) + zabbix_action: + default_subject: Example default subject + default_message: Example default message + register: zbxaction_def_msgsubj + + - assert: + that: zbxaction_def_msgsubj.changed is sameas False + + - when: + - zabbix_version is version('3.2', '>=') + - zabbix_version is version('5.0', '<') + block: + - name: test - update action with recovery_default_subject and recovery_default_message + zabbix_action: + default_subject: Example default subject + default_message: Example default message + recovery_default_subject: Example recovery subject + recovery_default_message: Example recovery message + register: zbxaction_rec_msgsubj + + - assert: + that: zbxaction_rec_msgsubj.changed is sameas True + + - name: test - update action with recovery_default_subject and recovery_default_message (again) + zabbix_action: + default_subject: Example default subject + default_message: Example default message + recovery_default_subject: Example recovery subject + recovery_default_message: Example recovery message + register: zbxaction_rec_msgsubj + + - assert: + that: zbxaction_rec_msgsubj.changed is sameas False + + - when: + - zabbix_version is version('3.4', '>=') + - zabbix_version is version('5.0', '<') + block: + - name: test - update action with acknowledge_default_subject and acknowledge_default_message + zabbix_action: + default_subject: Example default subject + default_message: Example default message + recovery_default_subject: Example recovery subject + recovery_default_message: Example recovery message + acknowledge_default_subject: Example acknowledge subject + acknowledge_default_message: Example acknowledge message + register: zbxaction_ack_msgsubj + + - assert: + that: zbxaction_ack_msgsubj.changed is sameas True + + - name: test - update action with acknowledge_default_subject and acknowledge_default_message (again) + zabbix_action: + default_subject: Example default subject + default_message: Example default message + recovery_default_subject: Example recovery subject + recovery_default_message: Example recovery message + acknowledge_default_subject: Example acknowledge subject + acknowledge_default_message: Example acknowledge message + register: zbxaction_ack_msgsubj + + - assert: + that: zbxaction_ack_msgsubj.changed is sameas False + + - name: test - reset action to default + zabbix_action: + register: zbxaction_reset + + - assert: + that: zbxaction_reset.changed is sameas True + + - name: test - disable action + zabbix_action: + status: disabled + register: zbxaction_disable + + - assert: + that: zbxaction_disable.changed is sameas True + + - name: test - disable action (again) + zabbix_action: + status: disabled + register: zbxaction_disable + + - assert: + that: zbxaction_disable.changed is sameas False + + - name: test - delete action + zabbix_action: + state: absent + register: zbxaction_delete + + - assert: + that: zbxaction_delete.changed is sameas True + + - name: test - delete action (again) + zabbix_action: + state: absent + register: zbxaction_delete + + - assert: + that: zbxaction_delete.changed is sameas False + +- name: test - trigger actions with conditions + module_defaults: + community.zabbix.zabbix_action: + state: present + status: enabled + name: ExampleTriggerActionConditions + event_source: trigger + esc_period: 60 + operations: + - type: send_message + subject: ExampleSubject + message: ExampleMessage + media_type: ExampleMediaTypeForActionModule + send_to_users: + - Admin + + block: + - name: test - create new action with multiple conditions + zabbix_action: + conditions: + - type: host_group + operator: '=' + value: Linux servers + - type: trigger_severity + operator: '>=' + value: Average + - type: event_tag_value + value: MyTag + operator: '=' + value2: MyTagValue + - type: time_period + operator: not in + value: 6-7,00:00-24:00 + register: zbxaction_conditions + + - assert: + that: zbxaction_conditions.changed is sameas True + + - name: test - create new action with multiple conditions (again) + zabbix_action: + conditions: + - type: host_group + operator: '=' + value: Linux servers + - type: trigger_severity + operator: '>=' + value: Average + - type: event_tag_value + value: MyTag + operator: '=' + value2: MyTagValue + - type: time_period + operator: not in + value: 6-7,00:00-24:00 + register: zbxaction_conditions + + - assert: + that: zbxaction_conditions.changed is sameas False + + - name: test - create new action with multiple conditions (reorder) + zabbix_action: + conditions: + - type: host_group + operator: '=' + value: Linux servers + - type: event_tag_value + value: MyTag + operator: '=' + value2: MyTagValue + - type: trigger_severity + operator: '>=' + value: Average + - type: time_period + operator: not in + value: 6-7,00:00-24:00 + register: zbxaction_conditions_reorder + + - assert: + that: zbxaction_conditions_reorder.changed is sameas False + + - name: test - update action with multiple conditions by removing one condition + zabbix_action: + conditions: + - type: host_group + operator: '=' + value: Linux servers + - type: event_tag_value + value: MyTag + operator: '=' + value2: MyTagValue + - type: trigger_severity + operator: '>=' + value: Average + register: zbxaction_conditions_delone + + - assert: + that: zbxaction_conditions_delone.changed is sameas True + + - name: test - update action with multiple conditions by changing operators + zabbix_action: + conditions: + - type: host_group + operator: '<>' + value: Linux servers + - type: event_tag_value + value: MyTag + operator: '<>' + value2: MyTagValue + - type: trigger_severity + operator: '<=' + value: Average + register: zbxaction_conditions_operators + + - assert: + that: zbxaction_conditions_operators.changed is sameas True + + - name: test - update action with multiple conditions with operator aliases + zabbix_action: + conditions: + - type: host_group + operator: does not equal + value: Linux servers + - type: event_tag_value + value: MyTag + operator: contains + value2: MyTagValue + - type: trigger_severity + operator: is less than or equals + value: Average + register: zbxaction_conditions_operator_aliases + + - assert: + that: zbxaction_conditions_operator_aliases.changed is sameas True + + - name: test - update action with multiple conditions and evaltype + zabbix_action: + conditions: + - type: host_group + operator: '<>' + value: Linux servers + - type: event_tag_value + value: MyTag + operator: '<>' + value2: MyTagValue + - type: trigger_severity + operator: '<=' + value: Average + eval_type: and + register: zbxaction_conditions_eval + + - assert: + that: zbxaction_conditions_eval.changed is sameas True + + - name: test - update action with multiple conditions and evaltype (again) + zabbix_action: + conditions: + - type: host_group + operator: '<>' + value: Linux servers + - type: event_tag_value + value: MyTag + operator: '<>' + value2: MyTagValue + - type: trigger_severity + operator: '<=' + value: Average + eval_type: and + register: zbxaction_conditions_eval + + - assert: + that: zbxaction_conditions_eval.changed is sameas False + + - name: test - update action with reduced conditions and formula + zabbix_action: + conditions: + - type: host_group + operator: '=' + value: Linux servers + formulaid: A + - type: trigger_severity + operator: '>=' + value: Average + formulaid: B + - type: event_tag_value + value: MyTag + operator: '<>' + value2: MyTagValue + formulaid: C + formula: A and (B or C) + register: zbxaction_conditions_formula + + - assert: + that: zbxaction_conditions_formula.changed is sameas True + + - name: test - update formula used in action with reduced conditions + zabbix_action: + conditions: + - type: host_group + operator: '=' + value: Linux servers + formulaid: A + - type: trigger_severity + operator: '>=' + value: Average + formulaid: B + - type: event_tag_value + value: MyTag + operator: '<>' + value2: MyTagValue + formulaid: C + formula: (A or B) or C + register: zbxaction_conditions_formula + + - assert: + that: zbxaction_conditions_formula.changed is sameas True + + - name: test - update formula used in action with reduced conditions (again) + zabbix_action: + conditions: + - type: host_group + operator: '=' + value: Linux servers + formulaid: A + - type: trigger_severity + operator: '>=' + value: Average + formulaid: B + - type: event_tag_value + value: MyTag + operator: '<>' + value2: MyTagValue + formulaid: C + formula: (A or B) or C + register: zbxaction_conditions_formula + + - assert: + that: zbxaction_conditions_formula.changed is sameas False + + - name: test - delete action + zabbix_action: + state: absent + register: zbxaction_delete + + - assert: + that: zbxaction_delete.changed is sameas True + +- name: test - trigger actions with message operations + module_defaults: + community.zabbix.zabbix_action: + state: present + status: enabled + name: ExampleTriggerActionOperations + event_source: trigger + esc_period: 60 + conditions: + - type: trigger_severity + operator: '>=' + value: Average + + block: + - name: test - create new action with send_message operations + zabbix_action: + operations: + - type: send_message + send_to_users: + - Admin + subject: test_subject + message: test_message + media_type: ExampleMediaTypeForActionModule + operation_condition: not_acknowledged + esc_step_from: 1 + esc_step_to: 2 + - type: send_message + send_to_users: + - Admin + subject: test_subject + message: test_message + media_type: SMS + operation_condition: not_acknowledged + esc_step_from: 2 + esc_step_to: 0 + esc_period: 300 + register: zbxaction_ops + + - assert: + that: zbxaction_ops.changed is sameas True + + - name: test - create new action with send_message operations (again) + zabbix_action: + operations: + - type: send_message + send_to_users: + - Admin + subject: test_subject + message: test_message + media_type: ExampleMediaTypeForActionModule + operation_condition: not_acknowledged + esc_step_from: 1 + esc_step_to: 2 + - type: send_message + send_to_users: + - Admin + subject: test_subject + message: test_message + media_type: SMS + operation_condition: not_acknowledged + esc_step_from: 2 + esc_step_to: 0 + esc_period: 300 + register: zbxaction_ops + + - assert: + that: zbxaction_ops.changed is sameas False + + - name: test - delete action + zabbix_action: + state: absent + register: zbxaction_delete + + - assert: + that: zbxaction_delete.changed is sameas True + + - name: test - create new action with escalation steps 1-1 + zabbix_action: + operations: + - type: send_message + send_to_users: + - Admin + media_type: ExampleMediaTypeForActionModule + esc_step_from: 1 + esc_step_to: 1 + register: zbxaction_esc11 + + - assert: + that: zbxaction_esc11.changed is sameas True + + - name: test - create new action with escalation steps 1-1 (again) + zabbix_action: + operations: + - type: send_message + send_to_users: + - Admin + media_type: ExampleMediaTypeForActionModule + esc_step_from: 1 + esc_step_to: 1 + register: zbxaction_esc11_again + + - assert: + that: zbxaction_esc11_again.changed is sameas False + + + - name: test - update action with escalation steps 2-2 + zabbix_action: + operations: + - type: send_message + send_to_users: + - Admin + media_type: ExampleMediaTypeForActionModule + esc_step_from: 2 + esc_step_to: 2 + register: zbxaction_esc22 + + - assert: + that: zbxaction_esc22.changed is sameas True + + - name: test - create new action with escalation steps 2-2 (again) + zabbix_action: + operations: + - type: send_message + send_to_users: + - Admin + media_type: ExampleMediaTypeForActionModule + esc_step_from: 2 + esc_step_to: 2 + register: zbxaction_esc22_again + + - assert: + that: zbxaction_esc11_again.changed is sameas False + + - name: test - delete action + zabbix_action: + state: absent + register: zbxaction_delete + + - assert: + that: zbxaction_delete.changed is sameas True +- name: test - trigger actions with remote_script operations with < Zabbix 6.0 + when: zabbix_version is version('6.0', '<') + module_defaults: + community.zabbix.zabbix_action: + state: present + status: enabled + name: ExampleTriggerActionOperations + event_source: trigger + esc_period: 60 + conditions: + - type: trigger_severity + operator: '>=' + value: Average + + block: + - name: test - create new action with remote_command operations + zabbix_action: + operations: + - type: remote_command + command_type: custom_script + command: /usr/local/bin/do_something.sh + execute_on: agent + run_on_hosts: 0 + - type: remote_command + command_type: ssh + command: /usr/local/bin/do_something.sh + run_on_hosts: 0 + ssh_auth_type: password + username: root + password: zabbix + - type: remote_command + command_type: global_script + script_name: Ping + run_on_hosts: 0 + register: zbxaction_rmtcmd + + - assert: + that: zbxaction_rmtcmd.changed is sameas True + + - name: test - create new action with remote_command operations (again) + zabbix_action: + operations: + - type: remote_command + command_type: custom_script + command: /usr/local/bin/do_something.sh + execute_on: agent + run_on_hosts: 0 + - type: remote_command + command_type: ssh + command: /usr/local/bin/do_something.sh + run_on_hosts: 0 + ssh_auth_type: password + username: root + password: zabbix + - type: remote_command + command_type: global_script + script_name: Ping + run_on_hosts: 0 + register: zbxaction_rmtcmd + + - assert: + that: zbxaction_rmtcmd.changed is sameas False + + - name: test - update ssh remote_command auth in action with remote_command operations + zabbix_action: + operations: + - type: remote_command + command_type: custom_script + command: /usr/local/bin/do_something.sh + execute_on: agent + run_on_hosts: 0 + - type: remote_command + command_type: ssh + command: /usr/local/bin/do_something.sh + run_on_hosts: 0 + ssh_auth_type: public_key + username: root + ssh_privatekey_file: /etc/zabbix/.ssh/id_test + ssh_publickey_file: /etc/zabbix/.ssh/id_test.pub + - type: remote_command + command_type: global_script + script_name: Ping + run_on_hosts: 0 + register: zbxaction_rmtcmd + + - assert: + that: zbxaction_rmtcmd.changed is sameas True + + - name: test - delete action + zabbix_action: + state: absent + register: zbxaction_delete + + - assert: + that: zbxaction_delete.changed is sameas True + +- name: test - discovery actions + module_defaults: + community.zabbix.zabbix_action: + state: present + status: enabled + name: ExampleDiscoveryActionOperations + event_source: discovery + esc_period: 60 + + block: + - name: test - create new discovery action + zabbix_action: + conditions: + - type: host_IP + operator: '=' + value: '192.168.0.1-127' + - type: discovery_object + operator: '=' + value: host + - type: discovery_status + operator: '=' + value: 'discovered' + - type: uptime_or_downtime_duration + operator: '>=' + value: 1800 + operations: + - type: add_host + - type: add_to_host_group + host_groups: + - Linux servers + - type: link_to_template + templates: + - ExampleTemplateForActionModule + - type: enable_host + - type: set_host_inventory_mode + inventory: automatic + register: zbxaction_discovery + + - assert: + that: zbxaction_discovery.changed is sameas True + + - name: test - create new discovery action (again) + zabbix_action: + conditions: + - type: host_IP + operator: '=' + value: '192.168.0.1-127' + - type: discovery_object + operator: '=' + value: host + - type: discovery_status + operator: '=' + value: 'discovered' + - type: uptime_or_downtime_duration + operator: '>=' + value: 1800 + operations: + - type: add_host + - type: add_to_host_group + host_groups: + - Linux servers + - type: link_to_template + templates: + - ExampleTemplateForActionModule + - type: enable_host + - type: set_host_inventory_mode + inventory: automatic + register: zbxaction_discovery + + - assert: + that: zbxaction_discovery.changed is sameas False + + - name: test - update discovery action conditions and operations + zabbix_action: + conditions: + - type: host_IP + operator: '=' + value: '192.168.1.1-127' + - type: discovery_object + operator: '=' + value: host + - type: discovery_status + operator: '=' + value: 'discovered' + - type: uptime_or_downtime_duration + operator: '>=' + value: 2200 + operations: + - type: add_host + - type: add_to_host_group + host_groups: + - Linux servers + - Discovered hosts + - type: link_to_template + templates: + - ExampleTemplateForActionModule + - type: enable_host + - type: send_message + send_to_users: + - Admin + subject: test_subject + message: test_message + media_type: ExampleMediaTypeForActionModule + operation_condition: not_acknowledged + esc_step_from: 1 + esc_step_to: 2 + register: zbxaction_discovery_update + + - assert: + that: zbxaction_discovery_update.changed is sameas True + + - name: test - update discovery action conditions and operations (again) + zabbix_action: + conditions: + - type: host_IP + operator: '=' + value: '192.168.1.1-127' + - type: discovery_object + operator: '=' + value: host + - type: discovery_status + operator: '=' + value: 'discovered' + - type: uptime_or_downtime_duration + operator: '>=' + value: 2200 + operations: + - type: add_host + - type: add_to_host_group + host_groups: + - Linux servers + - Discovered hosts + - type: link_to_template + templates: + - ExampleTemplateForActionModule + - type: enable_host + - type: send_message + send_to_users: + - Admin + subject: test_subject + message: test_message + media_type: ExampleMediaTypeForActionModule + operation_condition: not_acknowledged + esc_step_from: 1 + esc_step_to: 2 + register: zbxaction_discovery_update + + - assert: + that: zbxaction_discovery_update.changed is sameas False + + - name: test - delete action + zabbix_action: + state: absent + register: zbxaction_delete + + - assert: + that: zbxaction_delete.changed is sameas True + +- name: test - auto registration actions + module_defaults: + community.zabbix.zabbix_action: + state: present + status: enabled + name: ExampleAutoRegActionOperations + event_source: auto_registration + esc_period: 60 + + block: + - name: test - create new auto registration action + zabbix_action: + conditions: + - type: host_name + operator: like + value: zabbix + - type: host_metadata + operator: not like + value: somemetadata + operations: + - type: add_host + register: zbxaction_autoreg + + - assert: + that: zbxaction_autoreg.changed is sameas True + + - name: test - create new auto registration action (again) + zabbix_action: + conditions: + - type: host_name + operator: like + value: zabbix + - type: host_metadata + operator: not like + value: somemetadata + operations: + - type: add_host + register: zbxaction_autoreg + + - assert: + that: zbxaction_autoreg.changed is sameas False + + - name: test - update auto registration action + zabbix_action: + conditions: + - type: host_name + operator: like + value: zabbix + - type: host_metadata + operator: not like + value: somemetadata + - type: host_metadata + operator: like + value: somemetadata2 + operations: + - type: add_host + register: zbxaction_autoreg_update + + - assert: + that: zbxaction_autoreg_update.changed is sameas True + + - name: test - update auto registration action (again) + zabbix_action: + conditions: + - type: host_name + operator: like + value: zabbix + - type: host_metadata + operator: not like + value: somemetadata + - type: host_metadata + operator: like + value: somemetadata2 + operations: + - type: add_host + register: zbxaction_autoreg_update + + - assert: + that: zbxaction_autoreg_update.changed is sameas False + + - name: test - delete action + zabbix_action: + state: absent + register: zbxaction_delete + + - assert: + that: zbxaction_delete.changed is sameas True + +- name: test - internal actions + module_defaults: + community.zabbix.zabbix_action: + state: present + status: enabled + name: ExampleInternalActionOperations + event_source: internal + esc_period: 60 + operations: + - type: send_message + send_to_users: + - Admin + subject: test_subject + message: test_message + media_type: ExampleMediaTypeForActionModule + + block: + - name: test - create new internal action + zabbix_action: + conditions: + - type: host_template + operator: '=' + value: ExampleTemplateForActionModule + - type: event_type + operator: '=' + value: item in not supported state + register: zbxaction_internal + + - assert: + that: zbxaction_internal.changed is sameas True + + - name: test - create new internal action (again) + zabbix_action: + conditions: + - type: host_template + operator: '=' + value: ExampleTemplateForActionModule + - type: event_type + operator: '=' + value: item in not supported state + register: zbxaction_internal + + - assert: + that: zbxaction_internal.changed is sameas False + + - name: test - update internal action conditions + zabbix_action: + conditions: + - type: host_template + operator: '=' + value: ExampleTemplateForActionModule + - type: event_type + operator: '=' + value: item in not supported state + - type: event_type + operator: '=' + value: trigger in unknown state + register: zbxaction_internal_update + + - assert: + that: zbxaction_internal_update.changed is sameas True + + - name: test - update internal action conditions (again) + zabbix_action: + conditions: + - type: host_template + operator: '=' + value: ExampleTemplateForActionModule + - type: event_type + operator: '=' + value: item in not supported state + - type: event_type + operator: '=' + value: trigger in unknown state + register: zbxaction_internal_update + + - assert: + that: zbxaction_internal_update.changed is sameas False + + - name: test - delete action + zabbix_action: + state: absent + register: zbxaction_delete + + - assert: + that: zbxaction_delete.changed is sameas True + +- name: test - actions with recovery and acknowledge operations with < Zabbix 6.0 + when: + - zabbix_version is version('3.4', '>=') + - zabbix_version is version('6.0', '<') + module_defaults: + community.zabbix.zabbix_action: + state: present + status: enabled + name: ExampleTriggerActionRecAckOps + event_source: trigger + esc_period: 60 + conditions: + - type: trigger_severity + operator: '>=' + value: Information + operations: + - type: send_message + subject: ExampleSubject + message: ExampleMessage + media_type: ExampleMediaTypeForActionModule + send_to_users: + - Admin + + block: + - name: test - create new action with recovery and acknowledge operations + zabbix_action: + recovery_operations: + - type: send_message + subject: ExampleSubject + message: ExampleMessage + media_type: ExampleMediaTypeForActionModule + send_to_users: + - Admin + - type: remote_command + command_type: custom_script + command: /usr/local/bin/do_something.sh + execute_on: agent + run_on_hosts: 0 + - type: remote_command + command_type: ssh + command: /usr/local/bin/do_something.sh + run_on_hosts: 0 + ssh_auth_type: password + username: root + password: zabbix + - type: notify_all_involved + subject: RecoverySubject + message: RecoveryMessage + acknowledge_operations: + - type: send_message + subject: ExampleSubject + message: ExampleMessage + media_type: ExampleMediaTypeForActionModule + send_to_users: + - Admin + - type: remote_command + command_type: ssh + command: /usr/local/bin/do_something.sh + run_on_hosts: 0 + ssh_auth_type: public_key + username: root + ssh_privatekey_file: /etc/zabbix/.ssh/id_test + ssh_publickey_file: /etc/zabbix/.ssh/id_test.pub + - type: remote_command + command_type: global_script + script_name: Ping + run_on_hosts: 0 + - type: notify_all_involved + subject: RecoverySubject + message: RecoveryMessage + media_type: ExampleMediaTypeForActionModule + register: zbxaction_recack_new + + - assert: + that: zbxaction_recack_new.changed is sameas True + + - name: test - create new action with recovery and acknowledge operations (again) + zabbix_action: + recovery_operations: + - type: send_message + subject: ExampleSubject + message: ExampleMessage + media_type: ExampleMediaTypeForActionModule + send_to_users: + - Admin + - type: remote_command + command_type: custom_script + command: /usr/local/bin/do_something.sh + execute_on: agent + run_on_hosts: 0 + - type: remote_command + command_type: ssh + command: /usr/local/bin/do_something.sh + run_on_hosts: 0 + ssh_auth_type: password + username: root + password: zabbix + - type: notify_all_involved + subject: RecoverySubject + message: RecoveryMessage + acknowledge_operations: + - type: send_message + subject: ExampleSubject + message: ExampleMessage + media_type: ExampleMediaTypeForActionModule + send_to_users: + - Admin + - type: remote_command + command_type: ssh + command: /usr/local/bin/do_something.sh + run_on_hosts: 0 + ssh_auth_type: public_key + username: root + ssh_privatekey_file: /etc/zabbix/.ssh/id_test + ssh_publickey_file: /etc/zabbix/.ssh/id_test.pub + - type: remote_command + command_type: global_script + script_name: Ping + run_on_hosts: 0 + - type: notify_all_involved + subject: RecoverySubject + message: RecoveryMessage + media_type: ExampleMediaTypeForActionModule + register: zbxaction_recack_new + + - assert: + that: zbxaction_recack_new.changed is sameas False + + - name: test - delete action + zabbix_action: + state: absent + register: zbxaction_delete + + - assert: + that: zbxaction_delete.changed is sameas True + +- name: test - actions with recovery and acknowledge operations with >= Zabbx 6.0 + when: + - zabbix_version is version('6.0', '>=') + module_defaults: + community.zabbix.zabbix_action: + state: present + status: enabled + name: ExampleTriggerActionRecAckOps + event_source: trigger + esc_period: 60 + conditions: + - type: trigger_severity + operator: '>=' + value: Information + operations: + - type: send_message + subject: ExampleSubject + message: ExampleMessage + media_type: ExampleMediaTypeForActionModule + send_to_users: + - Admin + + block: + - name: test - create new action with recovery and acknowledge operations + zabbix_action: + recovery_operations: + - type: send_message + subject: ExampleSubject + message: ExampleMessage + media_type: ExampleMediaTypeForActionModule + send_to_users: + - Admin + - type: notify_all_involved + subject: RecoverySubject + message: RecoveryMessage + acknowledge_operations: + - type: send_message + subject: ExampleSubject + message: ExampleMessage + media_type: ExampleMediaTypeForActionModule + send_to_users: + - Admin + - type: notify_all_involved + subject: RecoverySubject + message: RecoveryMessage + media_type: ExampleMediaTypeForActionModule + register: zbxaction_recack_new + + - assert: + that: zbxaction_recack_new.changed is sameas True + + - name: test - create new action with recovery and acknowledge operations (again) + zabbix_action: + recovery_operations: + - type: send_message + subject: ExampleSubject + message: ExampleMessage + media_type: ExampleMediaTypeForActionModule + send_to_users: + - Admin + - type: notify_all_involved + subject: RecoverySubject + message: RecoveryMessage + acknowledge_operations: + - type: send_message + subject: ExampleSubject + message: ExampleMessage + media_type: ExampleMediaTypeForActionModule + send_to_users: + - Admin + - type: notify_all_involved + subject: RecoverySubject + message: RecoveryMessage + media_type: ExampleMediaTypeForActionModule + register: zbxaction_recack_new + + - assert: + that: zbxaction_recack_new.changed is sameas False + + - when: zabbix_version is version('6.4', '>=') + block: + - name: test - update action with pause_symptoms off + zabbix_action: + recovery_operations: + - type: send_message + subject: ExampleSubject + message: ExampleMessage + media_type: ExampleMediaTypeForActionModule + send_to_users: + - Admin + - type: notify_all_involved + subject: RecoverySubject + message: RecoveryMessage + acknowledge_operations: + - type: send_message + subject: ExampleSubject + message: ExampleMessage + media_type: ExampleMediaTypeForActionModule + send_to_users: + - Admin + - type: notify_all_involved + subject: RecoverySubject + message: RecoveryMessage + media_type: ExampleMediaTypeForActionModule + pause_symptoms: False + register: zbxaction_pause_symptoms + + - assert: + that: zbxaction_pause_symptoms.changed is sameas True + + - name: test - update action with pause_symptoms off (again) + zabbix_action: + recovery_operations: + - type: send_message + subject: ExampleSubject + message: ExampleMessage + media_type: ExampleMediaTypeForActionModule + send_to_users: + - Admin + - type: notify_all_involved + subject: RecoverySubject + message: RecoveryMessage + acknowledge_operations: + - type: send_message + subject: ExampleSubject + message: ExampleMessage + media_type: ExampleMediaTypeForActionModule + send_to_users: + - Admin + - type: notify_all_involved + subject: RecoverySubject + message: RecoveryMessage + media_type: ExampleMediaTypeForActionModule + pause_symptoms: False + register: zbxaction_pause_symptoms + + - assert: + that: zbxaction_pause_symptoms.changed is sameas False + + - name: test - delete action + zabbix_action: + state: absent + register: zbxaction_delete + + - assert: + that: zbxaction_delete.changed is sameas True + +- name: test - Output error message when user sets application to conditions with >= Zabbix 5.4 + community.zabbix.zabbix_action: + name: ExampleApplicationAction + event_source: trigger + esc_period: 60 + conditions: + - type: application + operator: like + value: AnsibleTest + operations: + - type: send_message + subject: ExampleSubject + message: ExampleMessage + media_type: ExampleMediaTypeForActionModule + send_to_users: + - Admin + ignore_errors: true + register: zbxaction_application + +- assert: + that: + - zbxaction_application.failed is sameas True + - zbxaction_application.msg == "'application' is disabled for condition type since 5.4 version." + when: zabbix_version is version('5.4', '>=') + +- name: delete ExampleApplicationAction action + community.zabbix.zabbix_action: + name: ExampleApplicationAction + state: absent + +- name: test - cleanup example template for zabbix_action module + zabbix_template: + template_name: ExampleTemplateForActionModule + timeout: 20 + state: absent + register: zbxaction_prep_template + +- name: test - cleanup example mediatype for zabbix_action module + zabbix_mediatype: + name: ExampleMediaTypeForActionModule + type: email + state: absent + register: zbxaction_prep_mediatype diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_authentication/meta/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_authentication/meta/main.yml new file mode 100644 index 000000000..acdb704c8 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_authentication/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - setup_zabbix diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_authentication/tasks/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_authentication/tasks/main.yml new file mode 100644 index 000000000..f6364f35a --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_authentication/tasks/main.yml @@ -0,0 +1,10 @@ +--- +- block: + - include_tasks: zabbix_authentication_tests.yml + + always: + - name: Cleanup + zabbix_user_directory: + name: TestUserDirectory + state: absent + ignore_errors: true diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_authentication/tasks/zabbix_authentication_tests.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_authentication/tasks/zabbix_authentication_tests.yml new file mode 100644 index 000000000..effc1b900 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_authentication/tasks/zabbix_authentication_tests.yml @@ -0,0 +1,439 @@ +--- +- name: test - do not run tests with < Zabbix 4.0 + meta: end_play + when: zabbix_version is version('4.0', '<') + +- when: zabbix_version is version('5.4', '<') + name: Unsupport Zabbix version (<5.4) + block: + - name: test - fail to update authentication setting + zabbix_authentication: + authentication_type: internal + ignore_errors: true + register: zbxauth_update + + - assert: + that: zbxauth_update.failed is sameas True + +- when: + - zabbix_version is version('5.4', '>=') + - zabbix_version is version('6.0', '<=') + name: support Zabbix version (>=5.4 <=6.0) + block: + - name: test - update ldap_configured without mandatory paramters + zabbix_authentication: + ldap_configured: true + ignore_errors: true + register: zbxauth_update + + - name: assert that authentication was NOT updated + assert: + that: + - zbxauth_update.failed is sameas True + - zbxauth_update.msg == "Please set ldap_host, ldap_search_attribute and ldap_base_dn when you change a value of ldap_configured to true." + + - name: test - update saml_auth_enabled without mandatory paramters + zabbix_authentication: + saml_auth_enabled: true + ignore_errors: true + register: zbxauth_update + + - name: assert that authentication was NOT updated + assert: + that: + - zbxauth_update.failed is sameas True + - zbxauth_update.msg == "Please set saml_idp_entityid, saml_sso_url, saml_username_attribute and saml_sp_entityid when you change a value of saml_auth_enabled to true." + + - name: test - update all authentication setting + zabbix_authentication: + authentication_type: internal + http_auth_enabled: true + http_login_form: zabbix_login_form + http_strip_domains: 'comp,any' + http_case_sensitive: true + ldap_configured: true + ldap_host: 'ldap://localhost' + ldap_port: 389 + ldap_base_dn: 'ou=Users,ou=system' + ldap_search_attribute: 'uid' + ldap_bind_dn: 'uid=ldap_search,ou=system' + ldap_case_sensitive: true + ldap_bind_password: 'password' + saml_auth_enabled: true + saml_idp_entityid: '' + saml_sso_url: 'https://localhost/SAML2/SSO' + saml_slo_url: 'https://localhost/SAML2/SLO' + saml_username_attribute: 'uid' + saml_sp_entityid: 'https://localhost' + saml_nameid_format: 'urn:oasis:names:tc:SAML:2.0:nameid-format:entity' + saml_sign_messages: true + saml_sign_assertions: true + saml_sign_authn_requests: true + saml_sign_logout_requests: true + saml_sign_logout_responses: true + saml_encrypt_nameid: true + saml_encrypt_assertions: true + saml_case_sensitive: true + passwd_min_length: 70 + passwd_check_rules: + - contain_uppercase_and_lowercase_letters + - contain_digits + - contain_special_characters + - avoid_easy_to_guess + register: zbxauth_update + + - name: assert that authentication was updated + assert: + that: zbxauth_update.changed is sameas True + + - name: test - update all authentication setting (again) + zabbix_authentication: + authentication_type: internal + http_auth_enabled: true + http_login_form: zabbix_login_form + http_strip_domains: + - comp + - any + http_case_sensitive: true + ldap_configured: true + ldap_host: 'ldap://localhost' + ldap_port: 389 + ldap_base_dn: 'ou=Users,ou=system' + ldap_search_attribute: 'uid' + ldap_bind_dn: 'uid=ldap_search,ou=system' + ldap_case_sensitive: true + ldap_bind_password: 'password' + saml_auth_enabled: true + saml_idp_entityid: '' + saml_sso_url: 'https://localhost/SAML2/SSO' + saml_slo_url: 'https://localhost/SAML2/SLO' + saml_username_attribute: 'uid' + saml_sp_entityid: 'https://localhost' + saml_nameid_format: 'urn:oasis:names:tc:SAML:2.0:nameid-format:entity' + saml_sign_messages: true + saml_sign_assertions: true + saml_sign_authn_requests: true + saml_sign_logout_requests: true + saml_sign_logout_responses: true + saml_encrypt_nameid: true + saml_encrypt_assertions: true + saml_case_sensitive: true + passwd_min_length: 70 + passwd_check_rules: + - contain_uppercase_and_lowercase_letters + - contain_digits + - contain_special_characters + - avoid_easy_to_guess + register: zbxauth_update + + - name: assert that authentication was NOT updated + assert: + that: zbxauth_update.changed is sameas False + + - name: test - initialize all authentication setting + zabbix_authentication: + authentication_type: internal + http_auth_enabled: false + http_login_form: zabbix_login_form + http_strip_domains: [] + http_case_sensitive: true + ldap_configured: false + ldap_host: '' + ldap_port: 389 + ldap_base_dn: '' + ldap_search_attribute: '' + ldap_bind_dn: '' + ldap_case_sensitive: true + ldap_bind_password: '' + saml_auth_enabled: false + saml_idp_entityid: '' + saml_sso_url: '' + saml_slo_url: '' + saml_username_attribute: '' + saml_sp_entityid: '' + saml_nameid_format: '' + saml_sign_messages: false + saml_sign_assertions: false + saml_sign_authn_requests: false + saml_sign_logout_requests: false + saml_sign_logout_responses: false + saml_encrypt_nameid: false + saml_encrypt_assertions: false + saml_case_sensitive: false + passwd_min_length: 8 + passwd_check_rules: + - avoid_easy_to_guess + register: zbxauth_update + + - name: assert that authentication was updated + assert: + that: zbxauth_update.changed is sameas True + +- when: + - zabbix_version is version('6.2', '=') + name: support Zabbix version (=6.2) + block: + - name: test - create user directory + zabbix_user_directory: + name: TestUserDirectory + host: 'test.com' + port: 389 + base_dn: 'ou=Users,dc=example,dc=org' + search_attribute: 'uid' + + - name: test - update ldap_configured without mandatory paramters + zabbix_authentication: + ldap_configured: true + ignore_errors: true + register: zbxauth_update + + - name: assert that authentication was NOT updated + assert: + that: + - zbxauth_update.failed is sameas True + - zbxauth_update.msg == "Please set ldap_userdirectory when you change a value of ldap_configured to true." + + - name: test - update saml_auth_enabled without mandatory paramters + zabbix_authentication: + saml_auth_enabled: true + ignore_errors: true + register: zbxauth_update + + - name: assert that authentication was NOT updated + assert: + that: + - zbxauth_update.failed is sameas True + - zbxauth_update.msg == "Please set saml_idp_entityid, saml_sso_url, saml_username_attribute and saml_sp_entityid when you change a value of saml_auth_enabled to true." + + - name: test - update all authentication setting + zabbix_authentication: + authentication_type: internal + http_auth_enabled: true + http_login_form: zabbix_login_form + http_strip_domains: 'comp,any' + http_case_sensitive: true + ldap_configured: true + ldap_case_sensitive: true + ldap_userdirectory: TestUserDirectory + saml_auth_enabled: true + saml_idp_entityid: '' + saml_sso_url: 'https://localhost/SAML2/SSO' + saml_slo_url: 'https://localhost/SAML2/SLO' + saml_username_attribute: 'uid' + saml_sp_entityid: 'https://localhost' + saml_nameid_format: 'urn:oasis:names:tc:SAML:2.0:nameid-format:entity' + saml_sign_messages: true + saml_sign_assertions: true + saml_sign_authn_requests: true + saml_sign_logout_requests: true + saml_sign_logout_responses: true + saml_encrypt_nameid: true + saml_encrypt_assertions: true + saml_case_sensitive: true + passwd_min_length: 70 + passwd_check_rules: + - contain_uppercase_and_lowercase_letters + - contain_digits + - contain_special_characters + - avoid_easy_to_guess + register: zbxauth_update + + - name: assert that authentication was updated + assert: + that: zbxauth_update.changed is sameas True + + - name: test - update all authentication setting (again) + zabbix_authentication: + authentication_type: internal + http_auth_enabled: true + http_login_form: zabbix_login_form + http_strip_domains: + - comp + - any + http_case_sensitive: true + ldap_configured: true + ldap_case_sensitive: true + ldap_userdirectory: TestUserDirectory + saml_auth_enabled: true + saml_idp_entityid: '' + saml_sso_url: 'https://localhost/SAML2/SSO' + saml_slo_url: 'https://localhost/SAML2/SLO' + saml_username_attribute: 'uid' + saml_sp_entityid: 'https://localhost' + saml_nameid_format: 'urn:oasis:names:tc:SAML:2.0:nameid-format:entity' + saml_sign_messages: true + saml_sign_assertions: true + saml_sign_authn_requests: true + saml_sign_logout_requests: true + saml_sign_logout_responses: true + saml_encrypt_nameid: true + saml_encrypt_assertions: true + saml_case_sensitive: true + passwd_min_length: 70 + passwd_check_rules: + - contain_uppercase_and_lowercase_letters + - contain_digits + - contain_special_characters + - avoid_easy_to_guess + register: zbxauth_update + + - name: assert that authentication was NOT updated + assert: + that: zbxauth_update.changed is sameas False + + - name: test - initialize all authentication setting + zabbix_authentication: + authentication_type: internal + http_auth_enabled: false + http_login_form: zabbix_login_form + http_strip_domains: [] + http_case_sensitive: true + ldap_configured: false + ldap_case_sensitive: true + saml_auth_enabled: false + saml_idp_entityid: '' + saml_sso_url: '' + saml_slo_url: '' + saml_username_attribute: '' + saml_sp_entityid: '' + saml_nameid_format: '' + saml_sign_messages: false + saml_sign_assertions: false + saml_sign_authn_requests: false + saml_sign_logout_requests: false + saml_sign_logout_responses: false + saml_encrypt_nameid: false + saml_encrypt_assertions: false + saml_case_sensitive: false + passwd_min_length: 8 + passwd_check_rules: + - avoid_easy_to_guess + register: zbxauth_update + + - name: assert that authentication was updated + assert: + that: zbxauth_update.changed is sameas True + + - name: test - delete user directory + zabbix_user_directory: + name: TestUserDirectory + state: absent + +- when: zabbix_version is version('6.4', '>=') + name: support Zabbix version (>=6.4) + block: + - name: test - update ldap_configured without mandatory paramters + zabbix_authentication: + ldap_auth_enabled: true + ignore_errors: true + register: zbxauth_update + + - name: assert that authentication was NOT updated + assert: + that: + - zbxauth_update.failed is sameas True + - zbxauth_update.msg == "Please set ldap_userdirectory when you change a value of ldap_auth_enabled to true." + + - name: test - create LDAP user directory + zabbix_user_directory: + name: TestUserDirectory + idp_type: ldap + host: 'test.ca' + port: 389 + base_dn: 'ou=Users,dc=example,dc=org' + search_attribute: 'uid' + provision_status: True + group_name: cn + group_basedn: ou=Group,dc=example,dc=org + group_member: member + user_ref_attr: uid + group_filter: '(member=uid=%{ref},ou=Users,dc=example,dc=com)' + user_username: first_name + user_lastname: last_name + provision_media: + - name: Media1 + mediatype: Email + attribute: email1 + provision_groups: + - name: idpname1 + role: Guest role + user_groups: + - Guests + + - name: test - update all authentication setting + zabbix_authentication: + authentication_type: internal + http_auth_enabled: true + http_login_form: zabbix_login_form + http_strip_domains: 'comp,any' + http_case_sensitive: true + ldap_auth_enabled: true + ldap_case_sensitive: true + ldap_userdirectory: TestUserDirectory + saml_auth_enabled: true + saml_case_sensitive: true + passwd_min_length: 70 + passwd_check_rules: + - contain_uppercase_and_lowercase_letters + - contain_digits + - contain_special_characters + - avoid_easy_to_guess + ldap_jit_status: true + saml_jit_status: true + jit_provision_interval: 2h + disabled_usrgroup: Disabled + register: zbxauth_update + + - name: assert that authentication was updated + assert: + that: zbxauth_update.changed is sameas True + + - name: test - update all authentication setting (again) + zabbix_authentication: + authentication_type: internal + http_auth_enabled: true + http_login_form: zabbix_login_form + http_strip_domains: 'comp,any' + http_case_sensitive: true + ldap_auth_enabled: true + ldap_case_sensitive: true + ldap_userdirectory: TestUserDirectory + saml_auth_enabled: true + saml_case_sensitive: true + passwd_min_length: 70 + passwd_check_rules: + - contain_uppercase_and_lowercase_letters + - contain_digits + - contain_special_characters + - avoid_easy_to_guess + ldap_jit_status: true + saml_jit_status: true + jit_provision_interval: 2h + disabled_usrgroup: Disabled + register: zbxauth_update + + - name: assert that authentication was NOT updated + assert: + that: zbxauth_update.changed is sameas False + + - name: test - initialize all authentication setting + zabbix_authentication: + authentication_type: internal + http_auth_enabled: false + http_login_form: zabbix_login_form + http_strip_domains: [] + http_case_sensitive: false + ldap_auth_enabled: false + ldap_case_sensitive: false + saml_auth_enabled: false + saml_case_sensitive: false + ldap_jit_status: false + saml_jit_status: false + passwd_min_length: 8 + passwd_check_rules: + - avoid_easy_to_guess + register: zbxauth_update + + - name: assert that authentication was updated + assert: + that: zbxauth_update.changed is sameas True diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_autoregister/meta/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_autoregister/meta/main.yml new file mode 100644 index 000000000..acdb704c8 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_autoregister/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - setup_zabbix diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_autoregister/tasks/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_autoregister/tasks/main.yml new file mode 100644 index 000000000..3dcf93dbe --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_autoregister/tasks/main.yml @@ -0,0 +1,108 @@ +--- +- name: test - do not run tests with < Zabbix 4.0 + meta: end_play + when: zabbix_version is version('4.0', '<') + +- when: zabbix_version is version('4.4', '<') + name: Unsupport Zabbix version (<4.4) + block: + - name: test fail to update autoregistration + community.zabbix.zabbix_autoregister: + tls_accept: "tls_with_psk" + tls_psk_identity: 'PSK 001' + tls_psk: "11111595725ac58dd977beef14b97461a7c1045b9a1c923453302c5473193478" + register: zbxautoregister_update_result + ignore_errors: true + + - assert: + that: zbxautoregister_update_result.failed is sameas True + +- when: zabbix_version is version('4.4', '>=') + name: Support Zabbix version (>=4.4) + block: + - name: test update autoregistration with no parameter + community.zabbix.zabbix_autoregister: + register: zbxautoregister_update_result + ignore_errors: true + + - assert: + that: zbxautoregister_update_result.failed is sameas True + + - name: test update autoregistration with all parameters + community.zabbix.zabbix_autoregister: + tls_accept: + - unsecure + - tls_with_psk + tls_psk_identity: 'PSK 001' + tls_psk: "11111595725ac58dd977beef14b97461a7c1045b9a1c923453302c5473193478" + register: zbxautoregister_update_result + + - assert: + that: zbxautoregister_update_result.changed is sameas True + + - name: test update autoregistration with all parameters (again) + community.zabbix.zabbix_autoregister: + tls_accept: + - unsecure + - tls_with_psk + tls_psk_identity: 'PSK 001' + tls_psk: "11111595725ac58dd977beef14b97461a7c1045b9a1c923453302c5473193478" + register: zbxautoregister_update_result + + - assert: + that: zbxautoregister_update_result.changed is sameas True + + - name: test update autoregistration with only tls_accept + community.zabbix.zabbix_autoregister: + tls_accept: "tls_with_psk" + register: zbxautoregister_update_result + + - assert: + that: zbxautoregister_update_result.changed is sameas True + + - name: test update autoregistration with only tls_accept (again) + community.zabbix.zabbix_autoregister: + tls_accept: + - tls_with_psk + register: zbxautoregister_update_result + + - assert: + that: zbxautoregister_update_result.changed is sameas False + + - name: test update autoregistration with only tls_accept (unsecure) + community.zabbix.zabbix_autoregister: + tls_accept: + - unsecure + register: zbxautoregister_update_result + + - assert: + that: zbxautoregister_update_result.changed is sameas True + + - name: test fail to update autoregistration with only tls_accept (tls_with_psk) + community.zabbix.zabbix_autoregister: + tls_accept: "tls_with_psk" + register: zbxautoregister_update_result + ignore_errors: true + + - assert: + that: zbxautoregister_update_result.failed is sameas True + + - name: test fail to update autoregistration with only tls_accept and tls_psk_identity (tls_with_psk) + community.zabbix.zabbix_autoregister: + tls_accept: "tls_with_psk" + tls_psk_identity: 'PSK 001' + register: zbxautoregister_update_result + ignore_errors: true + + - assert: + that: zbxautoregister_update_result.failed is sameas True + + - name: test fail to update autoregistration with only tls_accept and tls_psk (tls_with_psk) + community.zabbix.zabbix_autoregister: + tls_accept: "tls_with_psk" + tls_psk: "11111595725ac58dd977beef14b97461a7c1045b9a1c923453302c5473193478" + register: zbxautoregister_update_result + ignore_errors: true + + - assert: + that: zbxautoregister_update_result.failed is sameas True diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_discovery_rule/meta/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_discovery_rule/meta/main.yml new file mode 100644 index 000000000..acdb704c8 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_discovery_rule/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - setup_zabbix diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_discovery_rule/tasks/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_discovery_rule/tasks/main.yml new file mode 100644 index 000000000..16062a52e --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_discovery_rule/tasks/main.yml @@ -0,0 +1,280 @@ +--- +- name: test - do not run tests for Zabbix 3.0 + meta: end_play + when: zabbix_version is version('3.0', '=') + +- name: test - Zabbix discovery rule + module_defaults: + community.zabbix.zabbix_discovery_rule: + name: ACME + state: present + iprange: 192.168.1.1-255 + dchecks: + - type: ICMP + delay: "{{ 3600 if zabbix_version is version('3.4', '<=') else omit }}" + + block: + - name: test - create new Zabbix discovery rule (checkmode) + zabbix_discovery_rule: + check_mode: true + register: drule_new_checkmode + + - name: assert that drule will be created (checkmode) + assert: + that: drule_new_checkmode is changed + + - name: test - create new Zabbix discovery rule + zabbix_discovery_rule: + register: drule_new + + - name: assert that drule was created + assert: + that: drule_new is changed + + - name: test - create same Zabbix discovery rule + zabbix_discovery_rule: + register: drule_exists + + - name: assert that nothing has been changed + assert: + that: not drule_exists is changed + + - name: test - update Zabbix discovery rule iprange (checkmode) + zabbix_discovery_rule: + iprange: + - 192.168.1.1-255 + - 10.0.0.1-255 + check_mode: true + register: drule_iprange_update_checkmode + + - name: assert that iprange will be changed + assert: + that: drule_iprange_update_checkmode is changed + + - name: test - update Zabbix discovery rule iprange + zabbix_discovery_rule: + iprange: + - 192.168.1.1-255 + - 10.0.0.1-255 + register: drule_iprange_update + + - name: assert that iprange has been changed + assert: + that: drule_iprange_update is changed + + - name: test - reset Zabbix discovery rule to default + zabbix_discovery_rule: + register: drule_reset + + - name: assert that iprange has been changed + assert: + that: drule_reset is changed + + - name: test - update Zabbix discovery rule status + zabbix_discovery_rule: + status: disabled + register: drule_status_update + + - name: assert that iprange has been changed + assert: + that: drule_status_update is changed + + - name: test - reset Zabbix discovery rule to default + zabbix_discovery_rule: + register: drule_reset + + - name: assert that iprange has been changed + assert: + that: drule_reset is changed + + - name: test - update Zabbix discovery rule dchecks + zabbix_discovery_rule: + dchecks: + - type: ICMP + - type: Zabbix + key: "system.hostname" + ports: "10050" + uniq: true + host_source: discovery + register: drule_dchecks_update + + - name: assert that dcheck has been changed + assert: + that: drule_dchecks_update is changed + + - name: test - update Zabbix discovery rule dchecks ssh + zabbix_discovery_rule: + dchecks: + - type: ICMP + - type: SSH + ports: "22" + register: drule_dchecks_ssh_update + + - name: assert that dcheck has been changed + assert: + that: drule_dchecks_ssh_update is changed + + - name: test - update Zabbix discovery rule dchecks ldap + zabbix_discovery_rule: + dchecks: + - type: ICMP + - type: SSH + ports: "22" + - type: LDAP + ports: "389" + register: drule_dchecks_ldap_update + + - name: assert that dcheck has been changed + assert: + that: drule_dchecks_ldap_update is changed + + - name: test - update Zabbix discovery rule dchecks smtp + zabbix_discovery_rule: + dchecks: + - type: ICMP + - type: SSH + ports: "22" + - type: LDAP + ports: "389" + - type: SMTP + ports: 25,465,587 + register: drule_dchecks_smtp_update + + - name: assert that dcheck has been changed + assert: + that: drule_dchecks_smtp_update is changed + + - name: test - update Zabbix discovery rule dchecks http + zabbix_discovery_rule: + dchecks: + - type: ICMP + - type: SSH + ports: "22" + - type: LDAP + ports: "389" + - type: SMTP + ports: 25,465,587 + - type: HTTP + ports: 80,8080 + register: drule_dchecks_http_update + + - name: assert that dcheck has been changed + assert: + that: drule_dchecks_http_update is changed + + - name: test - remove Zabbix discovery rule dchecks + zabbix_discovery_rule: + dchecks: + - type: ICMP + register: drule_dchecks_remove_update + + - name: assert that dcheck has been changed + assert: + that: drule_dchecks_remove_update is changed + + - name: test - update Zabbix discovery rule snmp dcheck + zabbix_discovery_rule: + dchecks: + - type: SNMPv2 + snmp_community: CUSTOMER@snmp-readonly + ports: "161" + key: iso.3.6.1.2.1.1.1.0 + uniq: false + host_source: discovery + name_source: discovery + register: drule_snmp_update + + - name: assert that snmp dcheck has been changed + assert: + that: drule_snmp_update is changed + + - name: test - update Zabbix discovery rule snmp3 dcheck + zabbix_discovery_rule: + dchecks: + - type: SNMPv3 + snmp_community: CUSTOMER@snmp3-readonly + ports: "161" + key: iso.3.6.1.2.1.1.1.0 + snmpv3_contextname: "ContextName" + snmpv3_securityname: "SecurityName" + snmpv3_securitylevel: authPriv + snmpv3_authprotocol: SHA + snmpv3_authpassphrase: "SeCrEt" + snmpv3_privprotocol: AES + snmpv3_privpassphrase: "TopSecret" + uniq: false + host_source: DNS + name_source: None + register: drule_snmp3_update + + - name: assert that snmp3 dcheck has been changed + assert: + that: drule_snmp3_update is changed + + - name: test - reset Zabbix discovery rule to default + zabbix_discovery_rule: + register: drule_reset + + - name: assert that iprange has been changed + assert: + that: drule_reset is changed + + - name: test - create new active Zabbix proxy server + zabbix_proxy: + proxy_name: ACME_proxy + status: active + state: present + register: zbxproxy_active + + - name: assert that proxy was created + assert: + that: zbxproxy_active is changed + + - name: test - update Zabbix discovery rule proxy + zabbix_discovery_rule: + proxy: ACME_proxy + register: drule_proxy_update + + - name: assert that proxy has been changed + assert: + that: drule_proxy_update is changed + + - name: test - update Zabbix discovery rule proxy (again) + zabbix_discovery_rule: + proxy: ACME_proxy + register: drule_proxy_update_again + + - name: assert that nothing has been changed + assert: + that: not drule_proxy_update_again is changed + +- name: test - delete Zabbix discovery rule + zabbix_discovery_rule: + name: ACME + state: absent + register: drule_delete + +- name: assert that proxy has been deleted + assert: + that: drule_delete is changed + +- name: test - delete Zabbix discovery rule (again) + zabbix_discovery_rule: + name: ACME + state: absent + register: drule_delete_again + +- name: assert that nothing has been changed + assert: + that: not drule_delete_again is changed + +# Cleanup +- name: delete active Zabbix proxy server + zabbix_proxy: + proxy_name: ACME_proxy + state: absent + register: zbxproxy_delete + +- name: assert that proxy has been deleted + assert: + that: zbxproxy_delete is changed diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_globalmacro/meta/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_globalmacro/meta/main.yml new file mode 100644 index 000000000..acdb704c8 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_globalmacro/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - setup_zabbix diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_globalmacro/tasks/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_globalmacro/tasks/main.yml new file mode 100644 index 000000000..ce49f0f86 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_globalmacro/tasks/main.yml @@ -0,0 +1,174 @@ +--- +- name: test - attempt to create new global macro + zabbix_globalmacro: + macro_name: zbxgmacro_test01 + macro_value: 123 + macro_type: text + macro_description: Global Macro description + register: zbxgmacro_new + +- name: assert that macro was created + assert: + that: zbxgmacro_new is changed + +- name: test - attempt to create same global macro + zabbix_globalmacro: + macro_name: zbxgmacro_test01 + macro_value: 123 + macro_type: text + macro_description: Global Macro description + register: zbxgmacro_existing + +- name: assert that nothing has been changed + assert: + that: not zbxgmacro_existing is changed + +- name: test - attempt to create same global macro in zabbix native format + zabbix_globalmacro: + macro_name: "{$zbxgmacro_test01}" + macro_value: 123 + macro_type: text + macro_description: Global Macro description + register: zbxgmacro_existing_native + +- name: assert that nothing has been changed + assert: + that: not zbxgmacro_existing_native is changed + +- name: test - attempt to create new global macro in zabbix native format + zabbix_globalmacro: + macro_name: "{$ZBXGMACRO_TEST02}" + macro_value: abcd + macro_type: text + register: zbxgmacro_new_native + +- name: assert that nothing macro was created + assert: + that: zbxgmacro_new_native is changed + +- name: test - attempt to update global macro with string value while force=no + zabbix_globalmacro: + macro_name: zbxgmacro_test01 + macro_value: abc + macro_type: text + force: false + register: zbxgmacro_update_noforce + +- name: assert that nothing has been changed + assert: + that: not zbxgmacro_update_noforce is changed + +- name: test - attempt to update global macro with string value + zabbix_globalmacro: + macro_name: zbxgmacro_test01 + macro_value: abc + macro_type: text + register: zbxgmacro_update + +- name: assert that global macro was updated + assert: + that: zbxgmacro_update is changed + +- name: test - attempt to create global macro with context + zabbix_globalmacro: + macro_name: low_space_limit:/home + macro_value: 10 + macro_type: text + register: zbxgmacro_context_new + +- name: assert that macro was created + assert: + that: zbxgmacro_context_new is changed + +- name: test - attempt to create same global macro with context and verify that it was converted to uppercase + zabbix_globalmacro: + macro_name: LOW_SPACE_LIMIT:/home + macro_value: 10 + macro_type: text + register: zbxgmacro_context_existing + +- name: assert that nothing has been changed + assert: + that: not zbxgmacro_context_existing is changed + +- name: test - attempt to delete all global macros + zabbix_globalmacro: + macro_name: "{{ item }}" + state: absent + loop: + - zbxgmacro_test01 + - LOW_SPACE_LIMIT:/home + - "{$ZBXGMACRO_TEST02}" + register: zbxgmacro_delete_existing + +- name: assert that all macros have been deleted + assert: + that: item.changed is sameas True + loop: "{{ zbxgmacro_delete_existing.results }}" + +- name: test - attempt to delete non-existing global macro + zabbix_globalmacro: + macro_name: zbxgmacro_test01 + state: absent + register: zbxgmacro_delete_missing + +- name: assert that nothing has been changed + assert: + that: not zbxgmacro_delete_missing is changed + +- name: test - attempt to create secret global macro + zabbix_globalmacro: + macro_name: zbxgmacro_test_secret + macro_value: 123 + macro_type: secret + macro_description: Global Macro description + register: zbxgmacro_secret + +- assert: + that: zbxgmacro_secret.changed is sameas True + +- name: test - attempt to create same global macro + zabbix_globalmacro: + macro_name: zbxgmacro_test_secret + macro_value: 123 + macro_type: secret + macro_description: Global Macro description + register: zbxgmacro_secret + +- assert: + that: zbxgmacro_secret.changed is sameas True + when: zabbix_version is version('5.0', '>=') + +- assert: + that: zbxgmacro_secret.changed is sameas False + when: zabbix_version is version('5.0', '<') + +- name: test - attempt to create vault global macro + zabbix_globalmacro: + macro_name: zbxgmacro_test_vault + macro_value: path/to/vault:zabbix + macro_type: vault + macro_description: Global Macro description + register: zbxgmacro_vault + +- assert: + that: zbxgmacro_vault.changed is sameas True + +- name: test - attempt to create same global macro + zabbix_globalmacro: + macro_name: zbxgmacro_test_vault + macro_value: path/to/vault:zabbix + macro_type: vault + macro_description: Global Macro description + register: zbxgmacro_vault + +- assert: + that: zbxgmacro_vault.changed is sameas False + +- name: delete all global macros + zabbix_globalmacro: + macro_name: "{{ item }}" + state: absent + loop: + - zbxgmacro_test_secret + - zbxgmacro_test_vault diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_group/meta/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_group/meta/main.yml new file mode 100644 index 000000000..acdb704c8 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_group/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - setup_zabbix diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_group/tasks/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_group/tasks/main.yml new file mode 100644 index 000000000..0f099d7c1 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_group/tasks/main.yml @@ -0,0 +1,88 @@ +--- +- name: test - create new Zabbix group + zabbix_group: + host_groups: + - zbxgrp_example_group01 + state: present + register: zbxgrp_new + +- name: assert that group was created + assert: + that: zbxgrp_new is changed + +- name: test - create simple zabbix host to assign to group + zabbix_host: + host_name: zbxgrp_example_host01 + host_groups: + - zbxgrp_example_group01 + interfaces: + - type: agent + main: 1 + dns: zbxgrp_example_host01 + state: present + register: zbxgrp_host_assignement + +- name: assert that host was assigned successfully + assert: + that: zbxgrp_host_assignement is changed + +- name: test - create same Zabbix group once again + zabbix_group: + host_groups: + - zbxgrp_example_group01 + state: present + register: zbxgrp_existing + +- name: assert that nothing has been changed + assert: + that: not zbxgrp_existing is changed + +- name: test - attempt to create new Zabbix group matching name of default Zabbix group + zabbix_group: + host_groups: + - Linux servers + state: present + register: zbxgrp_default_existing + +- name: assert that nothing has been changed + assert: + that: not zbxgrp_default_existing is changed + +- name: test - attempt to delete host group while its only group host has assigned + zabbix_group: + host_groups: + - zbxgrp_example_group01 + state: absent + register: zbxgrp_existing_delete_failed + ignore_errors: true + +- name: assert that group deletion failed + assert: + that: zbxgrp_existing_delete_failed is failed + +- name: delete helper zabbix host + zabbix_host: + host_name: zbxgrp_example_host01 + state: absent + +- name: test - attempt to delete previously created zabbix group + zabbix_group: + host_groups: + - zbxgrp_example_group01 + state: absent + register: zbxgrp_existing_delete + +- name: assert that group was deleted + assert: + that: zbxgrp_existing_delete is changed + +- name: test - attempt to delete non-existing zabbix group + zabbix_group: + host_groups: + - zbxgrp_example_group01 + state: absent + register: zbxgrp_missing_delete + +- name: assert that nothing has been changed + assert: + that: not zbxgrp_missing_delete is changed diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_group_info/meta/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_group_info/meta/main.yml new file mode 100644 index 000000000..acdb704c8 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_group_info/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - setup_zabbix diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_group_info/tasks/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_group_info/tasks/main.yml new file mode 100644 index 000000000..624679603 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_group_info/tasks/main.yml @@ -0,0 +1,50 @@ +--- +- name: test - create new Zabbix group + zabbix_group: + host_groups: + - zbxgrp_example_group01 + - zbxgrp_example_group02 + state: present + register: zbxgrp_new + +- name: assert that group was created + assert: + that: zbxgrp_new is changed + +- name: test - get one hostgroup info + zabbix_group_info: + hostgroup_name: + - zbxgrp_example_group01 + register: get_hostgorup_info_result + +- name: assert that one group was get + assert: + that: + - get_hostgorup_info_result.host_groups | length == 1 + - get_hostgorup_info_result.host_groups.0.name == 'zbxgrp_example_group01' + +- name: test - get two hostgroup info + zabbix_group_info: + hostgroup_name: + - zbxgrp_example_group01 + - zbxgrp_example_group02 + register: get_hostgorup_info_result + +- name: assert that two group was get + assert: + that: + - get_hostgorup_info_result.host_groups | length == 2 + - get_hostgorup_info_result.host_groups.0.name == 'zbxgrp_example_group01' + - get_hostgorup_info_result.host_groups.1.name == 'zbxgrp_example_group02' + +- name: test - delete Zabbix group + zabbix_group: + host_groups: + - zbxgrp_example_group01 + - zbxgrp_example_group02 + state: absent + register: delete_zbxgrp + +- name: assert that group was deleted + assert: + that: delete_zbxgrp is changed diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_host/meta/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_host/meta/main.yml new file mode 100644 index 000000000..acdb704c8 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_host/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - setup_zabbix diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_host/tasks/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_host/tasks/main.yml new file mode 100644 index 000000000..20755061f --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_host/tasks/main.yml @@ -0,0 +1,19 @@ +--- +- block: + # setup stuff not testing zabbix_host + - include_tasks: zabbix_host_setup.yml + + # zabbix_host module tests + - include_tasks: zabbix_host_tests.yml + + # documentation example tests + - include_tasks: zabbix_host_doc.yml + + # tear down stuff set up earlier + - include_tasks: zabbix_host_teardown.yml + always: + - name: "cleanup if tests failed" + zabbix_host: + host_name: ExampleHost + state: absent + ignore_errors: true diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_host/tasks/zabbix_host_doc.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_host/tasks/zabbix_host_doc.yml new file mode 100644 index 000000000..4415e2ca1 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_host/tasks/zabbix_host_doc.yml @@ -0,0 +1,77 @@ +--- +# These two tests are close to documentation example + +- name: Create a new host or update an existing host's info + zabbix_host: + host_name: ExampleHost1 + visible_name: ExampleName + description: My ExampleHost Description + host_groups: + - Linux servers + - Zabbix servers + link_templates: + - "{{ 'IMAP Service' if zabbix_version | float >= 5.2 else 'Template App IMAP Service' }}" + - "{{ 'NTP Service' if zabbix_version | float >= 5.2 else 'Template App NTP Service' }}" + status: enabled + state: present + inventory_mode: manual + inventory_zabbix: + tag: test-tag + alias: test-alias + notes: "Special Informations: test-info" + location: test-location + site_rack: test-rack + os: test-os + hardware: test-hw + ipmi_authtype: 2 + ipmi_privilege: 4 + ipmi_username: username + ipmi_password: password + interfaces: + - type: 1 + main: 1 + useip: 1 + ip: 10.1.1.1 + dns: "" + port: "10050" + - type: 4 + main: 1 + useip: 1 + ip: 10.1.1.1 + dns: "" + port: "12345" + macros: + - macro: '{$EXAMPLEMACRO}' + value: ExampleMacroValue + - macro: EXAMPLEMACRO2 + value: ExampleMacroValue2 + description: Example desc that work only with Zabbix 4.4 and higher + tags: + - tag: ExampleHostsTag + - tag: ExampleHostsTag2 + value: ExampleTagValue + register: zabbix_host1 + +- name: Update an existing host's tls settings + zabbix_host: + host_name: ExampleHost2 + visible_name: ExampleName2 + interfaces: + - type: 1 + main: 1 + useip: 1 + ip: 10.1.1.2 + dns: "" + port: "10050" + host_groups: + - Linux servers + tls_psk_identity: test + tls_connect: 2 + tls_psk: 123456789abcdef123456789abcdef12 + register: zabbix_host2 + +- name: expect both to succeed + assert: + that: + - "zabbix_host1 is changed" + - "zabbix_host2 is changed" diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_host/tasks/zabbix_host_setup.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_host/tasks/zabbix_host_setup.yml new file mode 100644 index 000000000..15e3e2fa5 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_host/tasks/zabbix_host_setup.yml @@ -0,0 +1,29 @@ +--- +# set up a zabbix proxy to test zabbix_host with + +- name: Create a new proxy + zabbix_proxy: + proxy_name: ExampleProxy + description: ExampleProxy + status: active + state: present + interface: + type: 0 + main: 1 + useip: 1 + ip: 10.5.6.7 + dns: "" + port: 10050 + register: zabbix_proxy + +- name: Create Templates + zabbix_template: + template_name: "{{ item }}" + template_groups: + - Templates + with_items: + - IMAP Service + - NTP Service + - HTTP Service + - LDAP Service + when: zabbix_version | float >= 6.4 diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_host/tasks/zabbix_host_teardown.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_host/tasks/zabbix_host_teardown.yml new file mode 100644 index 000000000..7eedcf12d --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_host/tasks/zabbix_host_teardown.yml @@ -0,0 +1,18 @@ +--- +# remove zabbix_proxy (hopefully) created earlier + +- name: remove proxy + zabbix_proxy: + proxy_name: ExampleProxy + state: absent + +- name: remove Templates + zabbix_template: + template_name: "{{ item }}" + state: absent + with_items: + - IMAP Service + - NTP Service + - HTTP Service + - LDAP Service + when: zabbix_version | float >= 6.4 diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_host/tasks/zabbix_host_tests.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_host/tasks/zabbix_host_tests.yml new file mode 100644 index 000000000..d72dbe318 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_host/tasks/zabbix_host_tests.yml @@ -0,0 +1,1385 @@ +--- +- name: "test: create host with many options set" + zabbix_host: + timeout: 30 # slower with py2.7 + host_name: ExampleHost + visible_name: ExampleName + description: My ExampleHost Description + host_groups: + - Linux servers + - Zabbix servers + link_templates: + - "{{ 'IMAP Service' if zabbix_version | float >= 5.2 else 'Template App IMAP Service' }}" + - "{{ 'NTP Service' if zabbix_version | float >= 5.2 else 'Template App NTP Service' }}" + status: enabled + state: present + inventory_mode: manual + inventory_zabbix: + tag: test-tag + alias: test-alias + notes: "Special Informations: test-info" + location: test-location + site_rack: test-rack + os: test-os + hardware: test-hw + interfaces: + - type: 1 + main: 1 + useip: 1 + ip: 10.1.1.1 + dns: "" + port: "10050" + - type: 1 + main: 0 + useip: 1 + ip: 10.1.1.1 + dns: "" + port: "{$MACRO}" + - type: 4 + main: 1 + useip: 1 + ip: 10.1.1.1 + dns: "" + port: "12345" + proxy: ExampleProxy + macros: + - macro: MACRO1 + value: test1 + - macro: '{$MACRO2}' + value: test2 + tags: + - tag: Tag1 + - tag: Tag2 + value: test2 + register: zabbix_host1 + +- name: expect to succeed and that things changed + assert: + that: + - "zabbix_host1 is changed" + +- name: "test: try to create the same host with the same settings" + zabbix_host: + timeout: 30 # slower with py2.7 + host_name: ExampleHost + visible_name: ExampleName + description: My ExampleHost Description + host_groups: + - Linux servers + - Zabbix servers + link_templates: + - "{{ 'IMAP Service' if zabbix_version | float >= 5.2 else 'Template App IMAP Service' }}" + - "{{ 'NTP Service' if zabbix_version | float >= 5.2 else 'Template App NTP Service' }}" + status: enabled + state: present + inventory_mode: manual + inventory_zabbix: + tag: test-tag + alias: test-alias + notes: "Special Informations: test-info" + location: test-location + site_rack: test-rack + os: test-os + hardware: test-hw + interfaces: + - type: 1 + main: 1 + useip: 1 + ip: 10.1.1.1 + dns: "" + port: "10050" + - type: 1 + main: 0 + useip: 1 + ip: 10.1.1.1 + dns: "" + port: "{$MACRO}" + - type: 4 + main: 1 + useip: 1 + ip: 10.1.1.1 + dns: "" + port: "12345" + proxy: ExampleProxy + macros: + - macro: MACRO1 + value: test1 + - macro: '{$MACRO2}' + value: test2 + tags: + - tag: Tag1 + - tag: Tag2 + value: test2 + register: zabbix_host1 + +- name: updating with same values should be idempotent + assert: + that: + - "not zabbix_host1 is changed" + +- name: "test: try to create the same host with the same settings and force false" + zabbix_host: + force: false + timeout: 30 # slower with py2.7 + host_name: ExampleHost + visible_name: ExampleName + description: My ExampleHost Description + host_groups: + - Linux servers + - Zabbix servers + link_templates: + - "{{ 'IMAP Service' if zabbix_version | float >= 5.2 else 'Template App IMAP Service' }}" + - "{{ 'NTP Service' if zabbix_version | float >= 5.2 else 'Template App NTP Service' }}" + status: enabled + state: present + inventory_mode: manual + inventory_zabbix: + tag: test-tag + alias: test-alias + notes: "Special Informations: test-info" + location: test-location + site_rack: test-rack + os: test-os + hardware: test-hw + interfaces: + - type: 1 + main: 1 + useip: 1 + ip: 10.1.1.1 + dns: "" + port: "10050" + - type: 1 + main: 0 + useip: 1 + ip: 10.1.1.1 + dns: "" + port: "{$MACRO}" + - type: 4 + main: 1 + useip: 1 + ip: 10.1.1.1 + dns: "" + port: "12345" + proxy: ExampleProxy + register: zabbix_host1 + +- name: updating with same values and force false should be idempotent + assert: + that: + - "not zabbix_host1 is changed" + +- name: "test: try to create the same host changing one parameter in the inventory with force false" + zabbix_host: + force: false + timeout: 30 # slower with py2.7 + host_name: ExampleHost + visible_name: ExampleName + description: My ExampleHost Description + host_groups: + - Linux servers + - Zabbix servers + link_templates: + - "{{ 'IMAP Service' if zabbix_version | float >= 5.2 else 'Template App IMAP Service' }}" + - "{{ 'NTP Service' if zabbix_version | float >= 5.2 else 'Template App NTP Service' }}" + status: enabled + state: present + inventory_mode: manual + inventory_zabbix: + tag: test-tag + alias: test-alias + notes: "Special Informations: test-info" + location: test-location + site_rack: test-rack + os: test-os + hardware: test-hw-modified + interfaces: + - type: 1 + main: 1 + useip: 1 + ip: 10.1.1.1 + dns: "" + port: "10050" + - type: 1 + main: 0 + useip: 1 + ip: 10.1.1.1 + dns: "" + port: "{$MACRO}" + - type: 4 + main: 1 + useip: 1 + ip: 10.1.1.1 + dns: "" + port: "12345" + proxy: ExampleProxy + register: zabbix_host1 + +- name: changing the value of an already defined inventory should work and mark task as changed + assert: + that: + - "zabbix_host1 is changed" + +- name: "test: change visible_name" + zabbix_host: + host_name: ExampleHost + visible_name: "ExampleName Changed" + register: zabbix_host1 + +- name: expect to succeed and that things changed + assert: + that: + - "zabbix_host1 is changed" + +- name: "test: change visible_name (again)" + zabbix_host: + host_name: ExampleHost + visible_name: "ExampleName Changed" + register: zabbix_host1 + +- name: updating with same values should be idempotent + assert: + that: + - "not zabbix_host1 is changed" + +- name: "test: change description" + zabbix_host: + host_name: ExampleHost + description: "My ExampleHost Description Changed" + register: zabbix_host1 + +- name: expect to succeed and that things changed + assert: + that: + - "zabbix_host1 is changed" + +- name: "test: change description (again)" + zabbix_host: + host_name: ExampleHost + description: "My ExampleHost Description Changed" + register: zabbix_host1 + +- name: updating with same values should be idempotent + assert: + that: + - "not zabbix_host1 is changed" + +- name: "test: change host groups (adding one group)" + zabbix_host: + host_name: ExampleHost + host_groups: + - Linux servers + - Zabbix servers + - Virtual machines + register: zabbix_host1 + +- name: expect to succeed and that things changed + assert: + that: + - "zabbix_host1 is changed" + +- name: "test: change host groups (remove one group)" + zabbix_host: + host_name: ExampleHost + host_groups: + - Linux servers + - Zabbix servers + register: zabbix_host1 + +- name: expect to succeed and that things changed + assert: + that: + - "zabbix_host1 is changed" + +- name: "test: change host groups (add one group using force=no)" + zabbix_host: + host_name: ExampleHost + host_groups: + - Virtual machines + force: false + register: zabbix_host1 + +- name: expect to succeed and that things changed + assert: + that: + - "zabbix_host1 is changed" + + +- name: "test: change host groups (check whether we are at three groups)" + zabbix_host: + host_name: ExampleHost + host_groups: + - Linux servers + - Zabbix servers + - Virtual machines + register: zabbix_host1 + +- name: expect to succeed and that things have not changed + assert: + that: + - "not zabbix_host1 is changed" + +- name: "test: change host groups (attempt to remove all host groups)" + zabbix_host: + host_name: ExampleHost + # list with empty value, expected: + host_groups: + - + register: zabbix_host1 + ignore_errors: true + +- name: expect to fail + assert: + that: + - "zabbix_host1 is failed" + +- name: "test: change host linked templates (same as before)" + zabbix_host: + host_name: ExampleHost + link_templates: + - "{{ 'IMAP Service' if zabbix_version | float >= 5.2 else 'Template App IMAP Service' }}" + - "{{ 'NTP Service' if zabbix_version | float >= 5.2 else 'Template App NTP Service' }}" + register: zabbix_host1 + +- name: expect to succeed and that things have not changed + assert: + that: + - "not zabbix_host1 is changed" + +- name: "test: change host linked templates (add one template)" + zabbix_host: + host_name: ExampleHost + link_templates: + - "{{ 'IMAP Service' if zabbix_version | float >= 5.2 else 'Template App IMAP Service' }}" + - "{{ 'NTP Service' if zabbix_version | float >= 5.2 else 'Template App NTP Service' }}" + - "{{ 'HTTP Service' if zabbix_version | float >= 5.2 else 'Template App HTTP Service' }}" + register: zabbix_host1 + +- name: expect to succeed and that things have changed + assert: + that: + - "zabbix_host1 is changed" + +- name: "test: change host linked templates (add one template, using force=no)" + zabbix_host: + host_name: ExampleHost + link_templates: + - "{{ 'LDAP Service' if zabbix_version | float >= 5.2 else 'Template App LDAP Service' }}" + force: false + register: zabbix_host1 + +- name: expect to succeed and that things have changed + assert: + that: + - "zabbix_host1 is changed" + +- name: "test: change host linked templates (make sure we are at 4 templates)" + zabbix_host: + host_name: ExampleHost + link_templates: + - "{{ 'IMAP Service' if zabbix_version | float >= 5.2 else 'Template App IMAP Service' }}" + - "{{ 'NTP Service' if zabbix_version | float >= 5.2 else 'Template App NTP Service' }}" + - "{{ 'HTTP Service' if zabbix_version | float >= 5.2 else 'Template App HTTP Service' }}" + - "{{ 'LDAP Service' if zabbix_version | float >= 5.2 else 'Template App LDAP Service' }}" + register: zabbix_host1 + +- name: expect to succeed and that things have not changed + assert: + that: + - "not zabbix_host1 is changed" + +- name: "test: change host linked templates (remove all templates)" + zabbix_host: + timeout: 60 # slower with py2.7 + host_name: ExampleHost + link_templates: + - + register: zabbix_host1 + +- name: expect to succeed and that things have changed + assert: + that: + - "zabbix_host1 is changed" + +- name: "test: change host linked templates (check we have no templates left)" + zabbix_host: + host_name: ExampleHost + link_templates: + - + register: zabbix_host1 + +- name: expect to succeed and that things have not changed + assert: + that: + - "not zabbix_host1 is changed" + +- name: "test: change host status" + zabbix_host: + host_name: ExampleHost + status: disabled + register: zabbix_host1 + +- name: expect to succeed and that things have changed + assert: + that: + - "zabbix_host1 is changed" + +- name: "test: change host status (again)" + zabbix_host: + host_name: ExampleHost + status: disabled + register: zabbix_host1 + +- name: expect to succeed and that things have not changed + assert: + that: + - "not zabbix_host1 is changed" + +- name: "test: change host inventory mode" + zabbix_host: + host_name: ExampleHost + inventory_mode: automatic + register: zabbix_host1 + +- name: expect to succeed and that things have changed + assert: + that: + - "zabbix_host1 is changed" + +- name: "test: change host inventory mode" + zabbix_host: + host_name: ExampleHost + inventory_mode: automatic + register: zabbix_host1 + +- name: expect to succeed and that things have not changed + assert: + that: + - "not zabbix_host1 is changed" + +- name: "test: change host inventory data (one field)" + zabbix_host: + host_name: ExampleHost + inventory_zabbix: + tag: test-tag-two + alias: test-alias + notes: "Special Informations: test-info" + location: test-location + site_rack: test-rack + os: test-os + hardware: test-hw + register: zabbix_host1 + +- name: expect to succeed and that things have changed + assert: + that: + - "zabbix_host1 is changed" + +- name: "test: change host inventory data (again)" + zabbix_host: + host_name: ExampleHost + inventory_zabbix: + tag: test-tag-two + alias: test-alias + notes: "Special Informations: test-info" + location: test-location + site_rack: test-rack + os: test-os + hardware: test-hw + register: zabbix_host1 + +- name: expect to succeed and that things have not changed + assert: + that: + - "not zabbix_host1 is changed" + +- name: "test: remove host proxy" + zabbix_host: + host_name: ExampleHost + proxy: '' + register: zabbix_host1 + +- name: expect to succeed and that things have changed + assert: + that: + - "zabbix_host1 is changed" + +- name: "test: add host proxy" + zabbix_host: + host_name: ExampleHost + proxy: ExampleProxy + register: zabbix_host1 + +- name: expect to succeed and that things have changed + assert: + that: + - "zabbix_host1 is changed" + +- name: "test: add host proxy (again)" + zabbix_host: + host_name: ExampleHost + proxy: ExampleProxy + register: zabbix_host1 + +- name: expect to succeed and that things have not changed + assert: + that: + - "not zabbix_host1 is changed" + +- name: "test: change tls certificate settings" + zabbix_host: + host_name: ExampleHost + tls_connect: 4 + tls_accept: 4 + tls_issuer: AcmeCorp + tls_subject: AcmeCorpServer + register: zabbix_host1 + +- name: expect to succeed and that things have changed + assert: + that: + - "zabbix_host1 is changed" + +- name: "test: change tls certificate settings (again)" + zabbix_host: + host_name: ExampleHost + tls_connect: 4 + tls_accept: 4 + tls_issuer: AcmeCorp + tls_subject: AcmeCorpServer + register: zabbix_host1 + +- name: expect to succeed and that things have not changed + assert: + that: + - "not zabbix_host1 is changed" + +- name: "test: change tls psk (write-only) settings" + zabbix_host: + host_name: ExampleHost + tls_connect: 2 + tls_accept: 2 + tls_psk_identity: test + tls_psk: 123456789abcdef123456789abcdef12 + register: zabbix_host1 + +- name: expect to succeed and that things have changed + assert: + that: zabbix_host1 is changed + +- name: "test: change tls psk (write-only) settings (again)" + zabbix_host: + host_name: ExampleHost + tls_connect: 2 + tls_accept: 2 + tls_psk_identity: test + tls_psk: 123456789abcdef123456789abcdef12 + register: zabbix_host1 + +- name: expect to succeed and that things have changed (tls_psk makes module non-idempotent) + assert: + that: zabbix_host1 is changed + when: zabbix_version is version('5.4', '>=') + +- name: expect to succeed and that things have not changed + assert: + that: zabbix_host1 is not changed + when: zabbix_version is version('5.4', '<') + +- name: "test: change interface settings (remove one)" + zabbix_host: + host_name: ExampleHost + interfaces: + - type: 1 + main: 1 + useip: 1 + ip: 10.1.1.1 + dns: "" + port: "10050" + register: zabbix_host1 + +- name: expect to succeed and that things have changed + assert: + that: + - "zabbix_host1 is changed" + +- name: "test: change interface settings (again)" + zabbix_host: + host_name: ExampleHost + interfaces: + - type: 1 + main: 1 + useip: 1 + ip: 10.1.1.1 + dns: "" + port: "10050" + register: zabbix_host1 + +- name: expect to succeed and that things have not changed + assert: + that: + - "not zabbix_host1 is changed" + +- name: "test: change interface settings (add one interface using force=no)" + zabbix_host: + host_name: ExampleHost + interfaces: + - type: 4 + main: 1 + useip: 1 + ip: 10.1.1.1 + dns: "" + port: "12345" + force: false + register: zabbix_host1 + +- name: expect to succeed and that things have changed + assert: + that: + - "zabbix_host1 is changed" + +- name: "test: change interface settings (verify that we are at two interfaces)" + zabbix_host: + host_name: ExampleHost + interfaces: + - type: 1 + main: 1 + useip: 1 + ip: 10.1.1.1 + dns: "" + port: "10050" + - type: 4 + main: 1 + useip: 1 + ip: 10.1.1.1 + dns: "" + port: "12345" + register: zabbix_host1 + +- name: expect to succeed and that things have not changed + assert: + that: + - "not zabbix_host1 is changed" + +- name: "test: configure interface to useip=1 but provide no ip" + zabbix_host: + host_name: ExampleHost + interfaces: + - type: 1 + main: 1 + useip: 1 + port: "10050" + - type: 4 + main: 1 + useip: 1 + ip: 10.1.1.1 + port: "12345" + register: zabbix_host1 + ignore_errors: true + +- name: expect to fail + assert: + that: + - "zabbix_host1 is failed" + +- name: "test: configure interface to useip=0 but provide no dns" + zabbix_host: + host_name: ExampleHost + interfaces: + - type: 1 + main: 1 + useip: 0 + ip: 10.1.1.1 + port: "10050" + - type: 4 + main: 1 + useip: 1 + ip: 10.1.1.1 + port: "12345" + register: zabbix_host1 + ignore_errors: true + +- name: expect to fail + assert: + that: + - "zabbix_host1 is failed" + +- when: zabbix_version is version("5.0", ">=") + block: + - name: "test: configure SNMPv2 interface without details (fail)" + zabbix_host: + host_name: ExampleHost + interfaces: + - type: 1 + main: 1 + useip: 1 + ip: 10.1.1.1 + port: "10050" + - type: 2 + main: 1 + useip: 1 + ip: 10.1.1.1 + port: "161" + register: zabbix_host1 + ignore_errors: true + + - name: expect to fail + assert: + that: + - "zabbix_host1 is failed" + + - name: "test: configure details for SNMPv2 interface" + zabbix_host: + host_name: ExampleHost + interfaces: + - type: 1 + main: 1 + useip: 1 + ip: 10.1.1.1 + port: "10050" + - type: 2 + main: 1 + useip: 1 + ip: 10.1.1.1 + port: "161" + details: + version: 2 + community: Community String + register: zabbix_host1 + + - name: expect to succeed and that things have changed + assert: + that: + - "zabbix_host1 is changed" + + - name: "test: configure details for SNMPv2 interface (again)" + zabbix_host: + host_name: ExampleHost + interfaces: + - type: 1 + main: 1 + useip: 1 + ip: 10.1.1.1 + port: "10050" + - type: 2 + main: 1 + useip: 1 + ip: 10.1.1.1 + port: "161" + details: + version: 2 + community: Community String + register: zabbix_host1 + + - name: expect to succeed and that things have not changed + assert: + that: + - "zabbix_host1 is not changed" + + - name: "test: configure SNMPv2 interface with the same options and force=False " + zabbix_host: + host_name: ExampleHost + force: False + interfaces: + - type: 1 + main: 1 + useip: 1 + ip: 10.1.1.1 + port: "10050" + - type: 2 + main: 1 + useip: 1 + ip: 10.1.1.1 + port: "161" + details: + version: 2 + community: Community String + register: zabbix_host1 + + - name: expect to succeed and that things have not changed + assert: + that: + - "zabbix_host1 is not changed" + + - name: "test: update details for SNMPv2 interface with bulk sub option" + zabbix_host: + host_name: ExampleHost + interfaces: + - type: 1 + main: 1 + useip: 1 + ip: 10.1.1.1 + port: "10050" + - type: 2 + main: 1 + useip: 1 + ip: 10.1.1.1 + port: "161" + details: + version: 2 + community: Community String + bulk: 0 + register: zabbix_host1 + + - name: expect to succeed and that things have changed + assert: + that: + - "zabbix_host1 is changed" + + - name: "test: configure details for SNMPv3 interface" + zabbix_host: + host_name: ExampleHost + interfaces: + - type: 1 + main: 1 + useip: 1 + ip: 10.1.1.1 + port: "10050" + - type: 2 + main: 1 + useip: 1 + ip: 10.1.1.1 + port: "161" + details: + version: 3 + contextname: snmp_context + securityname: SNMP3 sec name + securitylevel: 0 + register: zabbix_host1 + + - name: expect to succeed and that things have changed + assert: + that: + - "zabbix_host1 is changed" + + - name: "test: configure details for SNMPv3 interface (again)" + zabbix_host: + host_name: ExampleHost + interfaces: + - type: 1 + main: 1 + useip: 1 + ip: 10.1.1.1 + port: "10050" + - type: 2 + main: 1 + useip: 1 + ip: 10.1.1.1 + port: "161" + details: + version: 3 + contextname: snmp_context + securityname: SNMP3 sec name + securitylevel: 0 + register: zabbix_host1 + + - name: expect to succeed and that things have not changed + assert: + that: + - "zabbix_host1 is not changed" + + - name: "test: update details for SNMPv3 interface" + zabbix_host: + host_name: ExampleHost + interfaces: + - type: 1 + main: 1 + useip: 1 + ip: 10.1.1.1 + port: "10050" + - type: 2 + main: 1 + useip: 1 + ip: 10.1.1.1 + port: "161" + details: + version: 3 + contextname: snmp_context + securityname: SNMP3 sec name + securitylevel: 2 + authprotocol: "{{ 2 if zabbix_version | float >= 5.4 else 0 }}" + authpassphrase: secret_auth_passphrase + privprotocol: "{{ 2 if zabbix_version | float >= 5.4 else 0 }}" + privpassphrase: secret_priv_passphrase + register: zabbix_host1 + + - name: expect to succeed and that things have changed + assert: + that: + - "zabbix_host1 is changed" + +# https://github.com/ansible-collections/community.zabbix/pull/391 +- name: "reset interfaces to two of the same type" + zabbix_host: + host_name: ExampleHost + interfaces: + - type: "1" + main: 1 + useip: 1 + ip: 127.0.0.1 + - type: "1" + useip: 1 + ip: 127.0.1.1 + register: zabbix_host1 + +- name: expect to succeed and that things have changed + assert: + that: + - "zabbix_host1 is changed" + +- name: "reset interfaces to two of the same type (again)" + zabbix_host: + host_name: ExampleHost + interfaces: + - type: "1" + main: 1 + useip: 1 + ip: 127.0.0.1 + - type: "1" + useip: 1 + ip: 127.0.1.1 + register: zabbix_host1 + +- name: expect to succeed and that things have not changed + assert: + that: + - "zabbix_host1 is not changed" + +- name: "test: add IPMI settings" + zabbix_host: + host_name: ExampleHost + ipmi_authtype: 2 + ipmi_privilege: 4 + ipmi_username: username + ipmi_password: password + register: zabbix_host1 + +- name: expect to succeed and that things have changed + assert: + that: + - "zabbix_host1 is changed" + +- name: "test: add IPMI settings again" + zabbix_host: + host_name: ExampleHost + ipmi_authtype: 2 + ipmi_privilege: 4 + ipmi_username: username + ipmi_password: password + register: zabbix_host1 + +- name: expect to succeed and that things have not changed + assert: + that: + - "zabbix_host1 is not changed" + +- name: "test: verify that an empty change is idempotent" + zabbix_host: + host_name: ExampleHost + register: zabbix_host1 + +- name: expect to succeed and that things have not changed + assert: + that: + - "zabbix_host1 is not changed" + +- name: "test: IPMI set default values" + zabbix_host: + host_name: ExampleHost + ipmi_authtype: -1 + ipmi_privilege: 2 + ipmi_username: "" + ipmi_password: "" + register: zabbix_host1 + +- name: expect to succeed and that things have changed + assert: + that: + - "zabbix_host1 is changed" + +- name: "test: IPMI set default values (again)" + zabbix_host: + host_name: ExampleHost + ipmi_authtype: -1 + ipmi_privilege: 2 + ipmi_username: "" + ipmi_password: "" + register: zabbix_host1 + +- name: expect to succeed and that things have not changed + assert: + that: + - "zabbix_host1 is not changed" + +- name: "test: change host inventory mode to disabled" + zabbix_host: + host_name: ExampleHost + inventory_mode: disabled + register: zabbix_host1 + +- name: expect to succeed and that things have changed + assert: + that: + - "zabbix_host1 is changed" + +- name: "test: change host inventory mode to manual" + zabbix_host: + host_name: ExampleHost + inventory_mode: manual + register: zabbix_host1 + +- name: expect to succeed and that things have changed + assert: + that: + - "zabbix_host1 is changed" + +- name: "test: add new set of user macros to the host" + zabbix_host: + host_name: ExampleHost + macros: + - macro: '{$NEWMACRO1}' + value: test123 + - macro: NEWMACRO2 + value: abc + register: zabbix_host1 + +- name: expect to succeed and that things have changed + assert: + that: + - "zabbix_host1 is changed" + +- name: "test: add new set of user macros to the host (again - lowercase)" + zabbix_host: + host_name: ExampleHost + macros: + - macro: '{$newmacro1}' + value: test123 + - macro: newmacro2 + value: abc + register: zabbix_host1 + +- name: expect to succeed and that things have not changed + assert: + that: + - "zabbix_host1 is not changed" + +- name: "test: update one of the user macros present on the host" + zabbix_host: + host_name: ExampleHost + macros: + - macro: '{$NEWMACRO1}' + value: test1234 + - macro: NEWMACRO2 + value: abc + register: zabbix_host1 + +- name: expect to succeed and that things have changed + assert: + that: + - "zabbix_host1 is changed" + +# The description of tag is available since Zabbix version 4.4 +- when: zabbix_version is version("4.4", ">=") + block: + - name: "test: update one of the user macros with description" + zabbix_host: + host_name: ExampleHost + macros: + - macro: '{$NEWMACRO1}' + value: test1234 + description: Example Description + - macro: NEWMACRO2 + value: abc + register: zabbix_host1 + + - name: expect to succeed and that things have changed + assert: + that: + - "zabbix_host1 is changed" + + - name: "test: update one of the user macros with description (again)" + zabbix_host: + host_name: ExampleHost + macros: + - macro: '{$NEWMACRO1}' + value: test1234 + description: Example Description + - macro: NEWMACRO2 + value: abc + register: zabbix_host1 + + - name: expect to succeed and that things have not changed + assert: + that: + - "zabbix_host1 is not changed" + + - name: "test: update one of the user macros by removing description" + zabbix_host: + host_name: ExampleHost + macros: + - macro: '{$NEWMACRO1}' + value: test1234 + - macro: NEWMACRO2 + value: abc + register: zabbix_host1 + + - name: expect to succeed and that things have changed + assert: + that: + - "zabbix_host1 is changed" + +- name: "test: add user macro while keeping previous ones with force=no" + zabbix_host: + host_name: ExampleHost + force: false + macros: + - macro: '{$NEWMACRO3}' + value: testing + register: zabbix_host1 + +- name: expect to succeed and that things have changed + assert: + that: + - "zabbix_host1 is changed" + +- name: "test: add user macro while keeping previous ones with force=no (again)" + zabbix_host: + host_name: ExampleHost + force: false + macros: + - macro: '{$NEWMACRO3}' + value: testing + register: zabbix_host1 + +- name: expect to succeed and that things have not changed + assert: + that: + - "zabbix_host1 is not changed" + +- name: "test: add the same user macros (again)" + zabbix_host: + host_name: ExampleHost + macros: + - macro: '{$NEWMACRO1}' + value: test1234 + - macro: NEWMACRO2 + value: abc + - macro: '{$NEWMACRO3}' + value: testing + register: zabbix_host1 + +- name: expect to succeed and that things have not changed + assert: + that: + - "zabbix_host1 is not changed" + +# type for macros added in 5.0 +- when: zabbix_version is version("5.0", ">=") + block: + - name: "test: add new user macro with type secret" + zabbix_host: + host_name: ExampleHost + macros: + - macro: '{$NEWMACROSECRET}' + value: secretvalue + type: secret + register: zabbix_host1 + + - name: expect to succeed and that things have changed + assert: + that: + - "zabbix_host1 is changed" + + - name: "test: add new user macro with type secret (again)" + zabbix_host: + host_name: ExampleHost + macros: + - macro: '{$NEWMACROSECRET}' + value: secretvalue + type: secret + register: zabbix_host1 + + - name: expect to succeed and that things have changed as it has secret value + assert: + that: + - "zabbix_host1 is changed" + +- name: "test: wipe out all of the user macros" + zabbix_host: + host_name: ExampleHost + macros: [] + register: zabbix_host1 + +- name: expect to succeed and that things have changed + assert: + that: + - "zabbix_host1 is changed" + +- name: "test: wipe out all of the user macros (again)" + zabbix_host: + host_name: ExampleHost + macros: [] + register: zabbix_host1 + +- name: expect to succeed and that things have not changed + assert: + that: + - "zabbix_host1 is not changed" + +# The tag function is available since Zabbix version 4.4 +- when: zabbix_version is version("4.4", ">=") + block: + - name: "test: add new set of tags to the host" + zabbix_host: + host_name: ExampleHost + tags: + - tag: NEWTAG1 + - tag: NewTag2 + value: abc + register: zabbix_host1 + + - name: expect to succeed and that things have changed + assert: + that: + - "zabbix_host1 is changed" + + - name: "test: add new set of tags to the host (again)" + zabbix_host: + host_name: ExampleHost + tags: + - tag: NEWTAG1 + - tag: NewTag2 + value: abc + register: zabbix_host1 + + - name: expect to succeed and that things have not changed + assert: + that: + - "zabbix_host1 is not changed" + + - name: "test: update one of the tags present on the host" + zabbix_host: + host_name: ExampleHost + tags: + - tag: NEWTAG1 + - tag: NewTag2 + value: abcd + register: zabbix_host1 + + - name: expect to succeed and that things have changed + assert: + that: + - "zabbix_host1 is changed" + + - name: "test: add tag while keeping previous ones with force=no" + zabbix_host: + host_name: ExampleHost + force: false + tags: + - tag: newtag3 + value: testing + register: zabbix_host1 + + - name: expect to succeed and that things have changed + assert: + that: + - "zabbix_host1 is changed" + + - name: "test: add the same tags (again)" + zabbix_host: + host_name: ExampleHost + tags: + - tag: NEWTAG1 + - tag: NewTag2 + value: abcd + - tag: newtag3 + value: testing + register: zabbix_host1 + + - name: expect to succeed and that things have not changed + assert: + that: + - "zabbix_host1 is not changed" + + - name: "test: wipe out all of the tags" + zabbix_host: + host_name: ExampleHost + tags: [] + register: zabbix_host1 + + - name: expect to succeed and that things have changed + assert: + that: + - "zabbix_host1 is changed" + +- name: "test: wipe out all of the tags (again)" + zabbix_host: + host_name: ExampleHost + tags: [] + register: zabbix_host1 + +- name: expect to succeed and that things have not changed + assert: + that: + - "zabbix_host1 is not changed" + +- name: "test: attempt to delete host created earlier" + zabbix_host: + host_name: ExampleHost + state: absent + register: zabbix_host1 + +- name: deleting a host is a change, right? + assert: + that: + - "zabbix_host1 is changed" + +- name: "test: attempt deleting a non-existant host" + zabbix_host: + host_name: ExampleHost + state: absent + register: zabbix_host1 + +- name: deleting a non-existant host is not a change, right? + assert: + that: + - "not zabbix_host1 is changed" + +- when: zabbix_version is version('5.2', '>=') + block: + - name: "test: create host without host interfaces" + zabbix_host: + host_name: ExampleHost + visible_name: ExampleName + description: My ExampleHost Description + host_groups: + - Linux servers + status: disabled + state: present + register: zbx_host_create_interfaceless + + - name: verify host was created without interfaces + assert: + that: zbx_host_create_interfaceless is changed + + - name: "test: create host without host interfaces (again)" + zabbix_host: + server_url: "{{ zabbix_api_server_url }}" + login_user: "{{ zabbix_api_login_user }}" + login_password: "{{ zabbix_api_login_pass }}" + host_name: ExampleHost + visible_name: ExampleName + description: My ExampleHost Description + host_groups: + - Linux servers + status: disabled + state: present + register: zbx_host_create_interfaceless + + - name: expect to succeed and that things have not changed + assert: + that: zbx_host_create_interfaceless is not changed + + - name: "cleanup" + zabbix_host: + host_name: ExampleHost + state: absent diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_host_info/meta/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_host_info/meta/main.yml new file mode 100644 index 000000000..acdb704c8 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_host_info/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - setup_zabbix diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_host_info/tasks/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_host_info/tasks/main.yml new file mode 100644 index 000000000..dfcaf097d --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_host_info/tasks/main.yml @@ -0,0 +1,185 @@ +--- +- name: "test - Prepare host for zabbix_host_info module" + zabbix_host: + host_name: ExampleHostForHostInfoModule + visible_name: ExampleHostForHostInfoModuleName + description: Test Host + host_groups: + - Linux servers + - Hypervisors + link_templates: + - "{{ 'Zabbix server health' if zabbix_version | float >= 5.4 else 'Template App Zabbix Server' }}" + status: enabled + inventory_mode: manual + inventory_zabbix: + tag: tag1 + os: Linux + interfaces: + - type: 1 + main: 1 + useip: 1 + ip: 192.168.0.1 + dns: "" + port: 10050 + state: present + register: prepare_host_result + +- assert: + that: + - prepare_host_result.changed is sameas true + +- name: "test - Gather zabbix host facts using environment variables" + community.zabbix.zabbix_host_info: + host_name: ExampleHostForHostInfoModule + register: env_vars_usage + environment: + ZABBIX_VALIDATE_CERTS: false + +- assert: + that: + - env_vars_usage.hosts[0].name == "ExampleHostForHostInfoModuleName" + +- name: "test - Set default parameters to zabbix_host_info" + module_defaults: + community.zabbix.zabbix_host_info: + host_name: ExampleHostForHostInfoModule + + block: + - name: "test - Gather all facts of zabbix host" + zabbix_host_info: + register: gather_all_facts_result + + - when: zabbix_version is version('4.0', '<=') + assert: + that: + - gather_all_facts_result.hosts | length == 1 + - gather_all_facts_result.hosts.0.host == "ExampleHostForHostInfoModule" + - gather_all_facts_result.hosts.0.name == "ExampleHostForHostInfoModuleName" + - gather_all_facts_result.hosts.0.description == "Test Host" + - gather_all_facts_result.hosts.0.groups.0.name == "Linux servers" + - gather_all_facts_result.hosts.0.groups.1.name == "Hypervisors" + - gather_all_facts_result.hosts.0.parentTemplates.0.name == "Template App Zabbix Server" + - gather_all_facts_result.hosts.0.status == "0" + - gather_all_facts_result.hosts.0.inventory.inventory_mode == "0" + - gather_all_facts_result.hosts.0.inventory.tag == "tag1" + - gather_all_facts_result.hosts.0.inventory.os == "Linux" + - gather_all_facts_result.hosts.0.hostinterfaces.0.dns == "" + - gather_all_facts_result.hosts.0.hostinterfaces.0.ip == "192.168.0.1" + - gather_all_facts_result.hosts.0.hostinterfaces.0.main == "1" + - gather_all_facts_result.hosts.0.hostinterfaces.0.port == "10050" + - gather_all_facts_result.hosts.0.hostinterfaces.0.type == "1" + - gather_all_facts_result.hosts.0.hostinterfaces.0.useip == "1" + + - when: zabbix_version is version('4.4', '>=') and zabbix_version is version('5.0', '<=') + assert: + that: + - gather_all_facts_result.hosts | length == 1 + - gather_all_facts_result.hosts.0.host == "ExampleHostForHostInfoModule" + - gather_all_facts_result.hosts.0.name == "ExampleHostForHostInfoModuleName" + - gather_all_facts_result.hosts.0.description == "Test Host" + - gather_all_facts_result.hosts.0.groups.0.name == "Linux servers" + - gather_all_facts_result.hosts.0.groups.1.name == "Hypervisors" + - gather_all_facts_result.hosts.0.parentTemplates.0.name == "Template App Zabbix Server" + - gather_all_facts_result.hosts.0.status == "0" + - gather_all_facts_result.hosts.0.inventory_mode == "0" + - gather_all_facts_result.hosts.0.inventory.tag == "tag1" + - gather_all_facts_result.hosts.0.inventory.os == "Linux" + - gather_all_facts_result.hosts.0.hostinterfaces.0.dns == "" + - gather_all_facts_result.hosts.0.hostinterfaces.0.ip == "192.168.0.1" + - gather_all_facts_result.hosts.0.hostinterfaces.0.main == "1" + - gather_all_facts_result.hosts.0.hostinterfaces.0.port == "10050" + - gather_all_facts_result.hosts.0.hostinterfaces.0.type == "1" + - gather_all_facts_result.hosts.0.hostinterfaces.0.useip == "1" + + - when: zabbix_version is version('5.4', '>=') and zabbix_version is version('6.2', '<') + assert: + that: + - gather_all_facts_result.hosts | length == 1 + - gather_all_facts_result.hosts.0.host == "ExampleHostForHostInfoModule" + - gather_all_facts_result.hosts.0.name == "ExampleHostForHostInfoModuleName" + - gather_all_facts_result.hosts.0.description == "Test Host" + - gather_all_facts_result.hosts.0.groups.0.name == "Linux servers" + - gather_all_facts_result.hosts.0.groups.1.name == "Hypervisors" + - gather_all_facts_result.hosts.0.parentTemplates.0.name == "Zabbix server health" + - gather_all_facts_result.hosts.0.status == "0" + - gather_all_facts_result.hosts.0.inventory_mode == "0" + - gather_all_facts_result.hosts.0.inventory.tag == "tag1" + - gather_all_facts_result.hosts.0.inventory.os == "Linux" + - gather_all_facts_result.hosts.0.hostinterfaces.0.dns == "" + - gather_all_facts_result.hosts.0.hostinterfaces.0.ip == "192.168.0.1" + - gather_all_facts_result.hosts.0.hostinterfaces.0.main == "1" + - gather_all_facts_result.hosts.0.hostinterfaces.0.port == "10050" + - gather_all_facts_result.hosts.0.hostinterfaces.0.type == "1" + - gather_all_facts_result.hosts.0.hostinterfaces.0.useip == "1" + + - when: zabbix_version is version('6.2', '>=') + assert: + that: + - gather_all_facts_result.hosts | length == 1 + - gather_all_facts_result.hosts.0.host == "ExampleHostForHostInfoModule" + - gather_all_facts_result.hosts.0.name == "ExampleHostForHostInfoModuleName" + - gather_all_facts_result.hosts.0.description == "Test Host" + - gather_all_facts_result.hosts.0.groups.0.name == "Hypervisors" + - gather_all_facts_result.hosts.0.groups.1.name == "Linux servers" + - gather_all_facts_result.hosts.0.parentTemplates.0.name == "Zabbix server health" + - gather_all_facts_result.hosts.0.status == "0" + - gather_all_facts_result.hosts.0.inventory_mode == "0" + - gather_all_facts_result.hosts.0.inventory.tag == "tag1" + - gather_all_facts_result.hosts.0.inventory.os == "Linux" + - gather_all_facts_result.hosts.0.hostinterfaces.0.dns == "" + - gather_all_facts_result.hosts.0.hostinterfaces.0.ip == "192.168.0.1" + - gather_all_facts_result.hosts.0.hostinterfaces.0.main == "1" + - gather_all_facts_result.hosts.0.hostinterfaces.0.port == "10050" + - gather_all_facts_result.hosts.0.hostinterfaces.0.type == "1" + - gather_all_facts_result.hosts.0.hostinterfaces.0.useip == "1" + + - name: "test - Gather facts of zabbix host with host_inventory" + zabbix_host_info: + host_inventory: + - tag + - os + register: gather_facts_with_host_inventory_result + + - when: zabbix_version is version('3.4', '<=') + assert: + that: + - gather_facts_with_host_inventory_result.hosts.0.inventory | length == 3 + - gather_facts_with_host_inventory_result.hosts.0.inventory.tag == "tag1" + - gather_facts_with_host_inventory_result.hosts.0.inventory.os == "Linux" + + - when: zabbix_version is version('4.0', '>=') + assert: + that: + - gather_facts_with_host_inventory_result.hosts.0.inventory | length == 2 + - gather_facts_with_host_inventory_result.hosts.0.inventory.tag == "tag1" + - gather_facts_with_host_inventory_result.hosts.0.inventory.os == "Linux" + + - name: "test - Partial match of zabbix host name" + zabbix_host_info: + host_name: HostForHostInfo + exact_match: false + register: partial_match_result + + - assert: + that: + - partial_match_result.hosts | length == 1 + + - name: "test - Exact match of zabbix host name" + zabbix_host_info: + exact_match: true + register: exact_match_result + + - assert: + that: + - exact_match_result.hosts | length == 1 + + - name: "test - Exact match of zabbix host name(expectations - host not found)" + zabbix_host_info: + host_name: HostForHostInfo + exact_match: true + register: exact_match_host_not_found_result + ignore_errors: true + + - assert: + that: + - exact_match_host_not_found_result.failed is sameas true diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_hostmacro/meta/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_hostmacro/meta/main.yml new file mode 100644 index 000000000..acdb704c8 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_hostmacro/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - setup_zabbix diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_hostmacro/tasks/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_hostmacro/tasks/main.yml new file mode 100644 index 000000000..1a9d81eff --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_hostmacro/tasks/main.yml @@ -0,0 +1,171 @@ +--- +- name: create helper zabbix host + zabbix_host: + host_name: zbx_hmacro_host01 + host_groups: + - Linux servers + interfaces: + - type: agent + main: 1 + dns: zbx_hmacro_host01 + +- name: test - attempt to create new host macro + zabbix_hostmacro: + host_name: zbx_hmacro_host01 + macro_name: zbxhmacro_test01 + macro_value: 123 + register: zbxhmacro_new + +- name: assert that macro was created + assert: + that: zbxhmacro_new is changed + +- name: test - attempt to create same host macro + zabbix_hostmacro: + host_name: zbx_hmacro_host01 + macro_name: zbxhmacro_test01 + macro_value: 123 + register: zbxhmacro_existing + +- name: assert that nothing has been changed + assert: + that: not zbxhmacro_existing is changed + +- name: test - attempt to create same host macro in zabbix native format + zabbix_hostmacro: + host_name: zbx_hmacro_host01 + macro_name: "{$ZBXHMACRO_TEST01}" + macro_value: 123 + register: zbxhmacro_existing_native + +- name: assert that nothing has been changed + assert: + that: not zbxhmacro_existing_native is changed + +- name: test - attempt to create new host macro in zabbix native format + zabbix_hostmacro: + host_name: zbx_hmacro_host01 + macro_name: "{$ZBXHMACRO_TEST02}" + macro_value: abcd + register: zbxhmacro_new_native + +- name: assert that nothing macro was created + assert: + that: zbxhmacro_new_native is changed + +- name: test - attempt to update host macro with string value while force=no + zabbix_hostmacro: + host_name: zbx_hmacro_host01 + macro_name: zbxhmacro_test01 + macro_value: abc + force: false + register: zbxhmacro_update_noforce + +- name: assert that nothing has been changed + assert: + that: not zbxhmacro_update_noforce is changed + +- name: test - attempt to update host macro with string value + zabbix_hostmacro: + host_name: zbx_hmacro_host01 + macro_name: zbxhmacro_test01 + macro_value: abc + register: zbxhmacro_update + ignore_errors: true + +- name: assert that host macro was updated + assert: + that: zbxhmacro_update is changed + +- name: test - attempt to create host macro with context + zabbix_hostmacro: + host_name: zbx_hmacro_host01 + macro_name: low_space_limit:/home + macro_value: 10 + register: zbxhmacro_context_new + +- name: assert that macro was created + assert: + that: zbxhmacro_context_new is changed + +- name: test - attempt to create same host macro with context and verify that it was converted to uppercase + zabbix_hostmacro: + host_name: zbx_hmacro_host01 + macro_name: LOW_SPACE_LIMIT:/home + macro_value: 10 + register: zbxhmacro_context_existing + +- name: assert that nothing has been changed + assert: + that: not zbxhmacro_context_existing is changed + +- name: test - attempt to delete all host macros + zabbix_hostmacro: + host_name: zbx_hmacro_host01 + macro_name: "{{ item }}" + state: absent + loop: + - zbxhmacro_test01 + - LOW_SPACE_LIMIT:/home + - "{$ZBXHMACRO_TEST02}" + register: zbxhmacro_delete_existing + +- name: assert that all macros have been deleted + assert: + that: item.changed is sameas True + loop: "{{ zbxhmacro_delete_existing.results }}" + +- name: test - attempt to delete non-existing host macro + zabbix_hostmacro: + host_name: zbx_hmacro_host01 + macro_name: zbxhmacro_test01 + state: absent + register: zbxhmacro_delete_missing + +- name: assert that nothing has been changed + assert: + that: not zbxhmacro_delete_missing is changed + +- name: test - do not run host macro secret tests for Zabbix < 5.0 + meta: end_play + when: zabbix_version is version('5.0', '<') + +- name: test - attempt to create host macro with type secret + zabbix_hostmacro: + host_name: zbx_hmacro_host01 + macro_name: zbxhmacro_test03 + macro_value: abcd + macro_type: secret + register: zbxhmacro_update + ignore_errors: true + +- name: assert that host macro was updated + assert: + that: zbxhmacro_update is changed + +- name: test - attempt to update host macro with type secret with same value + zabbix_hostmacro: + host_name: zbx_hmacro_host01 + macro_name: zbxhmacro_test03 + macro_value: abcd + macro_type: secret + register: zbxhmacro_update + ignore_errors: true + +- name: assert that host macro was updated + assert: + that: zbxhmacro_update is changed + +- name: test - attempt to delete host macros type secret + zabbix_hostmacro: + host_name: zbx_hmacro_host01 + macro_name: "{{ item }}" + state: absent + loop: + - zbxhmacro_test03 + register: zbxhmacro_delete_existing + +- name: assert that all macros have been deleted + assert: + that: item.changed is sameas True + loop: "{{ zbxhmacro_delete_existing.results }}" diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_housekeeping/meta/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_housekeeping/meta/main.yml new file mode 100644 index 000000000..acdb704c8 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_housekeeping/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - setup_zabbix diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_housekeeping/tasks/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_housekeeping/tasks/main.yml new file mode 100644 index 000000000..6189c1d77 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_housekeeping/tasks/main.yml @@ -0,0 +1,96 @@ +--- +- name: test - do not run tests with < Zabbix 4.0 + meta: end_play + when: zabbix_version is version('4.0', '<') + +- when: zabbix_version is version('5.2', '<') + name: Unsupport Zabbix version (<5.2) + block: + - name: test fail to update housekeeping + community.zabbix.zabbix_housekeeping: + hk_events_mode: true + register: zbxhk_update_result + ignore_errors: true + + - assert: + that: zbxhk_update_result.failed is sameas True + +- when: zabbix_version is version('5.2', '>=') + name: Support Zabbix version (>=5.2) + block: + - name: test update housekeeping parameters. + community.zabbix.zabbix_housekeeping: + hk_events_mode: yes + hk_events_trigger: 365d + hk_events_service: 1w + hk_events_internal: 86400s + hk_events_discovery: 48h + hk_events_autoreg: 1440m + hk_services_mode: yes + hk_services: 365d + hk_audit_mode: yes + hk_audit: 365d + hk_sessions_mode: yes + hk_sessions: 365d + hk_history_mode: yes + hk_history_global: yes + hk_history: 365d + hk_trends_mode: yes + hk_trends_global: yes + hk_trends: 365d + compression_status: off + compress_older: 7d + register: zbxhk_update_result + + - assert: + that: zbxhk_update_result.changed is sameas True + + - name: test update housekeeping parameters (again). + community.zabbix.zabbix_housekeeping: + hk_events_mode: yes + hk_events_trigger: 365d + hk_events_service: 1w + hk_events_internal: 86400s + hk_events_discovery: 48h + hk_events_autoreg: 1440m + hk_services_mode: yes + hk_services: 365d + hk_audit_mode: yes + hk_audit: 365d + hk_sessions_mode: yes + hk_sessions: 365d + hk_history_mode: yes + hk_history_global: yes + hk_history: 365d + hk_trends_mode: yes + hk_trends_global: yes + hk_trends: 365d + compression_status: off + compress_older: 7d + register: zbxhk_update_result + + - assert: + that: zbxhk_update_result.changed is sameas False + + - name: initialize housekeeping setting. + community.zabbix.zabbix_housekeeping: + hk_events_mode: yes + hk_events_trigger: 365d + hk_events_service: 1d + hk_events_internal: 1d + hk_events_discovery: 1d + hk_events_autoreg: 1d + hk_services_mode: yes + hk_services: 365d + hk_audit_mode: yes + hk_audit: 365d + hk_sessions_mode: yes + hk_sessions: 365d + hk_history_mode: yes + hk_history_global: no + hk_history: 365d + hk_trends_mode: yes + hk_trends_global: no + hk_trends: 365d + compression_status: off + compress_older: 7d diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_maintenance/meta/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_maintenance/meta/main.yml new file mode 100644 index 000000000..acdb704c8 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_maintenance/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - setup_zabbix diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_maintenance/tasks/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_maintenance/tasks/main.yml new file mode 100644 index 000000000..0daca8d13 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_maintenance/tasks/main.yml @@ -0,0 +1,305 @@ +--- +# New host create test from here +- name: "test - Create a new host" + zabbix_host: + host_name: example + host_groups: + - Linux servers + interfaces: + - type: 1 + main: 1 + useip: 1 + ip: 10.1.1.1 + dns: "" + port: 10050 + register: create_host_result + +- assert: + that: + - create_host_result.changed is sameas true + +- name: "test - Create maintenance with a host_name param" + zabbix_maintenance: + name: maintenance + host_name: example + state: present + register: create_maintenance_host_name_result + +- assert: + that: + - create_maintenance_host_name_result.changed is sameas true + +# This check doesn't modify maintenace object and thus will be changed=false unless there are hosts without visible name defined +- name: "test - Create maintenance with a host_name param and disabled visible_name" + zabbix_maintenance: + name: maintenance + host_name: example + visible_name: false + state: present + register: create_maintenance_host_name_result + +# BUGGED: sometimes when test "lags" and some time passes since previous tasks, +# maintenance_start will not match and be updated, thus resulting in changed +# - assert: +# that: +# - create_maintenance_host_name_result.changed is sameas false + +- name: "test - Create maintenance with a host_name param(again - expectations: false change will occur)" + zabbix_maintenance: + name: maintenance + host_name: example + state: present + register: create_maintenance_host_name_again_result + +# BUGGED: sometimes when test "lags" and some time passes since previous tasks, +# maintenance_start will not match and be updated, thus resulting in changed +# - assert: +# that: +# - create_maintenance_host_name_again_result.changed is sameas false + +- name: "test - Update maintenance with a desc param" + zabbix_maintenance: + name: maintenance + host_name: example + desc: "test description" + state: present + register: update_maintenance_desc_result + +- debug: msg="{{ update_maintenance_desc_result }}" + +- assert: + that: + - update_maintenance_desc_result.changed is sameas true + +- name: "test - Update maintenance with a desc param(again - expectations: no change will occur)" + zabbix_maintenance: + name: maintenance + host_name: example + desc: "test description" + state: present + register: update_maintenance_desc_again_result + +# BUGGED: sometimes when test "lags" and some time passes since previous tasks, +# maintenance_start will not match and be updated, thus resulting in changed +# - assert: +# that: +# - update_maintenance_desc_again_result.changed is sameas false + +- name: "test - Update maintenance with a collect_data" + zabbix_maintenance: + name: maintenance + host_name: example + desc: "test description" + collect_data: false + state: present + register: update_maintenance_collect_data_result + +- assert: + that: + - update_maintenance_collect_data_result.changed is sameas true + +- name: "test - Update maintenance with a collect_data(again - expectations: no change will occur)" + zabbix_maintenance: + name: maintenance + host_name: example + desc: "test description" + collect_data: false + state: present + register: update_maintenance_collect_data_again_result + +# BUGGED: sometimes when test "lags" and some time passes since previous tasks, +# maintenance_start will not match and be updated, thus resulting in changed +# - assert: +# that: +# - update_maintenance_collect_data_again_result.changed is sameas false + +- name: "test - Update maintenance with a minutes param" + zabbix_maintenance: + name: maintenance + host_name: example + desc: "test description" + collect_data: false + minutes: 90 + state: present + register: update_maintenance_minutes_result + +- assert: + that: + - update_maintenance_minutes_result.changed is sameas true + +- name: "test - Update maintenance with a minutes param(again - expectations: no change will occur)" + zabbix_maintenance: + name: maintenance + host_name: example + desc: "test description" + collect_data: false + minutes: 90 + state: present + register: update_maintenance_minutes_again_result + +# BUGGED: sometimes when test "lags" and some time passes since previous tasks, +# maintenance_start will not match and be updated, thus resulting in changed +# - assert: +# that: +# - update_maintenance_minutes_again_result.changed is sameas false + +- name: "test - Update maintenance with a host_groups param" + zabbix_maintenance: + name: maintenance + host_name: example + host_groups: + - Linux servers + - Hypervisors + desc: "test description" + collect_data: false + minutes: 90 + state: present + register: update_maintenance_host_groups_result + +- assert: + that: + - update_maintenance_host_groups_result.changed is sameas true + +- name: "test - Update maintenance with a host_groups param(again - expectations: no change will occur)" + zabbix_maintenance: + name: maintenance + host_name: example + host_groups: + - Linux servers + - Hypervisors + desc: "test description" + collect_data: false + minutes: 90 + state: present + register: update_maintenance_host_groups_again_result + +# BUGGED: sometimes when test "lags" and some time passes since previous tasks, +# maintenance_start will not match and be updated, thus resulting in changed +# - assert: +# that: +# - update_maintenance_host_groups_again_result.changed is sameas false + +- name: "test - Update maintenance with change host_name to host_names param" + zabbix_maintenance: + name: maintenance + host_names: + - example + - Zabbix server + host_groups: + - Linux servers + - Hypervisors + desc: "test description" + collect_data: false + minutes: 90 + state: present + register: update_maintenance_host_names_result + +- assert: + that: + - update_maintenance_host_names_result.changed is sameas true + +- name: "test - Update maintenance with change host_name to host_names param(again - expectations: no change will occur)" + zabbix_maintenance: + name: maintenance + host_names: + - example + - Zabbix server + host_groups: + - Linux servers + - Hypervisors + desc: "test description" + collect_data: false + minutes: 90 + state: present + register: update_maintenance_host_names_again_result + +# BUGGED: sometimes when test "lags" and some time passes since previous tasks, +# maintenance_start will not match and be updated, thus resulting in changed +# - assert: +# that: +# - update_maintenance_host_names_again_result.changed is sameas false + +- name: "test - Update maintenance with tags" + zabbix_maintenance: + name: maintenance + host_names: + - example + - Zabbix server + host_groups: + - Linux servers + - Hypervisors + desc: "test description" + collect_data: yes # required for tags + minutes: 90 + state: present + tags: + - tag: ExampleHostsTag + - tag: ExampleHostsTag2 + value: ExampleTagValue + - tag: ExampleHostsTag3 + value: ExampleTagValue + operator: 0 + register: update_maintenance_host_tags + +- assert: + that: + - update_maintenance_host_tags.changed is sameas true + +- name: "test - Update maintenance with tags (again)" + zabbix_maintenance: + name: maintenance + host_names: + - example + - Zabbix server + host_groups: + - Linux servers + - Hypervisors + desc: "test description" + collect_data: yes + minutes: 90 + state: present + tags: + - tag: ExampleHostsTag + - tag: ExampleHostsTag2 + value: ExampleTagValue + - tag: ExampleHostsTag3 + value: ExampleTagValue + operator: 0 + register: update_maintenance_host_tags + +# BUGGED: sometimes when test "lags" and some time passes since previous tasks, +# maintenance_start will not match and be updated, thus resulting in changed +#- assert: +# that: +# - update_maintenance_host_tags.changed is sameas false + +- name: "test - Delete maintenance" + zabbix_maintenance: + name: maintenance + host_name: example + state: absent + register: delete_maintenance_result + tags: + - cleanup + +- assert: + that: + - delete_maintenance_result.changed is sameas true + +- name: "test - Delete maintenance(again - expectations: no change will occur)" + zabbix_maintenance: + name: maintenance + host_name: example + state: absent + register: delete_maintenance_again_result + +- assert: + that: + - delete_maintenance_again_result.changed is sameas false + +- name: "test - Delete testing host" + zabbix_host: + host_name: example + state: absent + tags: + - cleanup diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_mediatype/meta/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_mediatype/meta/main.yml new file mode 100644 index 000000000..acdb704c8 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_mediatype/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - setup_zabbix diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_mediatype/tasks/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_mediatype/tasks/main.yml new file mode 100644 index 000000000..4daffebdd --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_mediatype/tasks/main.yml @@ -0,0 +1,678 @@ +--- +- name: test - email mediatypes + module_defaults: + community.zabbix.zabbix_mediatype: + state: present + name: Example email + type: email + smtp_email: zabbix@example.com + + block: + - name: test - create new email mediatype without authentication + zabbix_mediatype: + register: zbxmediatype_new + + - assert: + that: zbxmediatype_new.changed is sameas True + + - name: test - create new email mediatype without authentication (again) + zabbix_mediatype: + register: zbxmediatype_new + + - assert: + that: zbxmediatype_new.changed is sameas False + + - name: test - update email mediatype smtp information + zabbix_mediatype: + smtp_helo: example.com + smtp_server: mail.example.com + smtp_server_port: 465 + register: zbxmediatype_smtp + + - assert: + that: zbxmediatype_smtp.changed is sameas True + + - name: test - update email mediatype smtp information (again) + zabbix_mediatype: + smtp_helo: example.com + smtp_server: mail.example.com + smtp_server_port: 465 + register: zbxmediatype_smtp + + - assert: + that: zbxmediatype_smtp.changed is sameas False + + - name: test - reset email mediatype smtp information to default + zabbix_mediatype: + register: zbxmediatype_reset + + - assert: + that: zbxmediatype_reset.changed is sameas True + + - name: test - update email mediatype with authentication without credentials (fail) + zabbix_mediatype: + smtp_authentication: true + smtp_security: STARTTLS + register: zbxmediatype_auth_fail + ignore_errors: true + + - assert: + that: zbxmediatype_auth_fail.failed is sameas True + + - name: test - update email mediatype with authentication + zabbix_mediatype: + smtp_authentication: true + smtp_security: STARTTLS + username: zabbix + password: Ex4mP!3 + register: zbxmediatype_auth + + - assert: + that: zbxmediatype_auth.changed is sameas True + + - name: test - update email mediatype with authentication (again) + zabbix_mediatype: + smtp_authentication: true + smtp_security: STARTTLS + username: zabbix + password: Ex4mP!3 + register: zbxmediatype_auth + + - assert: + that: zbxmediatype_auth.changed is sameas False + + - name: test - update email mediatype with SSL/TLS and host/peer verification + zabbix_mediatype: + smtp_authentication: true + smtp_security: SSL/TLS + smtp_verify_host: true + smtp_verify_peer: true + username: zabbix + password: Ex4mP!3 + register: zbxmediatype_verif + + - assert: + that: zbxmediatype_verif.changed is sameas True + + - name: test - update email mediatype with SSL/TLS and host/peer verification (again) + zabbix_mediatype: + smtp_authentication: true + smtp_security: SSL/TLS + smtp_verify_host: true + smtp_verify_peer: true + username: zabbix + password: Ex4mP!3 + register: zbxmediatype_verif + + - assert: + that: zbxmediatype_verif.changed is sameas False + + - when: zabbix_version is version('3.4', '>=') + block: + - name: test - reset email mediatype smtp information to default + zabbix_mediatype: + register: zbxmediatype_reset + + - assert: + that: zbxmediatype_reset.changed is sameas True + + - name: test - update email mediatype concurrent settings + zabbix_mediatype: + max_sessions: 99 + max_attempts: 10 + attempt_interval: 30s + register: zbxmediatype_concur + + - assert: + that: zbxmediatype_concur.changed is sameas True + + - name: test - update email mediatype concurrent settings (again) + zabbix_mediatype: + max_sessions: 99 + max_attempts: 10 + attempt_interval: 30s + register: zbxmediatype_concur + + - assert: + that: zbxmediatype_concur.changed is sameas False + + - name: test - update email mediatype concurrent settings above range (fail) + zabbix_mediatype: + max_sessions: 102 + max_attempts: 101 + attempt_interval: 61m + register: zbxmediatype_concur_fail + ignore_errors: true + + - assert: + that: zbxmediatype_concur_fail.failed is sameas True + + - when: zabbix_version is version('5.0', '>=') + block: + - name: test - reset email mediatype smtp information to default + zabbix_mediatype: + register: zbxmediatype_reset + + - assert: + that: zbxmediatype_reset.changed is sameas True + + - name: test - update email mediatype with message templates + zabbix_mediatype: + message_templates: + - eventsource: triggers + recovery: operations + subject: "Problem: {EVENT.NAME}" + body: "Problem started at {EVENT.TIME} on {EVENT.DATE}\r\nProblem name: {EVENT.NAME}\r\n" + - eventsource: discovery + recovery: operations + subject: "Discovery: {DISCOVERY.DEVICE.STATUS} {DISCOVERY.DEVICE.IPADDRESS}" + body: "Discovery rule: {DISCOVERY.RULE.NAME}\r\n\r\nDevice IP: {DISCOVERY.DEVICE.IPADDRESS}" + - eventsource: autoregistration + recovery: operations + subject: "Autoregistration: {HOST.HOST}" + body: "Host name: {HOST.HOST}\r\nHost IP: {HOST.IP}\r\nAgent port: {HOST.PORT}" + - eventsource: internal + recovery: operations + subject: "Internal: {EVENT.NAME}" + body: "Internal event started at {EVEN.TIME} on {EVENT.DATE}\r\nEvent name: {EVENT.NAME}\r\n" + register: zbxmediatype_msg_templates + + - assert: + that: zbxmediatype_msg_templates.changed is sameas True + + - name: test - update email mediatype with message templates (again) + zabbix_mediatype: + message_templates: + - eventsource: triggers + recovery: operations + subject: "Problem: {EVENT.NAME}" + body: "Problem started at {EVENT.TIME} on {EVENT.DATE}\r\nProblem name: {EVENT.NAME}\r\n" + - eventsource: discovery + recovery: operations + subject: "Discovery: {DISCOVERY.DEVICE.STATUS} {DISCOVERY.DEVICE.IPADDRESS}" + body: "Discovery rule: {DISCOVERY.RULE.NAME}\r\n\r\nDevice IP: {DISCOVERY.DEVICE.IPADDRESS}" + - eventsource: autoregistration + recovery: operations + subject: "Autoregistration: {HOST.HOST}" + body: "Host name: {HOST.HOST}\r\nHost IP: {HOST.IP}\r\nAgent port: {HOST.PORT}" + - eventsource: internal + recovery: operations + subject: "Internal: {EVENT.NAME}" + body: "Internal event started at {EVEN.TIME} on {EVENT.DATE}\r\nEvent name: {EVENT.NAME}\r\n" + register: zbxmediatype_msg_templates + + - assert: + that: zbxmediatype_msg_templates.changed is sameas False + + - name: test - update subject of message template in email mediatype + zabbix_mediatype: + message_templates: + - eventsource: triggers + recovery: operations + subject: "Problem: {EVENT.NAME} - test change" + body: "Problem started at {EVENT.TIME} on {EVENT.DATE}\r\nProblem name: {EVENT.NAME}\r\n" + - eventsource: discovery + recovery: operations + subject: "Discovery: {DISCOVERY.DEVICE.STATUS} {DISCOVERY.DEVICE.IPADDRESS}" + body: "Discovery rule: {DISCOVERY.RULE.NAME}\r\n\r\nDevice IP: {DISCOVERY.DEVICE.IPADDRESS}" + - eventsource: autoregistration + recovery: operations + subject: "Autoregistration: {HOST.HOST}" + body: "Host name: {HOST.HOST}\r\nHost IP: {HOST.IP}\r\nAgent port: {HOST.PORT}" + - eventsource: internal + recovery: operations + subject: "Internal: {EVENT.NAME}" + body: "Internal event started at {EVEN.TIME} on {EVENT.DATE}\r\nEvent name: {EVENT.NAME}\r\n" + register: zbxmediatype_msg_templates + + - assert: + that: zbxmediatype_msg_templates.changed is sameas True + + - name: test - update message of message template in email mediatype + zabbix_mediatype: + message_templates: + - eventsource: triggers + recovery: operations + subject: "Problem: {EVENT.NAME} - test change" + body: "Problem started at {EVENT.TIME} on {EVENT.DATE}\r\nProblem name: {EVENT.NAME}\r\n" + - eventsource: discovery + recovery: operations + subject: "Discovery: {DISCOVERY.DEVICE.STATUS} {DISCOVERY.DEVICE.IPADDRESS}" + body: "Discovery rule: {DISCOVERY.RULE.NAME}\r\n\r\nDevice IP: {DISCOVERY.DEVICE.IPADDRESS} - test" + - eventsource: autoregistration + recovery: operations + subject: "Autoregistration: {HOST.HOST}" + body: "Host name: {HOST.HOST}\r\nHost IP: {HOST.IP}\r\nAgent port: {HOST.PORT}" + - eventsource: internal + recovery: operations + subject: "Internal: {EVENT.NAME}" + body: "Internal event started at {EVEN.TIME} on {EVENT.DATE}\r\nEvent name: {EVENT.NAME}\r\n" + register: zbxmediatype_msg_templates + + - assert: + that: zbxmediatype_msg_templates.changed is sameas True + + - name: test - update subject and message of message template in email mediatype (again) + zabbix_mediatype: + message_templates: + - eventsource: triggers + recovery: operations + subject: "Problem: {EVENT.NAME} - test change" + body: "Problem started at {EVENT.TIME} on {EVENT.DATE}\r\nProblem name: {EVENT.NAME}\r\n" + - eventsource: discovery + recovery: operations + subject: "Discovery: {DISCOVERY.DEVICE.STATUS} {DISCOVERY.DEVICE.IPADDRESS}" + body: "Discovery rule: {DISCOVERY.RULE.NAME}\r\n\r\nDevice IP: {DISCOVERY.DEVICE.IPADDRESS} - test" + - eventsource: autoregistration + recovery: operations + subject: "Autoregistration: {HOST.HOST}" + body: "Host name: {HOST.HOST}\r\nHost IP: {HOST.IP}\r\nAgent port: {HOST.PORT}" + - eventsource: internal + recovery: operations + subject: "Internal: {EVENT.NAME}" + body: "Internal event started at {EVEN.TIME} on {EVENT.DATE}\r\nEvent name: {EVENT.NAME}\r\n" + register: zbxmediatype_msg_templates + + - assert: + that: zbxmediatype_msg_templates.changed is sameas False + + - name: test - disable email mediatype + zabbix_mediatype: + status: disabled + register: zbxmediatype_disable + + - assert: + that: zbxmediatype_disable.changed is sameas True + + - name: test - disable email mediatype (again) + zabbix_mediatype: + status: disabled + register: zbxmediatype_disable + + - assert: + that: zbxmediatype_disable.changed is sameas False + + - name: test - delete email mediatype + zabbix_mediatype: + state: absent + register: zbxmediatype_delete + + - assert: + that: zbxmediatype_delete.changed is sameas True + + - name: test - delete email mediatype (again) + zabbix_mediatype: + state: absent + register: zbxmediatype_delete + + - assert: + that: zbxmediatype_delete.changed is sameas False + +- name: test - script mediatypes + module_defaults: + community.zabbix.zabbix_mediatype: + state: present + name: Example script + type: script + + block: + - name: test - create new script mediatype + zabbix_mediatype: + script_name: /usr/local/bin/script.sh + register: zbxmediatype_script_new + + - assert: + that: zbxmediatype_script_new.changed is sameas True + + - name: test - create new script mediatype (again) + zabbix_mediatype: + script_name: /usr/local/bin/script.sh + register: zbxmediatype_script_new + + - assert: + that: zbxmediatype_script_new.changed is sameas False + + - name: test - update script mediatype with script parameters + zabbix_mediatype: + script_name: /usr/local/bin/script.sh + script_params: + - '-p test' + - '-q' + register: zbxmediatype_script_params + + - assert: + that: zbxmediatype_script_params.changed is sameas True + + - name: test - update script mediatype with script parameters (again) + zabbix_mediatype: + script_name: /usr/local/bin/script.sh + script_params: + - '-p test' + - '-q' + register: zbxmediatype_script_params + + - assert: + that: zbxmediatype_script_params.changed is sameas False + + - name: test - remove script mediatype parameters + zabbix_mediatype: + script_name: /usr/local/bin/script.sh + register: zbxmediatype_script_params_rev + + - assert: + that: zbxmediatype_script_params_rev.changed is sameas True + + - name: test - delete script mediatype + zabbix_mediatype: + state: absent + register: zbxmediatype_delete + + - assert: + that: zbxmediatype_delete.changed is sameas True + +- name: test - sms mediatypes + module_defaults: + community.zabbix.zabbix_mediatype: + state: present + name: Example sms + type: sms + + block: + - name: test - create new sms mediatype + zabbix_mediatype: + gsm_modem: /dev/ttyS0 + register: zbxmediatype_sms_new + + - assert: + that: zbxmediatype_sms_new.changed is sameas True + + - name: test - create new sms mediatype (again) + zabbix_mediatype: + gsm_modem: /dev/ttyS0 + register: zbxmediatype_sms_new + + - assert: + that: zbxmediatype_sms_new.changed is sameas False + + - when: zabbix_version is version('3.4', '>=') + block: + - name: test - update sms mediatype with concurrent settings + zabbix_mediatype: + gsm_modem: /dev/ttyS0 + max_sessions: 1 + max_attempts: 3 + attempt_interval: 30 + register: zbxmediatype_sms_concur + + - assert: + that: zbxmediatype_sms_concur.changed is sameas True + + - name: test - update sms mediatype with concurrent settings (again) + zabbix_mediatype: + gsm_modem: /dev/ttyS0 + max_sessions: 1 + max_attempts: 3 + attempt_interval: 30 + register: zbxmediatype_sms_concur + + - assert: + that: zbxmediatype_sms_concur.changed is sameas False + + - name: test - update sms mediatype with invalid max sessions (fail) + zabbix_mediatype: + gsm_modem: /dev/ttyS0 + max_sessions: 2 + register: zbxmediatype_sms_fail + ignore_errors: true + + - assert: + that: zbxmediatype_sms_fail.failed is sameas True + + - name: test - delete sms mediatype + zabbix_mediatype: + state: absent + register: zbxmediatype_delete + + - assert: + that: zbxmediatype_delete.changed is sameas True + +- name: test - jabber mediatypes + when: zabbix_version is version('4.2', '<=') + module_defaults: + community.zabbix.zabbix_mediatype: + state: present + name: Example jabber + type: jabber + + block: + - name: test - create new jabber mediatype + zabbix_mediatype: + username: zabbix + password: Ex4mP!3 + register: zbxmediatype_jabber_new + + - assert: + that: zbxmediatype_jabber_new.changed is sameas True + + - name: test - create new jabber mediatype (again) + zabbix_mediatype: + username: zabbix + password: Ex4mP!3 + register: zbxmediatype_jabber_new + + - assert: + that: zbxmediatype_jabber_new.changed is sameas False + + - name: test - delete jabber mediatype + zabbix_mediatype: + state: absent + register: zbxmediatype_delete + + - assert: + that: zbxmediatype_delete.changed is sameas True + +- name: test - ez_texting mediatypes + when: zabbix_version is version('4.2', '<=') + module_defaults: + community.zabbix.zabbix_mediatype: + state: present + name: Example ez_texting + type: ez_texting + + block: + - name: test - create new ez_texting mediatype + zabbix_mediatype: + username: zabbix + password: Ex4mP!3 + message_text_limit: USA + register: zbxmediatype_ez_texting_new + + - assert: + that: zbxmediatype_ez_texting_new.changed is sameas True + + - name: test - create new ez_texting mediatype (again) + zabbix_mediatype: + username: zabbix + password: Ex4mP!3 + message_text_limit: USA + register: zbxmediatype_ez_texting_new + + - assert: + that: zbxmediatype_ez_texting_new.changed is sameas False + + - name: test - update ez_texting mediatype with text limit + zabbix_mediatype: + username: zabbix + password: Ex4mP!3 + message_text_limit: Canada + register: zbxmediatype_ez_texting_update + + - assert: + that: zbxmediatype_ez_texting_update.changed is sameas True + + - name: test - delete ez_texting mediatype + zabbix_mediatype: + state: absent + register: zbxmediatype_delete + + - assert: + that: zbxmediatype_delete.changed is sameas True + +- name: test - email mediatypes + when: zabbix_version is version('4.4', '>=') + module_defaults: + community.zabbix.zabbix_mediatype: + state: present + name: Example webhook + type: webhook + webhook_script: "return 'Hello, world!';" + + block: + - name: test - create new webhook mediatype + zabbix_mediatype: + register: zbxmediatype_webhook_new + + - assert: + that: zbxmediatype_webhook_new.changed is sameas True + + - name: test - create new webhook mediatype (again) + zabbix_mediatype: + register: zbxmediatype_webhook_new + + - assert: + that: zbxmediatype_webhook_new.changed is sameas False + + - name: test - update webhook mediatype with process_tags + zabbix_mediatype: + process_tags: true + register: zbxmediatype_webhook_tags + + - assert: + that: zbxmediatype_webhook_tags.changed is sameas True + + - name: test - update webhook mediatype with process_tags (again) + zabbix_mediatype: + process_tags: true + register: zbxmediatype_webhook_tags + + - assert: + that: zbxmediatype_webhook_tags.changed is sameas False + + # supported since 4.4 + - name: test - update webhook mediatype with description + zabbix_mediatype: + process_tags: true + description: My custom webhook mediatype + register: zbxmediatype_webhook_desc + + - assert: + that: zbxmediatype_webhook_desc.changed is sameas True + + - name: test - update webhook mediatype with description (again) + zabbix_mediatype: + process_tags: true + description: My custom webhook mediatype + register: zbxmediatype_webhook_desc + + - assert: + that: zbxmediatype_webhook_desc.changed is sameas False + + - name: test - update webhook mediatype with event_menu without name and url (fail) + zabbix_mediatype: + process_tags: true + description: My custom webhook mediatype + event_menu: true + register: zbxmediatype_webhook_eventmenu + ignore_errors: true + + - assert: + that: zbxmediatype_webhook_eventmenu.failed is sameas True + + - name: test - update webhook mediatype with event_menu + zabbix_mediatype: + process_tags: true + description: My custom webhook mediatype + event_menu: true + event_menu_name: Example entry name + event_menu_url: '{EVENT.TAGS.__message_link}' + register: zbxmediatype_webhook_eventmenu + + - assert: + that: zbxmediatype_webhook_eventmenu.changed is sameas True + + - name: test - update webhook mediatype with event_menu (again) + zabbix_mediatype: + process_tags: true + description: My custom webhook mediatype + event_menu: true + event_menu_name: Example entry name + event_menu_url: '{EVENT.TAGS.__message_link}' + register: zbxmediatype_webhook_eventmenu + + - assert: + that: zbxmediatype_webhook_eventmenu.changed is sameas False + + - name: test - reset webhook mediatype to default + zabbix_mediatype: + register: zbxmediatype_reset + + - assert: + that: zbxmediatype_reset.changed is sameas True + + - name: test - update webhook mediatype with webhook_params + zabbix_mediatype: + webhook_params: + - name: param1 + value: value1 + register: zbxmediatype_webhook_params + + - assert: + that: zbxmediatype_webhook_params.changed is sameas True + + - name: test - update webhook mediatype with webhook_params (again) + zabbix_mediatype: + webhook_params: + - name: param1 + value: value1 + register: zbxmediatype_webhook_params + + - assert: + that: zbxmediatype_webhook_params.changed is sameas False + + - name: test - update webhook mediatype with webhook_params (reorder) + zabbix_mediatype: + webhook_params: + - name: z.param2 + value: xyz + - name: param1 + value: value1 + - name: b.param3 + - name: a.param4 + value: abc + register: zbxmediatype_webhook_params + + - assert: + that: zbxmediatype_webhook_params.changed is sameas True + + - name: test - update webhook mediatype with webhook_params (reorder again) + zabbix_mediatype: + webhook_params: + - name: param1 + value: value1 + - name: a.param4 + value: abc + - name: b.param3 + - name: z.param2 + value: xyz + register: zbxmediatype_webhook_params + + - assert: + that: zbxmediatype_webhook_params.changed is sameas False + + - name: test - delete webhook mediatype + zabbix_mediatype: + state: absent + register: zbxmediatype_delete + + - assert: + that: zbxmediatype_delete.changed is sameas True diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_module_defaults_group/meta/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_module_defaults_group/meta/main.yml new file mode 100644 index 000000000..acdb704c8 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_module_defaults_group/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - setup_zabbix diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_module_defaults_group/tasks/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_module_defaults_group/tasks/main.yml new file mode 100644 index 000000000..5b861810a --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_module_defaults_group/tasks/main.yml @@ -0,0 +1,48 @@ +--- +- name: Test module_defaults applied to a group during creation + module_defaults: + group/community.zabbix.zabbix: + host_groups: + - Example Group + state: present + block: + - name: Create host group + zabbix_group: + register: _grp + + - name: Create host + zabbix_host: + host_name: Example Host + interfaces: + - type: agent + main: 1 + dns: example-host01.local + register: _host + + - name: Assert that resources were correctly created + assert: + that: + - _grp is changed + - _host is changed + +- name: Test module_defaults applied to a group during deletion + module_defaults: + group/community.zabbix.zabbix: + host_groups: + - Example Group + state: absent + block: + - name: Delete host + zabbix_host: + host_name: Example Host + register: _host + + - name: Delete host group + zabbix_group: + register: _grp + + - name: Assert that resources were correctly deleted + assert: + that: + - _grp is changed + - _host is changed diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_proxy/meta/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_proxy/meta/main.yml new file mode 100644 index 000000000..acdb704c8 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_proxy/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - setup_zabbix diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_proxy/tasks/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_proxy/tasks/main.yml new file mode 100644 index 000000000..ee96e6e80 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_proxy/tasks/main.yml @@ -0,0 +1,313 @@ +--- +- name: test - create new passive Zabbix proxy server + zabbix_proxy: + proxy_name: zbxproxy_example01 + description: Example Zabbix Proxy + state: present + status: passive + interface: + useip: 0 + ip: 10.1.1.2 + dns: zbxproxy_example01 + port: 10051 + register: zbxproxy_new + +- name: assert that proxy was created + assert: + that: zbxproxy_new is changed + +- name: test - create same passive Zabbix proxy server + zabbix_proxy: + proxy_name: zbxproxy_example01 + description: Example Zabbix Proxy + state: present + status: passive + interface: + useip: 0 + ip: 10.1.1.2 + dns: zbxproxy_example01 + port: 10051 + register: zbxproxy_existing + +- name: assert that nothing has been changed + assert: + that: not zbxproxy_existing is changed + +- name: test - update Zabbix proxy server description + zabbix_proxy: + proxy_name: zbxproxy_example01 + description: Example Zabbix Proxy desc + state: present + status: passive + interface: + useip: 0 + ip: 10.1.1.2 + dns: zbxproxy_example01 + port: 10051 + register: zbxproxy_desc_update + +- name: assert that description has been updated + assert: + that: zbxproxy_desc_update is changed + +- name: test - update Zabbix proxy server interface + zabbix_proxy: + proxy_name: zbxproxy_example01 + description: Example Zabbix Proxy desc + state: present + status: passive + interface: + useip: 0 + ip: 10.1.1.3 + dns: zbxproxy_example01 + port: 10051 + register: zbxproxy_interface_update + +- name: assert that interface has been updated + assert: + that: zbxproxy_interface_update is changed + +- name: test - update Zabbix proxy server description & interface (again) + zabbix_proxy: + proxy_name: zbxproxy_example01 + description: Example Zabbix Proxy desc + state: present + status: passive + interface: + useip: 0 + ip: 10.1.1.3 + dns: zbxproxy_example01 + port: 10051 + register: zbxproxy_desc_interface_update + +- name: assert that nothing has been changed + assert: + that: not zbxproxy_desc_interface_update is changed + +- name: test - update Zabbix proxy server interface to use only ip + zabbix_proxy: + proxy_name: zbxproxy_example01 + description: Example Zabbix Proxy desc + state: present + status: passive + interface: + useip: 1 + ip: 10.1.1.3 + port: 10051 + register: zbxproxy_interface_onlyip + +- name: assert that interface has been updated + assert: + that: zbxproxy_interface_onlyip is changed + +- name: test - update Zabbix proxy server interface to use only ip again + zabbix_proxy: + proxy_name: zbxproxy_example01 + description: Example Zabbix Proxy desc + state: present + status: passive + interface: + useip: 1 + ip: 10.1.1.3 + port: 10051 + register: zbxproxy_interface_onlyip_again + +- name: assert that nothing has been changed + assert: + that: not zbxproxy_interface_onlyip_again is changed + +- name: test - update Zabbix proxy server interface to use only dns + zabbix_proxy: + proxy_name: zbxproxy_example01 + description: Example Zabbix Proxy desc + state: present + status: passive + interface: + useip: 0 + dns: zbxproxy_example01 + port: 10051 + register: zbxproxy_interface_onlydns + +- name: assert that interface has been updated + assert: + that: zbxproxy_interface_onlydns is changed + +- name: test - update Zabbix proxy server interface to use only dns again + zabbix_proxy: + proxy_name: zbxproxy_example01 + description: Example Zabbix Proxy desc + state: present + status: passive + interface: + useip: 0 + dns: zbxproxy_example01 + port: 10051 + register: zbxproxy_interface_onlydns_again + +- name: assert that nothing has been changed + assert: + that: not zbxproxy_interface_onlydns_again is changed + +- name: test - update Zabbix proxy server interface to fail + zabbix_proxy: + proxy_name: zbxproxy_example01 + description: Example Zabbix Proxy desc + state: present + status: passive + interface: + useip: 1 + dns: zbxproxy_example01 + port: 10051 + register: zbxproxy_interface_fail + ignore_errors: true + +- name: assert that module has failed + assert: + that: zbxproxy_interface_fail is failed + +- name: test - update Zabbix proxy server to be active + zabbix_proxy: + proxy_name: zbxproxy_example01 + description: Example Zabbix Proxy + state: present + status: active + register: zbxproxy_active_update + +- name: assert that proxy was updated + assert: + that: zbxproxy_active_update is changed + +- name: test - update Zabbix proxy server to be active (again) + zabbix_proxy: + proxy_name: zbxproxy_example01 + description: Example Zabbix Proxy + state: present + status: active + register: zbxproxy_active_update_again + +- name: assert that nothing has been changed + assert: + that: not zbxproxy_active_update_again is changed + +# proxy_address available on zabbix 4.0 and above +- block: + - name: test - update Zabbix proxy server to be active and use proxy_address + zabbix_proxy: + proxy_name: zbxproxy_example01 + description: Example Zabbix Proxy + state: present + status: active + proxy_address: 10.1.1.0/24,zabbix.example.com + register: zbxproxy_active_proxyaddress + + - name: assert that proxy was updated + assert: + that: zbxproxy_active_proxyaddress is changed + + - name: test - update Zabbix proxy server to be active use proxy_address (again) + zabbix_proxy: + proxy_name: zbxproxy_example01 + description: Example Zabbix Proxy + state: present + status: active + proxy_address: 10.1.1.0/24,zabbix.example.com + register: zbxproxy_active_proxyaddress_again + + - name: assert that nothing has been changed + assert: + that: not zbxproxy_active_proxyaddress_again is changed + + when: zabbix_version != "3.0" + +- name: test - update Zabbix proxy server to use encryption + zabbix_proxy: + proxy_name: zbxproxy_example01 + description: Example Zabbix Proxy + state: present + status: active + tls_psk_identity: test + tls_connect: PSK + tls_accept: PSK + tls_psk: 123456789abcdef123456789abcdef12 + register: zbxproxy_encryption + +- name: assert that encryption has been enabled + assert: + that: zbxproxy_encryption is changed + +- name: test - update Zabbix proxy server to use encryption (again) + zabbix_proxy: + proxy_name: zbxproxy_example01 + description: Example Zabbix Proxy + state: present + status: active + tls_psk_identity: test + tls_connect: PSK + tls_accept: PSK + tls_psk: 123456789abcdef123456789abcdef12 + register: zbxproxy_encryption_again + +- name: assert that nothing has been changed + assert: + that: not zbxproxy_encryption_again is changed + when: zabbix_version < "6.0" + +# With Zabbix >= 6.0 tls_psk and tls_psk_identity cannot be read +# thus there is no way to check idempotency +- name: assert that nothing has been changed + assert: + that: zbxproxy_encryption_again is changed + when: zabbix_version >= "6.0" + +- name: test - update Zabbix proxy server encryption settings + zabbix_proxy: + proxy_name: zbxproxy_example01 + description: Example Zabbix Proxy + state: present + status: active + tls_connect: certificate + tls_accept: certificate + tls_issuer: AcmeCorp + tls_subject: AcmeCorpServer + register: zbxproxy_encryption_update + +- name: assert that encryption has been updated + assert: + that: zbxproxy_encryption_update is changed + +- name: test - update Zabbix proxy server back to being passive + zabbix_proxy: + proxy_name: zbxproxy_example01 + description: Example Zabbix Proxy + state: present + status: passive + interface: + useip: 0 + ip: 10.1.1.2 + dns: zbxproxy_example01 + port: 10051 + register: zbxproxy_passive_update + +- name: assert that proxy was updated + assert: + that: zbxproxy_passive_update is changed + +- name: test - delete Zabbix proxy server + zabbix_proxy: + proxy_name: zbxproxy_example01 + state: absent + register: zbxproxy_delete + +- name: assert that proxy has been deleted + assert: + that: zbxproxy_delete is changed + +- name: test - delete Zabbix proxy server (again) + zabbix_proxy: + proxy_name: zbxproxy_example01 + state: absent + register: zbxproxy_delete_again + +- name: assert that nothing has been changed + assert: + that: not zbxproxy_delete_again is changed diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_proxy_info/meta/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_proxy_info/meta/main.yml new file mode 100644 index 000000000..acdb704c8 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_proxy_info/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - setup_zabbix diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_proxy_info/tasks/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_proxy_info/tasks/main.yml new file mode 100644 index 000000000..a5feb2731 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_proxy_info/tasks/main.yml @@ -0,0 +1,65 @@ +--- +- name: test - Create new Zabbix proxy + zabbix_proxy: + state: present + proxy_name: ExampleProxy + description: ExampleProxy + status: passive + interface: + useip: 1 + ip: 10.1.1.2 + port: 10051 + dns: ExampleProxy.local + register: create_proxy_result + +- assert: + that: + - create_proxy_result.changed is sameas true + +- name: test - Create new Zabbix host monitored by the proxy + zabbix_host: + state: present + host_name: ExampleHost + host_groups: + - Linux servers + status: enabled + proxy: ExampleProxy + interfaces: + - type: 1 + main: 1 + useip: 1 + ip: 10.1.1.3 + dns: "" + port: "10050" + register: create_host_result + +- assert: + that: + - create_host_result.changed is sameas true + +- name: test - Get zabbix proxy information + zabbix_proxy_info: + proxy_name: ExampleProxy + proxy_hosts: true + register: get_proxy_info_result + +- assert: + that: + - get_proxy_info_result["zabbix_proxy"].host == "ExampleProxy" + - get_proxy_info_result["zabbix_proxy"].hosts | length > 0 + - get_proxy_info_result["zabbix_proxy"].hosts[0].host == "ExampleHost" + - get_proxy_info_result["zabbix_proxy"].interface | length > 0 + - get_proxy_info_result["zabbix_proxy"].interface.ip == "10.1.1.2" + - get_proxy_info_result["zabbix_proxy"].interface.useip == "1" + - get_proxy_info_result["zabbix_proxy"].interface.port == "10051" + - get_proxy_info_result["zabbix_proxy"].interface.dns == "ExampleProxy.local" + +- name: test - cleanup test Zabbix host + zabbix_host: + state: absent + host_name: ExampleHost + +- name: test - cleanup test Zabbix proxy + zabbix_proxy: + state: absent + proxy_name: ExampleProxy diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_screen/meta/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_screen/meta/main.yml new file mode 100644 index 000000000..acdb704c8 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_screen/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - setup_zabbix diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_screen/tasks/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_screen/tasks/main.yml new file mode 100644 index 000000000..82d1e5f0e --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_screen/tasks/main.yml @@ -0,0 +1,149 @@ +--- + +- name: ensure zabbix server is being monitored + community.zabbix.zabbix_host: + host_name: Zabbix server + status: enabled + +- name: "Screen got removed with 5.4" + block: + - name: test - Check if screen fails on Zabbix >= 5.4 + community.zabbix.zabbix_screen: + screens: + - screen_name: TestScreenFail54 + host_group: Zabbix servers + state: present + graph_names: + - 'Zabbix cache usage, % used' + - 'Zabbix internal process busy %' + graph_width: 200 + graph_height: 100 + graphs_in_row: 5 + register: result + ignore_errors: true + when: zabbix_version is version('5.4', '>=') + + - name: expect to fail + assert: + that: + - "result is failed" + when: zabbix_version is version('5.4', '>=') + + - name: End play if Zabbix >= 5.4 + meta: end_play + when: zabbix_version is version('5.4', '>=') + +- name: test - delete the screen again + community.zabbix.zabbix_screen: + screens: + - screen_name: TestScreen1 + state: absent + +# ################################################# +# Test screen creation +# ################################################# + +- name: test - Create a new screen + community.zabbix.zabbix_screen: + screens: + - screen_name: TestScreen1 + host_group: Zabbix servers + state: present + graph_names: + - 'Zabbix cache usage, % used' + - 'Zabbix internal process busy %' + graph_width: 200 + graph_height: 100 + graphs_in_row: 5 + register: result + +- assert: + that: + - result.changed + +- name: test - Create a new screen again + community.zabbix.zabbix_screen: + screens: + - screen_name: TestScreen1 + host_group: Zabbix servers + state: present + graph_names: + - 'Zabbix cache usage, % used' + - 'Zabbix internal process busy %' + graph_width: 200 + graph_height: 100 + graphs_in_row: 5 + register: result + +- assert: + that: + - not result.changed + +# ################################################# +# Test screen editing +# ################################################# + +- name: test - Adding new graph + community.zabbix.zabbix_screen: + screens: + - screen_name: TestScreen1 + host_group: Zabbix servers + state: present + graph_names: + - 'Zabbix cache usage, % used' + - 'Zabbix internal process busy %' + - 'Zabbix internal queues' + - 'Zabbix server performance' + - 'Zabbix data gathering process busy %' + graph_width: 200 + graph_height: 100 + graphs_in_row: 5 + register: result + +- assert: + that: + - result.changed + +- name: test - Removing graph + community.zabbix.zabbix_screen: + screens: + - screen_name: TestScreen1 + host_group: Zabbix servers + state: present + graph_names: + - 'Zabbix cache usage, % used' + - 'Zabbix internal queues' + graph_width: 200 + graph_height: 100 + graphs_in_row: 5 + register: result + +- assert: + that: + - result.changed + +# ################################################# +# Test screen deletion +# ################################################# + +- name: test - delete the screen + community.zabbix.zabbix_screen: + screens: + - screen_name: TestScreen1 + state: absent + register: result + +- assert: + that: + - result.changed + +- name: test - delete the screen again + community.zabbix.zabbix_screen: + screens: + - screen_name: TestScreen1 + state: absent + register: result + +- assert: + that: + - not result.changed diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_script/meta/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_script/meta/main.yml new file mode 100644 index 000000000..acdb704c8 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_script/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - setup_zabbix diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_script/tasks/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_script/tasks/main.yml new file mode 100644 index 000000000..fe5c40519 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_script/tasks/main.yml @@ -0,0 +1,523 @@ +--- +- name: test - do not run tests for Zabbix < 6.0 + meta: end_play + when: zabbix_version is version('6.0', '<') + +- name: test - Test action operation script + module_defaults: + community.zabbix.zabbix_script: + name: Test action operation script + scope: action_operation + script_type: webhook + command: 'return 0' + description: "Test action operation script" + state: present + + block: + - name: test - Create new action operation script to execute webhook check mode + zabbix_script: + check_mode: true + register: create_action_check_mode_result + + - assert: + that: + - create_action_check_mode_result.changed is sameas true + + - name: test - Create new action operation script to execute webhook + zabbix_script: + register: create_action_result + + - assert: + that: + - create_action_result.changed is sameas true + + - name: test - Create new action operation script to execute webhook again + zabbix_script: + register: create_action_again_result + + - assert: + that: + - create_action_again_result.changed is sameas false + + - name: test - Update action operation script to execute webhook with host group + zabbix_script: + host_group: 'Discovered hosts' + register: update_action_host_group_result + + - assert: + that: + - update_action_host_group_result.changed is sameas true + + - name: test - Update action operation script to execute webhook with host group again + zabbix_script: + host_group: 'Discovered hosts' + register: update_action_host_group_again_result + + - assert: + that: + - update_action_host_group_again_result.changed is sameas false + + - name: test - Update action operation script to execute webhook with parameters + zabbix_script: + host_group: 'Discovered hosts' + parameters: + - name: param_name1 + register: update_action_param_result + + - assert: + that: + - update_action_param_result.changed is sameas true + + - name: test - Update action operation script to execute webhook with parameters again + zabbix_script: + host_group: 'Discovered hosts' + parameters: + - name: param_name1 + register: update_action_param_again_result + + - assert: + that: + - update_action_param_again_result.changed is sameas false + + - name: test - Update action operation script to execute webhook with parameters and value + zabbix_script: + host_group: 'Discovered hosts' + parameters: + - name: param_name1 + - name: param_name2 + value: value2 + register: update_action_param_value_result + + - assert: + that: + - update_action_param_value_result.changed is sameas true + + - name: test - Update action operation script to execute webhook with parameters and value again + zabbix_script: + host_group: 'Discovered hosts' + parameters: + - name: param_name1 + - name: param_name2 + value: value2 + register: update_action_param_value_again_result + + - assert: + that: + - update_action_param_value_again_result.changed is sameas false + + - name: test - Update action operation script remove host group + zabbix_script: + parameters: + - name: param_name1 + - name: param_name2 + value: value2 + register: update_action_no_host_group_result + + - assert: + that: + - update_action_no_host_group_result.changed is sameas true + + - name: test - Update action operation script remove host group again + zabbix_script: + parameters: + - name: param_name1 + - name: param_name2 + value: value2 + register: update_action_no_host_group_again_result + + - assert: + that: + - update_action_no_host_group_again_result.changed is sameas false + + - name: test - Update action operation script to type Script + zabbix_script: + script_type: script + execute_on: zabbix_agent + command: echo 1 + register: update_action_script_result + + - assert: + that: + - update_action_script_result.changed is sameas true + + - name: test - Update action operation script to type Script again + zabbix_script: + script_type: script + execute_on: zabbix_agent + command: echo 1 + register: update_action_script_again_result + + - assert: + that: + - update_action_script_again_result.changed is sameas false + + - name: test - Update action operation script to execute on server + zabbix_script: + script_type: script + execute_on: zabbix_server + command: echo 1 + register: update_action_script_server_result + + - assert: + that: + - update_action_script_server_result.changed is sameas true + + - name: test - Update action operation script to execute on server again + zabbix_script: + script_type: script + execute_on: zabbix_server + command: echo 1 + register: update_action_script_server_again_result + + - assert: + that: + - update_action_script_server_again_result.changed is sameas false + + - name: test - Update action operation script to execute on server or proxy + zabbix_script: + script_type: script + execute_on: zabbix_server_proxy + command: echo 1 + register: update_action_script_server_proxy_result + + - assert: + that: + - update_action_script_server_proxy_result.changed is sameas true + + - name: test - Update action operation script to execute on server or proxy again + zabbix_script: + script_type: script + execute_on: zabbix_server_proxy + command: echo 1 + register: update_action_script_server_proxy_again_result + + - assert: + that: + - update_action_script_server_proxy_again_result.changed is sameas false + + - name: test - Update action operation script to type SSH + zabbix_script: + script_type: ssh + authtype: password + username: bla + password: blabla + command: echo 2 + register: update_action_script_ssh_result + + - assert: + that: + - update_action_script_ssh_result.changed is sameas true + + - name: test - Update action operation script to type SSH again + zabbix_script: + script_type: ssh + authtype: password + username: bla + password: blabla + command: echo 2 + register: update_action_script_ssh_again_result + + - assert: + that: + - update_action_script_ssh_again_result.changed is sameas false + + - name: test - Update action operation script type SSH key auth + zabbix_script: + script_type: ssh + authtype: public_key + username: bla + publickey: blabla + privatekey: blablabla + command: echo 3 + register: update_action_script_ssh_authkey_result + + - assert: + that: + - update_action_script_ssh_authkey_result.changed is sameas true + + - name: test - Update action operation script type SSH key auth again + zabbix_script: + script_type: ssh + authtype: public_key + username: bla + publickey: blabla + privatekey: blablabla + command: echo 3 + register: update_action_script_ssh_authkey_again_result + + - assert: + that: + - update_action_script_ssh_authkey_again_result.changed is sameas false + + - name: test - Update action operation script type SSH add port + zabbix_script: + script_type: ssh + authtype: public_key + username: bla + publickey: blabla + privatekey: blablabla + command: echo 3 + port: 222 + register: update_action_script_ssh_port_result + + - assert: + that: + - update_action_script_ssh_port_result.changed is sameas true + + - name: test - Update action operation script type SSH add port again + zabbix_script: + script_type: ssh + authtype: public_key + username: bla + publickey: blabla + privatekey: blablabla + command: echo 3 + port: 222 + register: update_action_script_ssh_port_again_result + + - assert: + that: + - update_action_script_ssh_port_again_result.changed is sameas false + + - name: test - Update action operation script to type Telnet + zabbix_script: + script_type: telnet + username: bla1 + password: blabla1 + command: echo 4 + port: 223 + register: update_action_script_telnet_result + + - assert: + that: + - update_action_script_telnet_result.changed is sameas true + + - name: test - Update action operation script to type Telnet again + zabbix_script: + script_type: telnet + username: bla1 + password: blabla1 + command: echo 4 + port: 223 + register: update_action_script_telnet_again_result + + - assert: + that: + - update_action_script_telnet_again_result.changed is sameas false + + - name: test - Update action operation script to type IPMI + zabbix_script: + script_type: ipmi + command: echo 5 + register: update_action_script_ipmi_result + + - assert: + that: + - update_action_script_ipmi_result.changed is sameas true + + - name: test - Update action operation script to type IPMI again + zabbix_script: + script_type: ipmi + command: echo 5 + register: update_action_script_ipmi_again_result + + - assert: + that: + - update_action_script_ipmi_again_result.changed is sameas false + + - name: test - Delete action operation script + zabbix_script: + state: absent + register: delete_action_result + + - assert: + that: + - delete_action_result.changed is sameas true + + - name: test - Delete action operation script again + zabbix_script: + state: absent + register: delete_action_again_result + + - assert: + that: + - delete_action_again_result.changed is sameas false + +- name: test - Test manual host action script + module_defaults: + community.zabbix.zabbix_script: + name: Test manual host action script + scope: manual_host_action + script_type: webhook + command: 'return 0' + description: "Test manual host action script" + state: present + + block: + - name: test - Create new manual host action script to execute webhook check mode + zabbix_script: + parameters: + - name: param_name1 + - name: param_name2 + value: value2 + check_mode: true + register: create_action_check_mode_result + + - assert: + that: + - create_action_check_mode_result.changed is sameas true + + - name: test - Create new manual host action script to execute webhook + zabbix_script: + parameters: + - name: param_name1 + - name: param_name2 + value: value2 + register: create_action_result + + - assert: + that: + - create_action_result.changed is sameas true + + - name: test - Create new manual host action script to execute webhook again + zabbix_script: + parameters: + - name: param_name1 + - name: param_name2 + value: value2 + register: create_action_again_result + + - assert: + that: + - create_action_again_result.changed is sameas false + + - name: test - Update manual host action script with menu path + zabbix_script: + menu_path: menu/submenu + register: update_action_result + + - assert: + that: + - update_action_result.changed is sameas true + + - name: test - Update manual host action script with menu path again + zabbix_script: + menu_path: menu/submenu + register: update_action_again_result + + - assert: + that: + - update_action_again_result.changed is sameas false + + - name: test - Update manual host action script with user group + zabbix_script: + menu_path: menu/submenu + user_group: Guests + register: update_action_usrgrp_result + + - assert: + that: + - update_action_usrgrp_result.changed is sameas true + + - name: test - Update manual host action script with user group again + zabbix_script: + menu_path: menu/submenu + user_group: Guests + register: update_action_usrgrp_again_result + + - assert: + that: + - update_action_usrgrp_again_result.changed is sameas false + + - name: test - Update manual host action script with Write permissions + zabbix_script: + host_access: write + register: update_action_host_perms_result + + - assert: + that: + - update_action_host_perms_result.changed is sameas true + + - name: test - Update manual host action script with Write permissions again + zabbix_script: + host_access: write + register: update_action_host_perms_again_result + + - assert: + that: + - update_action_host_perms_again_result.changed is sameas false + + - name: test - Update manual host action script with confirmation + zabbix_script: + confirmation: 'Are you sure?' + register: update_action_host_confirm_result + + - assert: + that: + - update_action_host_confirm_result.changed is sameas true + + - name: test - Update manual host action script with confirmation again + zabbix_script: + confirmation: 'Are you sure?' + register: update_action_host_confirm_again_result + + - assert: + that: + - update_action_host_confirm_again_result.changed is sameas false + + - name: test - Delete manual host action script + zabbix_script: + state: absent + +- name: test - Test manual event action script + module_defaults: + community.zabbix.zabbix_script: + name: Test manual event action script + scope: manual_event_action + script_type: webhook + command: 'return 0' + description: "Test manual event action script" + state: present + + block: + - name: test - Create new manual event action script to execute webhook check mode + zabbix_script: + parameters: + - name: param_name1 + - name: param_name2 + value: value2 + check_mode: true + register: create_action_check_mode_result + + - assert: + that: + - create_action_check_mode_result.changed is sameas true + + - name: test - Create new manual event action script to execute webhook + zabbix_script: + parameters: + - name: param_name1 + - name: param_name2 + value: value2 + register: create_action_result + + - assert: + that: + - create_action_result.changed is sameas true + + - name: test - Create new manual event action script to execute webhook again + zabbix_script: + parameters: + - name: param_name1 + - name: param_name2 + value: value2 + diff: true + register: create_action_again_result + + - assert: + that: + - create_action_again_result.changed is sameas false + + - name: test - Delete manual host action script + zabbix_script: + state: absent diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_service/defaults/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_service/defaults/main.yml new file mode 100644 index 000000000..2a50fa6ae --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_service/defaults/main.yml @@ -0,0 +1,2 @@ +--- +service_example_trigger: "Zabbix http poller processes more than 75% busy" diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_service/meta/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_service/meta/main.yml new file mode 100644 index 000000000..acdb704c8 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_service/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - setup_zabbix diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_service/tasks/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_service/tasks/main.yml new file mode 100644 index 000000000..f4fc761b1 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_service/tasks/main.yml @@ -0,0 +1,900 @@ +--- +- when: zabbix_version is version('6.0', '<') + module_defaults: + community.zabbix.zabbix_service: + name: ExampleServiceForServiceModule + sla: 99.99 + sortorder: 0 + state: present + + block: + - name: "test - Create a new service with check_mode" + zabbix_service: + check_mode: true + register: create_service_check_mode_result + + - assert: + that: + - create_service_check_mode_result.changed is sameas true + + - name: "test - Create a new service" + zabbix_service: + register: create_service_result + + - assert: + that: + - create_service_result.changed is sameas true + + - name: "test - Create a new service (idempotency check)" + zabbix_service: + register: create_service_idempotency_check_result + + - assert: + that: + - create_service_idempotency_check_result.changed is sameas false + + - name: "test - Update a sla with check_mode" + zabbix_service: + sla: 99.999 + check_mode: true + register: update_sla_check_mode_result + + - assert: + that: + - update_sla_check_mode_result.changed is sameas true + + - name: "test - Update a sla" + zabbix_service: + sla: 99.999 + register: update_sla_result + + - assert: + that: + - update_sla_result.changed is sameas true + + - name: "test - Update a sla (idempotency check)" + zabbix_service: + sla: 99.999 + register: update_sla_idempotency_check_result + + - assert: + that: + - update_sla_idempotency_check_result.changed is sameas false + + - name: "test - Update a calculate_sla with check_mode" + zabbix_service: + sla: 99.999 + calculate_sla: true + check_mode: true + register: update_calculate_sla_check_mode_result + + - assert: + that: + - update_calculate_sla_check_mode_result.changed is sameas true + + - name: "test - Update a calculate_sla" + zabbix_service: + sla: 99.999 + calculate_sla: true + register: update_calculate_sla_result + + - assert: + that: + - update_calculate_sla_result.changed is sameas true + + - name: "test - Update a calculate_sla (idempotency check)" + zabbix_service: + sla: 99.999 + calculate_sla: true + register: update_calculate_sla_idempotency_check_result + + - assert: + that: + - update_calculate_sla_idempotency_check_result.changed is sameas false + + - name: "Override trigger_name for different version of Zabbix" + set_fact: + service_example_trigger: "Zabbix server: Utilization of http poller processes over 75%" + when: zabbix_version is version("5.0", "==") + + - name: "test - Update trigger_host and trigger_name with check_mode" + zabbix_service: + sla: 99.999 + calculate_sla: true + trigger_host: "Zabbix server" + trigger_name: "{{ service_example_trigger }}" + check_mode: true + register: update_trigger_name_check_mode_result + + - assert: + that: + - update_trigger_name_check_mode_result.changed is sameas true + + - name: "test - Update trigger_host and trigger_name" + zabbix_service: + sla: 99.999 + calculate_sla: true + trigger_host: "Zabbix server" + trigger_name: "{{ service_example_trigger }}" + register: update_trigger_name_result + + - assert: + that: + - update_trigger_name_result.changed is sameas true + + - name: "test - Update trigger_host and trigger_name (idempotency check)" + zabbix_service: + sla: 99.999 + calculate_sla: true + trigger_host: "Zabbix server" + trigger_name: "{{ service_example_trigger }}" + register: update_trigger_name_idempotency_check_result + + - assert: + that: + - update_trigger_name_idempotency_check_result.changed is sameas false + + - name: "test - Update a algorithm of service with check_mode" + zabbix_service: + sla: 99.999 + calculate_sla: true + trigger_host: "Zabbix server" + trigger_name: "{{ service_example_trigger }}" + algorithm: all_children + check_mode: true + register: update_algorithm_check_mode_result + + - assert: + that: + - update_algorithm_check_mode_result.changed is sameas true + + - name: "test - Update a algorithm of service" + zabbix_service: + sla: 99.999 + calculate_sla: true + trigger_host: "Zabbix server" + trigger_name: "{{ service_example_trigger }}" + algorithm: all_children + register: update_algorithm_result + + - assert: + that: + - update_algorithm_result.changed is sameas true + + - name: "test - Update a algorithm of service (idempotency check)" + zabbix_service: + sla: 99.999 + calculate_sla: true + trigger_host: "Zabbix server" + trigger_name: "{{ service_example_trigger }}" + algorithm: all_children + register: update_algorithm_idempotency_check_result + + - assert: + that: + - update_algorithm_idempotency_check_result.changed is sameas false + + - name: "test - Create a new root service for parent test" + zabbix_service: + name: ExampleServiceForServiceModuleRoot + sla: 99.99 + register: create_child_service_result + + - assert: + that: + - create_child_service_result.changed is sameas true + + - name: "test - Update a parent of child service with check_mode" + zabbix_service: + name: ExampleServiceForServiceModule + sla: 99.999 + calculate_sla: true + trigger_host: "Zabbix server" + trigger_name: "{{ service_example_trigger }}" + algorithm: all_children + parent: ExampleServiceForServiceModuleRoot + check_mode: true + register: create_parent_child_service_check_mode_result + + - assert: + that: + - create_parent_child_service_check_mode_result.changed is sameas true + + - name: "test - Update a parent of child service" + zabbix_service: + name: ExampleServiceForServiceModule + sla: 99.999 + calculate_sla: true + trigger_host: "Zabbix server" + trigger_name: "{{ service_example_trigger }}" + algorithm: all_children + parent: ExampleServiceForServiceModuleRoot + register: create_parent_child_service_result + + - assert: + that: + - create_parent_child_service_result.changed is sameas true + + - name: "test - Update a parent of child service (idempotency check)" + zabbix_service: + name: ExampleServiceForServiceModule + sla: 99.999 + calculate_sla: true + trigger_host: "Zabbix server" + trigger_name: "{{ service_example_trigger }}" + algorithm: all_children + parent: ExampleServiceForServiceModuleRoot + register: create_parent_child_service_idempotency_check_result + + - assert: + that: + - create_parent_child_service_idempotency_check_result.changed is sameas false + + - name: "test - Remove ExampleServiceForServiceModule service with check_mode" + zabbix_service: + name: ExampleServiceForServiceModule + sla: 99.999 + state: absent + check_mode: true + register: remove_service_with_check_mode_result + + - assert: + that: + - remove_service_with_check_mode_result.changed is sameas true + + - name: "test - Remove ExampleServiceForServiceModule service" + zabbix_service: + name: ExampleServiceForServiceModule + sla: 99.999 + state: absent + register: remove_service_result + + - assert: + that: + - remove_service_result.changed is sameas true + + - name: "test - Remove ExampleServiceForServiceModule service (idempotency check)" + zabbix_service: + name: ExampleServiceForServiceModule + sla: 99.999 + state: absent + register: remove_service_idempotency_check_result + + - assert: + that: + - remove_service_idempotency_check_result.changed is sameas false + + - name: "test - Remove ExampleServiceForServiceModuleRoot service with check_mode" + zabbix_service: + name: ExampleServiceForServiceModuleRoot + sla: 99.999 + state: absent + check_mode: true + register: remove_root_service_with_check_mode_result + + - assert: + that: + - remove_root_service_with_check_mode_result.changed is sameas true + + - name: "test - Remove ExampleServiceForServiceModuleRoot service" + zabbix_service: + name: ExampleServiceForServiceModuleRoot + sla: 99.999 + state: absent + register: remove_root_service_result + + - assert: + that: + - remove_root_service_result.changed is sameas true + + - name: "test - Remove ExampleServiceForServiceModuleRoot service (idempotency check)" + zabbix_service: + name: ExampleServiceForServiceModuleRoot + sla: 99.999 + state: absent + register: remove_root_service_idempotency_check_result + + - assert: + that: + - remove_root_service_idempotency_check_result.changed is sameas false + +- name: test - service for Zabbix >= 6.0 + when: zabbix_version is version('6.0', '>=') + module_defaults: + community.zabbix.zabbix_service: + description: "Example Service for Service Module" + sortorder: 0 + propagation_rule: increase + propagation_value: warning + state: present + + block: + - name: "test - Create a new service with check_mode" + zabbix_service: + name: ExampleServiceForServiceModule + check_mode: true + register: create_service_check_mode_result + + - assert: + that: + - create_service_check_mode_result.changed is sameas true + + - name: "test - Create a new service" + zabbix_service: + name: ExampleServiceForServiceModule + register: create_service_result + + - assert: + that: + - create_service_result.changed is sameas true + + - name: "test - Create a new service (idempotency check)" + zabbix_service: + name: ExampleServiceForServiceModule + register: create_service_idempotency_check_result + + - assert: + that: + - create_service_idempotency_check_result.changed is sameas false + + - name: "test - Update service add service tags" + zabbix_service: + name: ExampleServiceForServiceModule + tags: + - tag: TagName1 + value: TagValue1 + register: update_service_stags_result + + - assert: + that: + - update_service_stags_result.changed is sameas true + + - name: "test - Update service with service tags (idempotency check)" + zabbix_service: + name: ExampleServiceForServiceModule + tags: + - tag: TagName1 + value: TagValue1 + register: update_service_stags_idempotency_check_result + + - assert: + that: + - update_service_stags_idempotency_check_result.changed is sameas false + + - name: "test - Update service add more service tags" + zabbix_service: + name: ExampleServiceForServiceModule + tags: + - tag: TagName1 + value: TagValue1 + - tag: TagName2 + value: TagValue2 + register: update_service_more_stags_result + + - assert: + that: + - update_service_more_stags_result.changed is sameas true + + - name: "test - Update service add more service tags (idempotency check)" + zabbix_service: + name: ExampleServiceForServiceModule + tags: + - tag: TagName1 + value: TagValue1 + - tag: TagName2 + value: TagValue2 + register: update_service_more_stags_idempotency_check_result + + - assert: + that: + - update_service_more_stags_idempotency_check_result.changed is sameas false + + - name: "test - Update service remove service tags" + zabbix_service: + name: ExampleServiceForServiceModule + tags: + - tag: TagName2 + value: TagValue2 + register: update_service_less_stags_result + + - assert: + that: + - update_service_less_stags_result.changed is sameas true + + - name: "test - Update service remove service tags (idempotency check)" + zabbix_service: + name: ExampleServiceForServiceModule + tags: + - tag: TagName2 + value: TagValue2 + register: update_service_less_stags_idempotency_check_result + + - assert: + that: + - update_service_less_stags_idempotency_check_result.changed is sameas false + + - name: "test - Delete service" + zabbix_service: + name: ExampleServiceForServiceModule + state: absent + + - name: "test - Create service with one problem tag" + zabbix_service: + name: ExampleServiceForServiceModule + problem_tags: + - tag: TagName1 + operator: equals + value: TagValue1 + register: create_service_with_ptag_result + + - assert: + that: + - create_service_with_ptag_result.changed is sameas true + + - name: "test - Create service with one problem tag (idempotency check)" + zabbix_service: + name: ExampleServiceForServiceModule + problem_tags: + - tag: TagName1 + operator: equals + value: TagValue1 + register: create_service_with_ptag_idempotency_check_result + + - name: "test - Update service with problem tag without operator" + zabbix_service: + name: ExampleServiceForServiceModule + problem_tags: + - tag: TagName1 + operator: equals + value: TagValue1 + - tag: TagName2 + value: TagValue2 + register: update_service_with_ptag_woop_result + + - assert: + that: + - update_service_with_ptag_woop_result.changed is sameas true + + - name: "test - Update service with problem tag without operator (idempotency check)" + zabbix_service: + name: ExampleServiceForServiceModule + problem_tags: + - tag: TagName1 + operator: equals + value: TagValue1 + - tag: TagName2 + value: TagValue2 + register: update_service_with_ptag_woop_idempotency_check_result + + - assert: + that: + - update_service_with_ptag_woop_idempotency_check_result.changed is sameas false + + - name: "test - Update service with problem tag with like operator" + zabbix_service: + name: ExampleServiceForServiceModule + problem_tags: + - tag: TagName1 + operator: equals + value: TagValue1 + - tag: TagName2 + value: TagValue2 + - tag: TagName3 + operator: like + value: TagValue3 + register: update_service_with_ptag_wlikeop_result + + - assert: + that: + - update_service_with_ptag_wlikeop_result.changed is sameas true + + - name: "test - Update service with problem tag with like operator (idempotency check)" + zabbix_service: + name: ExampleServiceForServiceModule + problem_tags: + - tag: TagName1 + operator: equals + value: TagValue1 + - tag: TagName2 + value: TagValue2 + - tag: TagName3 + operator: like + value: TagValue3 + register: update_service_with_ptag_wlikeop_idempotency_check_result + + - assert: + that: + - update_service_with_ptag_wlikeop_idempotency_check_result.changed is sameas false + + - name: "test - Update service with problem tag without operator and without value" + zabbix_service: + name: ExampleServiceForServiceModule + problem_tags: + - tag: TagName1 + operator: equals + value: TagValue1 + - tag: TagName2 + value: TagValue2 + - tag: TagName3 + operator: like + value: TagValue3 + - tag: TagName4 + register: update_service_with_ptag_woov_result + + - assert: + that: + - update_service_with_ptag_woov_result.changed is sameas true + + - name: "test - Update service with problem tag without operator and without value (idempotency check)" + zabbix_service: + name: ExampleServiceForServiceModule + problem_tags: + - tag: TagName1 + operator: equals + value: TagValue1 + - tag: TagName2 + value: TagValue2 + - tag: TagName3 + operator: like + value: TagValue3 + - tag: TagName4 + register: update_service_with_ptag_woov_idempotency_check_result + + - assert: + that: + - update_service_with_ptag_woov_idempotency_check_result.changed is sameas false + + - name: "test - Update service remove problem tags" + zabbix_service: + name: ExampleServiceForServiceModule + problem_tags: + - tag: TagName1 + operator: equals + value: TagValue1 + - tag: TagName3 + operator: like + value: TagValue3 + register: update_service_remove_tags_result + + - assert: + that: + - update_service_remove_tags_result.changed is sameas true + + - name: "test - Update service remove problem tags (idempotency check)" + zabbix_service: + name: ExampleServiceForServiceModule + problem_tags: + - tag: TagName1 + operator: equals + value: TagValue1 + - tag: TagName3 + operator: like + value: TagValue3 + register: update_service_remove_tags_idempotency_check_result + + - assert: + that: + - update_service_remove_tags_idempotency_check_result.changed is sameas false + + - name: "test - Update service remove all problem tags" + zabbix_service: + name: ExampleServiceForServiceModule + register: update_service_remove_all_tags_result + + - assert: + that: + - update_service_remove_all_tags_result.changed is sameas true + + - name: "test - Update service remove all problem tags (idempotency check)" + zabbix_service: + name: ExampleServiceForServiceModule + register: update_service_remove_all_tags_idempotency_check_result + + - assert: + that: + - update_service_remove_all_tags_idempotency_check_result.changed is sameas false + + - name: "test - Create a new child service" + zabbix_service: + name: ExampleChildServiceForServiceModule + sortorder: 10 + parents: + - ExampleServiceForServiceModule + register: create_child_service_result + + - assert: + that: + - create_child_service_result.changed is sameas true + + - name: "test - Create a new child service (idempotency check)" + zabbix_service: + name: ExampleChildServiceForServiceModule + sortorder: 10 + parents: + - ExampleServiceForServiceModule + register: create_child_service_idempotency_check_result + + - assert: + that: + - create_child_service_idempotency_check_result.changed is sameas false + + - name: "test - Update child service to remove parent" + zabbix_service: + name: ExampleChildServiceForServiceModule + parents: [] + register: update_child_service_delete_parent_result + + - assert: + that: + - update_child_service_delete_parent_result.changed is sameas true + + - name: "test - Create a new parent service" + zabbix_service: + name: ExampleParentServiceForServiceModule + + - name: "test - Delete child service" + zabbix_service: + name: ExampleChildServiceForServiceModule + state: absent + + - name: "test - Create a new child service with two parents" + zabbix_service: + name: ExampleChildServiceForServiceModule + parents: + - ExampleServiceForServiceModule + - ExampleParentServiceForServiceModule + register: create_child_service_two_parents_result + + - assert: + that: + - create_child_service_two_parents_result.changed is sameas true + + - name: "test - Create a new child service with two parents (idempotency check)" + zabbix_service: + name: ExampleChildServiceForServiceModule + parents: + - ExampleServiceForServiceModule + - ExampleParentServiceForServiceModule + register: create_child_service_two_parents_idempotency_check_result + + - assert: + that: + - create_child_service_two_parents_idempotency_check_result.changed is sameas false + + - name: "test - Remove one parent from new child service" + zabbix_service: + name: ExampleChildServiceForServiceModule + parents: + - ExampleParentServiceForServiceModule + register: update_child_service_remove_parent_result + + - assert: + that: + - update_child_service_remove_parent_result.changed is sameas true + + - name: "test - Remove one parent from new child service (idempotency check)" + zabbix_service: + name: ExampleChildServiceForServiceModule + parents: + - ExampleParentServiceForServiceModule + register: update_child_service_remove_parent_idempotency_check_result + + - assert: + that: + - update_child_service_remove_parent_idempotency_check_result.changed is sameas false + + - name: "test - Delete parent service 2" + zabbix_service: + name: ExampleParentServiceForServiceModule + state: absent + + - name: "test - Create parent service with child service" + zabbix_service: + name: ExampleParentServiceForServiceModule + children: + - ExampleChildServiceForServiceModule + register: create_parent_service_with_child_result + + - assert: + that: + - create_parent_service_with_child_result.changed is sameas true + + - name: "test - Create parent service with child service (idempotency check)" + zabbix_service: + name: ExampleParentServiceForServiceModule + children: + - ExampleChildServiceForServiceModule + register: create_parent_service_with_child_result_idempotency_check_result + + - assert: + that: + - create_parent_service_with_child_result_idempotency_check_result.changed is sameas false + + - name: "test - Create second chile service" + zabbix_service: + name: ExampleChildServiceForServiceModule2 + + - name: "test - Update parent service with the second child service" + zabbix_service: + name: ExampleParentServiceForServiceModule + children: + - ExampleChildServiceForServiceModule + - ExampleChildServiceForServiceModule2 + register: update_parent_service_with_second_child_result + + - assert: + that: + - update_parent_service_with_second_child_result.changed is sameas true + + - name: "test - Update parent service with the second child service (idempotency check)" + zabbix_service: + name: ExampleParentServiceForServiceModule + children: + - ExampleChildServiceForServiceModule + - ExampleChildServiceForServiceModule2 + register: update_parent_service_with_second_child_result_idempotency_check_result + + - assert: + that: + - update_parent_service_with_second_child_result_idempotency_check_result.changed is sameas false + + - name: "test - Delete parent service" + zabbix_service: + name: ExampleParentServiceForServiceModule + state: absent + + - name: "test - Create parent service with two child services" + zabbix_service: + name: ExampleParentServiceForServiceModule + children: + - ExampleChildServiceForServiceModule + - ExampleChildServiceForServiceModule2 + register: create_parent_service_with_two_children_result + + - assert: + that: + - create_parent_service_with_two_children_result.changed is sameas true + + - name: "test - Create parent service with child services (idempotency check)" + zabbix_service: + name: ExampleParentServiceForServiceModule + children: + - ExampleChildServiceForServiceModule + - ExampleChildServiceForServiceModule2 + register: create_parent_service_with_two_children_idempotency_check_result + + - assert: + that: + - create_parent_service_with_two_children_idempotency_check_result.changed is sameas false + + - name: "test - Delete parent service" + zabbix_service: + name: ExampleParentServiceForServiceModule + state: absent + + - name: "test - Delete child service" + zabbix_service: + name: ExampleChildServiceForServiceModule + state: absent + - name: "test - Delete child servicei 2" + zabbix_service: + name: ExampleChildServiceForServiceModule2 + state: absent + + - name: "test - Delete new service" + zabbix_service: + name: ExampleServiceForServiceModule + state: absent + register: delete_service_result + + - assert: + that: + - delete_service_result.changed is sameas true + + - name: "test - Delete new service (idempotency check)" + zabbix_service: + name: ExampleServiceForServiceModule + state: absent + register: delete_service_idempotency_check_result + + - assert: + that: + - delete_service_idempotency_check_result.changed is sameas false + + - name: "test - Create a new service with status rule" + zabbix_service: + name: ExampleServiceForServiceModule + status_rules: + - type: at_least_n_child_services_have_status_or_above + limit_value: 4242 + limit_status: ok + new_status: not_classified + register: create_service_sr_result + + - assert: + that: + - create_service_sr_result.changed is sameas true + + - name: "test - Create a new service with status rule (idempotency check)" + zabbix_service: + name: ExampleServiceForServiceModule + status_rules: + - type: at_least_n_child_services_have_status_or_above + limit_value: 4242 + limit_status: ok + new_status: not_classified + register: create_service_sr_idempotency_check_result + + - assert: + that: + - create_service_sr_idempotency_check_result.changed is sameas false + + - name: "test - Update service with the second status rule" + zabbix_service: + name: ExampleServiceForServiceModule + status_rules: + - type: at_least_n_child_services_have_status_or_above + limit_value: 4242 + limit_status: ok + new_status: not_classified + - type: at_least_npct_child_services_have_status_or_above + limit_value: 42 + limit_status: information + new_status: warning + register: update_service_add_sr_result + + - assert: + that: + - update_service_add_sr_result.changed is sameas true + + - name: "test - Update service with the second status rule (idempotency check)" + zabbix_service: + name: ExampleServiceForServiceModule + status_rules: + - type: at_least_n_child_services_have_status_or_above + limit_value: 4242 + limit_status: ok + new_status: not_classified + - type: at_least_npct_child_services_have_status_or_above + limit_value: 42 + limit_status: information + new_status: warning + register: update_service_add_sr_idempotency_check_result + + - assert: + that: + - update_service_add_sr_idempotency_check_result.changed is sameas false + + - name: "test - Update service remove status rule" + zabbix_service: + name: ExampleServiceForServiceModule + status_rules: + - type: at_least_npct_child_services_have_status_or_above + limit_value: 42 + limit_status: information + new_status: warning + register: update_service_remove_sr_result + + - assert: + that: + - update_service_remove_sr_result.changed is sameas true + + - name: "test - Update service remove status rule (idempotency check)" + zabbix_service: + name: ExampleServiceForServiceModule + status_rules: + - type: at_least_npct_child_services_have_status_or_above + limit_value: 42 + limit_status: information + new_status: warning + register: update_service_remove_sr_idempotency_check_result + + - assert: + that: + - update_service_remove_sr_idempotency_check_result.changed is sameas false + + - name: "test - Delete new service" + zabbix_service: + name: ExampleServiceForServiceModule + state: absent + register: delete_service_result diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template/defaults/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template/defaults/main.yml new file mode 100644 index 000000000..6f736db53 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template/defaults/main.yml @@ -0,0 +1,2 @@ +--- +template_groups_key: "{{ 'template_groups' if zabbix_version is version('6.2', '>=') else 'groups' }}" diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template/files/template1-changed_50_lower.json b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template/files/template1-changed_50_lower.json new file mode 100644 index 000000000..adb0e977f --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template/files/template1-changed_50_lower.json @@ -0,0 +1,51 @@ +{ + "zabbix_export": { + "date": "2020-05-29T15:22:11Z", + "templates": [ + { + "template": "ExampleHost", + "name": "ExampleHost", + "description": "", + "groups": [ + { + "name": "Templates" + }, + { + "name": "Templates/Applications" + } + ], + "macros": [ + { + "macro": "{$EXAMPLE_MACRO1}", + "value": "1000" + }, + { + "macro": "{$EXAMPLE_MACRO2}", + "value": "text" + }, + { + "macro": "{$EXAMPLE_MACRO3}", + "value": "text2" + } + ], + "templates": [ + { + "name": "Template App FTP Service" + }, + { + "name": "Template App Zabbix Proxy" + } + ] + } + ], + "version": "3.0", + "groups": [ + { + "name": "Templates" + }, + { + "name": "Templates/Applications" + } + ] + } +} diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template/files/template1_50_higher_decode_unicode.json b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template/files/template1_50_higher_decode_unicode.json new file mode 100644 index 000000000..bd1ef8286 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template/files/template1_50_higher_decode_unicode.json @@ -0,0 +1,29 @@ +{ + "zabbix_export": { + "version": "5.0", + "groups": [ + { + "name": "Templates" + } + ], + "templates": [ + { + "template": "ExampleTemplate314", + "name": "ExampleTemplate314", + "description": "\u30c6\u30b9\u30c8\u30b3\u30e1\u30f3\u30c8", + "groups": [ + { + "name": "Templates" + } + ], + "items": [ + { + "name": "test", + "type": "ZABBIX_ACTIVE", + "key": "logrt[\"/test.*test.log\",\"test.*total=([0-9.]+)\",,,skip,\\1]" + } + ], + } + ], + } +} diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template/files/template1_50_lower.json b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template/files/template1_50_lower.json new file mode 100644 index 000000000..b0ff06fb1 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template/files/template1_50_lower.json @@ -0,0 +1,47 @@ +{ + "zabbix_export": { + "date": "2020-05-29T15:22:11Z", + "templates": [ + { + "template": "ExampleHost", + "name": "ExampleHost", + "description": "", + "groups": [ + { + "name": "Templates" + }, + { + "name": "Templates/Applications" + } + ], + "macros": [ + { + "macro": "{$EXAMPLE_MACRO1}", + "value": "1000" + }, + { + "macro": "{$EXAMPLE_MACRO2}", + "value": "text" + } + ], + "templates": [ + { + "name": "Template App FTP Service" + }, + { + "name": "Template App Zabbix Proxy" + } + ] + } + ], + "version": "3.0", + "groups": [ + { + "name": "Templates" + }, + { + "name": "Templates/Applications" + } + ] + } +} diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template/files/template2_50_lower.xml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template/files/template2_50_lower.xml new file mode 100644 index 000000000..93a32f0c5 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template/files/template2_50_lower.xml @@ -0,0 +1,53 @@ +<?xml version="1.0" encoding="UTF-8"?> +<zabbix_export> + <date>2020-05-29T15:22:11Z</date> + <templates> + <template> + <template>ExampleHost</template> + <name>ExampleHost</name> + <description></description> + <groups> + <group> + <name>Templates</name> + </group> + <group> + <name>Templates/Applications</name> + </group> + </groups> + <macros> + <macro> + <macro>{$EXAMPLE_MACRO1}</macro> + <value>1000</value> + </macro> + <macro> + <macro>{$EXAMPLE_MACRO2}</macro> + <value>text</value> + </macro> + <macro> + <macro>{$EXAMPLE_MACRO3}</macro> + <value>text2</value> + </macro> + </macros> + <templates> + <template> + <name>Template App FTP Service</name> + </template> + <template> + <name>Template App Zabbix Proxy</name> + </template> + <template> + <name>Template App HTTP Service</name> + </template> + </templates> + </template> + </templates> + <version>3.0</version> + <groups> + <group> + <name>Templates</name> + </group> + <group> + <name>Templates/Applications</name> + </group> + </groups> +</zabbix_export> diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template/files/template3-changed_54_higher.json b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template/files/template3-changed_54_higher.json new file mode 100644 index 000000000..d1854e8a9 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template/files/template3-changed_54_higher.json @@ -0,0 +1,53 @@ +{ + "zabbix_export": { + "date": "2022-01-23T15:13:26Z", + "groups": [ + { + "name": "Templates", + "uuid": "7df96b18c230490a9a0a9e2307226338" + }, + { + "name": "Templates/Applications", + "uuid": "a571c0d144b14fd4a87a9d9b2aa9fcd6" + } + ], + "templates": [ + { + "groups": [ + { + "name": "Templates" + }, + { + "name": "Templates/Applications" + } + ], + "macros": [ + { + "macro": "{$EXAMPLE_MACRO1}", + "value": "1000" + }, + { + "macro": "{$EXAMPLE_MACRO2}", + "value": "text" + }, + { + "macro": "{$EXAMPLE_MACRO3}", + "value": "text2" + } + ], + "name": "ExampleHost", + "template": "ExampleHost", + "templates": [ + { + "name": "FTP Service" + }, + { + "name": "Zabbix proxy health" + } + ], + "uuid": "cd837ef0edb14e4e875f409bc90af546" + } + ], + "version": "5.4" + } +}
\ No newline at end of file diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template/files/template3_54_higher.json b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template/files/template3_54_higher.json new file mode 100644 index 000000000..ce56f8262 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template/files/template3_54_higher.json @@ -0,0 +1,49 @@ +{ + "zabbix_export": { + "date": "2022-01-23T15:13:26Z", + "groups": [ + { + "name": "Templates", + "uuid": "7df96b18c230490a9a0a9e2307226338" + }, + { + "name": "Templates/Applications", + "uuid": "a571c0d144b14fd4a87a9d9b2aa9fcd6" + } + ], + "templates": [ + { + "groups": [ + { + "name": "Templates" + }, + { + "name": "Templates/Applications" + } + ], + "macros": [ + { + "macro": "{$EXAMPLE_MACRO1}", + "value": "1000" + }, + { + "macro": "{$EXAMPLE_MACRO2}", + "value": "text" + } + ], + "name": "ExampleHost", + "template": "ExampleHost", + "templates": [ + { + "name": "FTP Service" + }, + { + "name": "Zabbix proxy health" + } + ], + "uuid": "cd837ef0edb14e4e875f409bc90af546" + } + ], + "version": "5.4" + } +}
\ No newline at end of file diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template/files/template3_54_higher.xml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template/files/template3_54_higher.xml new file mode 100644 index 000000000..e45b3fd67 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template/files/template3_54_higher.xml @@ -0,0 +1,48 @@ +<?xml version="1.0" encoding="UTF-8"?> +<zabbix_export> + <version>5.4</version> + <date>2022-01-23T15:24:01Z</date> + <groups> + <group> + <uuid>7df96b18c230490a9a0a9e2307226338</uuid> + <name>Templates</name> + </group> + <group> + <uuid>a571c0d144b14fd4a87a9d9b2aa9fcd6</uuid> + <name>Templates/Applications</name> + </group> + </groups> + <templates> + <template> + <uuid>cd837ef0edb14e4e875f409bc90af546</uuid> + <template>ExampleHost</template> + <name>ExampleHost</name> + <templates> + <template> + <name>FTP Service</name> + </template> + <template> + <name>Zabbix proxy health</name> + </template> + </templates> + <groups> + <group> + <name>Templates</name> + </group> + <group> + <name>Templates/Applications</name> + </group> + </groups> + <macros> + <macro> + <macro>{$EXAMPLE_MACRO1}</macro> + <value>1000</value> + </macro> + <macro> + <macro>{$EXAMPLE_MACRO2}</macro> + <value>text</value> + </macro> + </macros> + </template> + </templates> +</zabbix_export>
\ No newline at end of file diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template/meta/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template/meta/main.yml new file mode 100644 index 000000000..acdb704c8 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - setup_zabbix diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template/tasks/import_54_higher.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template/tasks/import_54_higher.yml new file mode 100644 index 000000000..8ce7a51e1 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template/tasks/import_54_higher.yml @@ -0,0 +1,126 @@ +--- + +# +# For Zabbix lower than 5.4 we test against the ExampleHost which was created in the +# main.yml tests. Due to changes in the Zabbix API (mainly because UUIDs) this is +# not possible for 5.4 onwards - so there we first delete the example hosts. +# + +- name: Delete Zabbix template. + zabbix_template: + template_name: ExampleHost + state: absent + register: delete_zabbix_template_result + +- assert: + that: + - delete_zabbix_template_result.changed is sameas true + +- name: Delete Zabbix template (idempotency check). + zabbix_template: + template_name: ExampleHost + state: absent + register: delete_zabbix_template_result + +- assert: + that: + - delete_zabbix_template_result.changed is sameas false + +# +# JSON Tests +# + +- block: + - name: Import Zabbix template from JSON file (idempotency check) - >= Zabbix 5.4. + zabbix_template: + template_json: "{{ lookup('file', 'template3_54_higher.json') }}" + state: present + register: import_template_json + + - name: Assert Zabbix template from JSON file (idempotency check) - >= Zabbix 5.4. + assert: + that: + - import_template_json.changed is sameas true + + - name: Import Zabbix template from JSON file with matching values (idempotency check) - >= Zabbix 5.4. + zabbix_template: + template_json: "{{ lookup('file', 'template3_54_higher.json') }}" + state: present + register: import_template_json + + - name: Assert Zabbix template from JSON file with matching values (idempotency check) - >= Zabbix 5.4. + assert: + that: + - import_template_json.changed is sameas false + +- name: Gather Zabbix template infomation. + zabbix_template_info: + template_name: ExampleHost + format: json + register: gather_template_result + +- block: + - assert: + that: + - gather_template_result.template_json[template_export_key][template_groups_key].0.name == 'Templates' + - gather_template_result.template_json[template_export_key][template_groups_key].1.name == 'Templates/Applications' + - gather_template_result.template_json[template_export_key].templates.0.templates.0.name == 'FTP Service' + - gather_template_result.template_json[template_export_key].templates.0.templates.1.name == 'Zabbix proxy health' + - gather_template_result.template_json[template_export_key].templates.0.macros.0.macro == '{$EXAMPLE_MACRO1}' + - gather_template_result.template_json[template_export_key].templates.0.macros.0.value == '1000' + - gather_template_result.template_json[template_export_key].templates.0.macros.1.macro == '{$EXAMPLE_MACRO2}' + - gather_template_result.template_json[template_export_key].templates.0.macros.1.value == 'text' + +- block: + - name: Import Zabbix template from JSON file with updated values. + zabbix_template: + template_json: "{{ lookup('file', 'template3-changed_54_higher.json') }}" + state: present + register: import_template_json + + - assert: + that: + - import_template_json.changed is sameas true + +- name: Gather Zabbix template infomation. + zabbix_template_info: + template_name: ExampleHost + format: json + register: gather_template_result + +- assert: + that: + - gather_template_result.template_json[template_export_key].templates.0.macros.0.macro == '{$EXAMPLE_MACRO1}' + - gather_template_result.template_json[template_export_key].templates.0.macros.0.value == '1000' + - gather_template_result.template_json[template_export_key].templates.0.macros.1.macro == '{$EXAMPLE_MACRO2}' + - gather_template_result.template_json[template_export_key].templates.0.macros.1.value == 'text' + - gather_template_result.template_json[template_export_key].templates.0.macros.2.macro == '{$EXAMPLE_MACRO3}' + - gather_template_result.template_json[template_export_key].templates.0.macros.2.value == 'text2' + +# +# xml +# + +- block: + - name: Import Zabbix template from XML file with updated values. + zabbix_template: + template_xml: "{{ lookup('file', 'template3_54_higher.xml') }}" + state: present + register: import_template_xml + + - assert: + that: + - import_template_xml.changed is sameas true + +- name: Gather Zabbix template infomation. + zabbix_template_info: + template_name: ExampleHost + format: json + register: gather_template_result + +# zabbix returns values sorted alphabetically so HTTP Service template comes before Zabbix Proxy template +- block: + - assert: + that: + - gather_template_result.template_json[template_export_key].templates.0.templates.0.name == 'FTP Service' + - gather_template_result.template_json[template_export_key].templates.0.templates.1.name == 'Zabbix proxy health' diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template/tasks/import_54_lower.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template/tasks/import_54_lower.yml new file mode 100644 index 000000000..48d180210 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template/tasks/import_54_lower.yml @@ -0,0 +1,120 @@ +--- + +# +# For Zabbix lower than 5.4 we test against the ExampleHost which was created in the +# main.yml tests. Due to changes in the Zabbix API (mainly because UUIDs) this is +# not possible for 5.4 onwards - so there we first delete the Example host. +# + +# +# JSON Tests +# + +- name: Gather Zabbix template infomation. + zabbix_template_info: + template_name: ExampleHost + format: json + register: gather_template_result + +- block: + - assert: + that: + - gather_template_result.template_json[template_export_key].groups.0.name == 'Templates' + - gather_template_result.template_json[template_export_key].groups.1.name == 'Templates/Applications' + - gather_template_result.template_json[template_export_key].templates.0.templates.0.name == 'Template App FTP Service' + - gather_template_result.template_json[template_export_key].templates.0.templates.1.name == 'Template App Zabbix Proxy' + - gather_template_result.template_json[template_export_key].templates.0.macros.0.macro == '{$EXAMPLE_MACRO1}' + - gather_template_result.template_json[template_export_key].templates.0.macros.0.value == '1000' + - gather_template_result.template_json[template_export_key].templates.0.macros.1.macro == '{$EXAMPLE_MACRO2}' + - gather_template_result.template_json[template_export_key].templates.0.macros.1.value == 'text' + +- block: + - name: Import Zabbix template from JSON file with matching values (idempotency check) - < Zabbix 5.4. + zabbix_template: + template_json: "{{ lookup('file', 'template1_50_lower.json') }}" + state: present + register: import_template_json + + - name: Assert Zabbix template from JSON file with matching values (idempotency check) - < Zabbix 5.4. + assert: + that: + - import_template_json.changed is sameas false + +- block: + - name: Import Zabbix template from JSON file with updated values. + zabbix_template: + template_json: "{{ lookup('file', 'template1-changed_50_lower.json') }}" + state: present + register: import_template_json + + - assert: + that: + - import_template_json.changed is sameas true + +- name: Gather Zabbix template infomation. + zabbix_template_info: + template_name: ExampleHost + format: json + register: gather_template_result + +- assert: + that: + - gather_template_result.template_json[template_export_key].templates.0.macros.0.macro == '{$EXAMPLE_MACRO1}' + - gather_template_result.template_json[template_export_key].templates.0.macros.0.value == '1000' + - gather_template_result.template_json[template_export_key].templates.0.macros.1.macro == '{$EXAMPLE_MACRO2}' + - gather_template_result.template_json[template_export_key].templates.0.macros.1.value == 'text' + - gather_template_result.template_json[template_export_key].templates.0.macros.2.macro == '{$EXAMPLE_MACRO3}' + - gather_template_result.template_json[template_export_key].templates.0.macros.2.value == 'text2' + +- name: Dump Zabbix template to JSON format. + zabbix_template: + template_name: ExampleHost + dump_format: json + state: dump + register: template_dump_result + +- assert: + that: + - template_dump_result.deprecations is defined + - template_dump_result.deprecations.0.version == '3.0.0' + +# +# XML Tests +# + +- block: + - name: Import Zabbix template from XML file with updated values. + zabbix_template: + template_xml: "{{ lookup('file', 'template2_50_lower.xml') }}" + state: present + register: import_template_xml + + - assert: + that: + - import_template_xml.changed is sameas true + +- name: Gather Zabbix template infomation. + zabbix_template_info: + template_name: ExampleHost + format: json + register: gather_template_result + +# zabbix returns values sorted alphabetically so HTTP Service template comes before Zabbix Proxy template +- block: + - assert: + that: + - gather_template_result.template_json[template_export_key].templates.0.templates.0.name == 'Template App FTP Service' + - gather_template_result.template_json[template_export_key].templates.0.templates.1.name == 'Template App HTTP Service' + - gather_template_result.template_json[template_export_key].templates.0.templates.2.name == 'Template App Zabbix Proxy' + +- name: Dump Zabbix template to XML format. + zabbix_template: + template_name: ExampleHost + dump_format: xml + state: dump + register: template_dump_result + +- assert: + that: + - template_dump_result.deprecations is defined + - template_dump_result.deprecations.0.version == '3.0.0' diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template/tasks/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template/tasks/main.yml new file mode 100644 index 000000000..66505f9a7 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template/tasks/main.yml @@ -0,0 +1,330 @@ +--- +- name: Create FTP Service Template + zabbix_template: + template_name: FTP Service + template_groups: + - 'Templates' + state: present + +- name: Create a new Zabbix template (check mode). + zabbix_template: + template_name: ExampleHost + template_groups: + - 'Templates' + - 'Templates/Applications' + state: present + register: create_zabbix_template_result + check_mode: true + +- assert: + that: + - create_zabbix_template_result.changed is sameas true + +- name: Create a new Zabbix template. + zabbix_template: + template_name: ExampleHost + template_groups: + - 'Templates' + - 'Templates/Applications' + state: present + register: create_zabbix_template_result + +- assert: + that: + - create_zabbix_template_result.changed is sameas true + +- name: Create a new Zabbix template (idempotency check). + zabbix_template: + template_name: ExampleHost + template_groups: + - 'Templates' + - 'Templates/Applications' + state: present + register: create_zabbix_template_result + +- assert: + that: + - create_zabbix_template_result.changed is sameas false + +- name: Create a new Zabbix template with linked templates. + zabbix_template: + template_name: ExampleHostWithLinked + template_groups: + - 'Templates' + - 'Templates/Applications' + link_templates: + - "{{ 'Zabbix proxy health' if zabbix_version | float >= 5.4 else 'Template App Zabbix Proxy' }}" + - "{{ 'FTP Service' if zabbix_version | float >= 5.4 else 'Template App FTP Service' }}" + state: present + register: create_zabbix_template_linked_result + +- assert: + that: + - create_zabbix_template_linked_result.changed is sameas true + +- name: Gather Zabbix template infomation. + zabbix_template_info: + template_name: ExampleHost + format: json + register: gather_template_result + +- name: "test - Set key to template_export_key variable(This deals with the key being masked)" + set_fact: + template_export_key: "{{ item }}" + loop: "{{ gather_template_result.template_json.keys() | list }}" + when: + - item | regex_search('_export') + +- assert: + that: + - gather_template_result.template_json[template_export_key][template_groups_key].0.name == 'Templates' + - gather_template_result.template_json[template_export_key][template_groups_key].1.name == 'Templates/Applications' + +- name: Add link_templates to Zabbix template. + zabbix_template: + template_name: ExampleHost + template_groups: + - 'Templates' + - 'Templates/Applications' + link_templates: + - "{{ 'Zabbix proxy health' if zabbix_version | float >= 5.4 else 'Template App Zabbix Proxy' }}" + - "{{ 'FTP Service' if zabbix_version | float >= 5.4 else 'Template App FTP Service' }}" + state: present + register: update_zabbix_template_result + +- assert: + that: + - update_zabbix_template_result.changed is sameas true + +- name: Add link_templates to Zabbix template (idempotency check). + zabbix_template: + template_name: ExampleHost + template_groups: + - 'Templates' + - 'Templates/Applications' + link_templates: + - "{{ 'Zabbix proxy health' if zabbix_version | float >= 5.4 else 'Template App Zabbix Proxy' }}" + - "{{ 'FTP Service' if zabbix_version | float >= 5.4 else 'Template App FTP Service' }}" + state: present + register: update_zabbix_template_result + +- assert: + that: + - update_zabbix_template_result.changed is sameas false + +- name: Gather Zabbix template infomation. + zabbix_template_info: + template_name: ExampleHost + format: json + register: gather_template_result + +- when: zabbix_version is version('5.4', '<') + block: + - assert: + that: + - gather_template_result.template_json[template_export_key].groups.0.name == 'Templates' + - gather_template_result.template_json[template_export_key].groups.1.name == 'Templates/Applications' + - gather_template_result.template_json[template_export_key].templates.0.templates.0.name == 'Template App FTP Service' + - gather_template_result.template_json[template_export_key].templates.0.templates.1.name == 'Template App Zabbix Proxy' + +- when: zabbix_version is version('5.4', '>=') + block: + - assert: + that: + - gather_template_result.template_json[template_export_key][template_groups_key].0.name == 'Templates' + - gather_template_result.template_json[template_export_key][template_groups_key].1.name == 'Templates/Applications' + - gather_template_result.template_json[template_export_key].templates.0.templates.0.name == 'FTP Service' + - gather_template_result.template_json[template_export_key].templates.0.templates.1.name == 'Zabbix proxy health' + +- name: Add macros to Zabbix template. + zabbix_template: + template_name: ExampleHost + template_groups: + - 'Templates' + - 'Templates/Applications' + link_templates: + - "{{ 'Zabbix proxy health' if zabbix_version | float >= 5.4 else 'Template App Zabbix Proxy' }}" + - "{{ 'FTP Service' if zabbix_version | float >= 5.4 else 'Template App FTP Service' }}" + macros: + - macro: '{$EXAMPLE_MACRO1}' + value: 1000 + - macro: '{$EXAMPLE_MACRO2}' + value: 'text' + state: present + register: update_zabbix_template_result + +- assert: + that: + - update_zabbix_template_result.changed is sameas true + +- name: Add macros to Zabbix template (idempotency check). + zabbix_template: + template_name: ExampleHost + template_groups: + - 'Templates' + - 'Templates/Applications' + link_templates: + - "{{ 'Zabbix proxy health' if zabbix_version | float >= 5.4 else 'Template App Zabbix Proxy' }}" + - "{{ 'FTP Service' if zabbix_version | float >= 5.4 else 'Template App FTP Service' }}" + macros: + - macro: '{$EXAMPLE_MACRO1}' + value: 1000 + - macro: '{$EXAMPLE_MACRO2}' + value: 'text' + state: present + register: update_zabbix_template_result + +- assert: + that: + - update_zabbix_template_result.changed is sameas false + +- name: Add tags to Zabbix template. + zabbix_template: + template_name: ExampleHost + template_groups: + - 'Templates' + - 'Templates/Applications' + link_templates: + - "{{ 'Zabbix proxy health' if zabbix_version | float >= 5.4 else 'Template App Zabbix Proxy' }}" + - "{{ 'FTP Service' if zabbix_version | float >= 5.4 else 'Template App FTP Service' }}" + macros: + - macro: '{$EXAMPLE_MACRO1}' + value: 1000 + - macro: '{$EXAMPLE_MACRO2}' + value: 'text' + tags: + - tag: tag1 + value: 1000 + - tag: tag2 + value: text + state: present + register: update_zabbix_template_result + when: zabbix_version is version('4.2', '>=') + +- assert: + that: update_zabbix_template_result is changed + when: zabbix_version is version('4.2', '>=') + +- name: Add tags to Zabbix template (idempotency check). + zabbix_template: + template_name: ExampleHost + template_groups: + - 'Templates' + - 'Templates/Applications' + link_templates: + - "{{ 'Zabbix proxy health' if zabbix_version | float >= 5.4 else 'Template App Zabbix Proxy' }}" + - "{{ 'FTP Service' if zabbix_version | float >= 5.4 else 'Template App FTP Service' }}" + macros: + - macro: '{$EXAMPLE_MACRO1}' + value: 1000 + - macro: '{$EXAMPLE_MACRO2}' + value: 'text' + tags: + - tag: tag1 + value: 1000 + - tag: tag2 + value: text + state: present + register: update_zabbix_template_result + when: zabbix_version is version('4.2', '>=') + +- assert: + that: update_zabbix_template_result is not changed + when: zabbix_version is version('4.2', '>=') + +- name: Remove tags from Zabbix template. + zabbix_template: + template_name: ExampleHost + template_groups: + - 'Templates' + - 'Templates/Applications' + link_templates: + - "{{ 'Zabbix proxy health' if zabbix_version | float >= 5.4 else 'Template App Zabbix Proxy' }}" + - "{{ 'FTP Service' if zabbix_version | float >= 5.4 else 'Template App FTP Service' }}" + macros: + - macro: '{$EXAMPLE_MACRO1}' + value: 1000 + - macro: '{$EXAMPLE_MACRO2}' + value: 'text' + tags: [] + state: present + register: update_zabbix_template_result + when: zabbix_version is version('4.2', '>=') + +- assert: + that: update_zabbix_template_result is changed + when: zabbix_version is version('4.2', '>=') + +# #### +# Import template tests +# #### + +- include_tasks: import_54_lower.yml + when: zabbix_version is version('5.4', '<') + +- include_tasks: import_54_higher.yml + when: zabbix_version is version('5.4', '>=') + +# +# Cleanup again +# + +- name: Delete Zabbix template. + zabbix_template: + template_name: ExampleHost + state: absent + register: delete_zabbix_template_result + +- assert: + that: + - delete_zabbix_template_result.changed is sameas true + +- name: Delete Zabbix template (idempotency check). + zabbix_template: + template_name: ExampleHost + state: absent + register: delete_zabbix_template_result + +- assert: + that: + - delete_zabbix_template_result.changed is sameas false + +# +# Unicode stuff +# + +- when: zabbix_version is version('5.0', '>=') + block: + # The test if decode Unicode correctly and to be imported the template. + # https://github.com/ansible-collections/community.zabbix/issues/314 + - name: Import Zabbix template from JSON file with unicode. + zabbix_template: + template_json: "{{ lookup('file', 'template1_50_higher_decode_unicode.json') }}" + state: present + register: import_template_json + + - name: Gather Zabbix template infomation. + zabbix_template_info: + template_name: ExampleTemplate314 + format: json + register: gather_template_result + + - assert: + that: + - import_template_json.changed is sameas true + - gather_template_result.template_json.zabbix_export.templates.0.description == "\u30c6\u30b9\u30c8\u30b3\u30e1\u30f3\u30c8" + + - name: Delete Zabbix template. + zabbix_template: + template_name: ExampleTemplate314 + state: absent + register: delete_zabbix_template_result + + - assert: + that: + - delete_zabbix_template_result.changed is sameas true + +- name: Clean up ExampleHostWithLinked template + zabbix_template: + template_name: ExampleHostWithLinked + state: absent diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template_info/defaults/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template_info/defaults/main.yml new file mode 100644 index 000000000..6f736db53 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template_info/defaults/main.yml @@ -0,0 +1,2 @@ +--- +template_groups_key: "{{ 'template_groups' if zabbix_version is version('6.2', '>=') else 'groups' }}" diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template_info/meta/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template_info/meta/main.yml new file mode 100644 index 000000000..acdb704c8 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template_info/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - setup_zabbix diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template_info/tasks/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template_info/tasks/main.yml new file mode 100644 index 000000000..3146c04b3 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_template_info/tasks/main.yml @@ -0,0 +1,117 @@ +--- +- name: "test - Prepare integration tests for zabbix_template_info module" + zabbix_template: + template_name: ExampleTemplateForTempleteInfoModule + template_groups: + - Templates + state: present + register: prepare_result + +- assert: + that: + - prepare_result.changed is sameas true + +- name: "test - Fetch template info as a JSON format from Zabbix Server" + zabbix_template_info: + template_name: ExampleTemplateForTempleteInfoModule + format: json + register: fetch_template_json_format_result + +- name: "test - Set key to template_export_key variable(This deals with the key being masked)" + set_fact: + template_export_key: "{{ item }}" + loop: "{{ fetch_template_json_format_result.template_json.keys() | list }}" + when: + - item | regex_search('_export') + +- assert: + that: + - fetch_template_json_format_result.template_json[template_export_key].date is defined + when: zabbix_version is version('6.2', '<=') + +- assert: + that: + - fetch_template_json_format_result.template_json[template_export_key][template_groups_key].0.name == "Templates" + - fetch_template_json_format_result.template_json[template_export_key].templates.0.name == "ExampleTemplateForTempleteInfoModule" + - fetch_template_json_format_result.template_json[template_export_key].templates.0.template == "ExampleTemplateForTempleteInfoModule" + +- name: "test - Fetch template info as a JSON format with omit_date parameter from Zabbix Server" + zabbix_template_info: + template_name: ExampleTemplateForTempleteInfoModule + format: json + omit_date: true + register: fetch_template_json_format_omit_date_result + +- assert: + that: + - fetch_template_json_format_omit_date_result.template_json[template_export_key].date is not defined + - fetch_template_json_format_omit_date_result.template_json[template_export_key][template_groups_key].0.name == "Templates" + - fetch_template_json_format_omit_date_result.template_json[template_export_key].templates.0.name == "ExampleTemplateForTempleteInfoModule" + - fetch_template_json_format_omit_date_result.template_json[template_export_key].templates.0.template == "ExampleTemplateForTempleteInfoModule" + +- name: "test - Fetch template info as a XML format from Zabbix Server" + zabbix_template_info: + template_name: ExampleTemplateForTempleteInfoModule + format: xml + register: fetch_template_xml_format_result + +- assert: + that: + - fetch_template_xml_format_result.template_xml | regex_search('<date>.*</date>') is defined + - fetch_template_xml_format_result.template_xml | regex_search('</date><groups><group><name>Templates</name></group></groups><templates>') is defined + - fetch_template_xml_format_result.template_xml | regex_search('<templates><template><template>ExampleTemplateForTempleteInfoModule</template><name>ExampleTemplateForTempleteInfoModule</name><groups><group><name>Templates</name></group></groups></template></templates>') is defined + +- name: "test - Fetch template info as a XML format with omit_date parameter from Zabbix Server" + zabbix_template_info: + template_name: ExampleTemplateForTempleteInfoModule + format: xml + omit_date: true + register: fetch_template_xml_format_omit_date_result + +- assert: + that: + - fetch_template_xml_format_omit_date_result.template_xml | regex_search('<date>.*</date>') is none + - fetch_template_xml_format_omit_date_result.template_xml | regex_search('</date><groups><group><name>Templates</name></group></groups><templates>') is defined + - fetch_template_xml_format_omit_date_result.template_xml | regex_search('<templates><template><template>ExampleTemplateForTempleteInfoModule</template><name>ExampleTemplateForTempleteInfoModule</name><groups><group><name>Templates</name></group></groups></template></templates>') is defined + +- name: "test - Fetch template info as a YAML format from Zabbix Server" + zabbix_template_info: + template_name: ExampleTemplateForTempleteInfoModule + format: yaml + register: fetch_template_yaml_format_result + when: zabbix_version is version('5.2', '>=') + +- assert: + that: + - fetch_template_yaml_format_result.template_yaml | regex_search('date: .+') is defined + - fetch_template_yaml_format_result.template_yaml | regex_search('name: Templates') is defined + - fetch_template_yaml_format_result.template_yaml | regex_search('template: ExampleTemplateForTempleteInfoModule') is defined + when: zabbix_version is version('5.2', '>=') + +- name: "test - Fetch template info as a YAML format with omit_date parameter from Zabbix Server" + zabbix_template_info: + template_name: ExampleTemplateForTempleteInfoModule + format: yaml + omit_date: true + register: fetch_template_yaml_format_omit_date_result + when: zabbix_version is version('5.2', '>=') + +- assert: + that: + - fetch_template_yaml_format_result.template_yaml | regex_search('date: .+') is not defined + - fetch_template_yaml_format_result.template_yaml | regex_search('name: Templates') is defined + - fetch_template_yaml_format_result.template_yaml | regex_search('template: ExampleTemplateForTempleteInfoModule') is defined + when: zabbix_version is version('5.2', '>=') + +- name: "test - Fetch template info with none format from Zabbix Server" + zabbix_template_info: + template_name: ExampleTemplateForTempleteInfoModule + format: none + register: fetch_template_none_format_result + +- assert: + that: + - fetch_template_none_format_result.template_id is defined + - fetch_template_none_format_result.template_json is not defined + - fetch_template_none_format_result.template_xml is not defined + - fetch_template_none_format_result.template_yaml is not defined diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_user/meta/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_user/meta/main.yml new file mode 100644 index 000000000..acdb704c8 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_user/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - setup_zabbix diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_user/tasks/for_zabbix_50_lower.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_user/tasks/for_zabbix_50_lower.yml new file mode 100644 index 000000000..b658e970a --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_user/tasks/for_zabbix_50_lower.yml @@ -0,0 +1,1044 @@ +--- +# New user create test from here +- name: test - Create a new Zabbix user with check_mode and diff + zabbix_user: + alias: example1 + name: example + surname: test + usrgrps: + - Guests + passwd: password + check_mode: true + diff: true + register: create_zabbix_user_result + +- assert: + that: + - create_zabbix_user_result.changed is sameas true + +- name: test - Create a new Zabbix user + zabbix_user: + alias: example1 + name: example + surname: test + usrgrps: + - Guests + passwd: password + register: create_zabbix_user_result + +- assert: + that: + - create_zabbix_user_result.changed is sameas true + +- name: test - Create a new Zabbix user(again) + zabbix_user: + alias: example1 + name: example + surname: test + usrgrps: + - Guests + passwd: password + register: create_zabbix_user_result + +- assert: + that: + - not create_zabbix_user_result.changed is sameas true + +# Parameter add test from here to existing user +- name: test - Add user group to existing user + zabbix_user: + alias: example1 + name: example + surname: test + usrgrps: + - Guests + - Zabbix administrators + passwd: password + register: add_usergroup_to_existing_user_result + +- assert: + that: + - add_usergroup_to_existing_user_result.changed is sameas true + +- name: test - Add user medias(Email) to existing user + zabbix_user: + alias: example1 + name: example + surname: test + usrgrps: + - Guests + - Zabbix administrators + passwd: password + user_medias: + - mediatype: Email + sendto: example@example.com + period: 1-7,00:00-24:00 + severity: + not_classified: false + information: true + warning: true + average: true + high: true + disaster: true + active: true + register: add_user_medias_to_existing_user_result + +- assert: + that: + - add_user_medias_to_existing_user_result.changed is sameas true + +- name: test - Add multiple user medias(Email and SMS) to existing user + zabbix_user: + alias: example1 + name: example + surname: test + usrgrps: + - Guests + - Zabbix administrators + passwd: password + user_medias: + - mediatype: Email + sendto: example@example.com + period: 1-7,00:00-24:00 + severity: + not_classified: false + information: true + warning: true + average: true + high: true + disaster: true + active: true + - mediatype: SMS + sendto: example@example.com + period: 1-5,01:00-23:00 + severity: + not_classified: false + information: true + warning: true + average: false + high: true + disaster: true + active: true + register: add_user_medias_to_existing_user_result + +- assert: + that: + - add_user_medias_to_existing_user_result.changed is sameas true + +# Existing parameter updates test from here +- name: test - Update password parameter for existing user + zabbix_user: + alias: example1 + name: example + surname: test + usrgrps: + - Guests + - Zabbix administrators + passwd: update_password + override_passwd: true + user_medias: + - mediatype: Email + sendto: example@example.com + period: 1-7,00:00-24:00 + severity: + not_classified: false + information: true + warning: true + average: true + high: true + disaster: true + active: true + - mediatype: SMS + sendto: example@example.com + period: 1-5,01:00-23:00 + severity: + not_classified: false + information: true + warning: true + average: false + high: true + disaster: true + active: true + register: update_password_parameter_existing_user_result + +- assert: + that: + - update_password_parameter_existing_user_result.changed is sameas true + +- name: test - Update autologin parameter for existing user + zabbix_user: + alias: example1 + name: example + surname: test + usrgrps: + - Guests + - Zabbix administrators + passwd: update_password + autologin: true + user_medias: + - mediatype: Email + sendto: example@example.com + period: 1-7,00:00-24:00 + severity: + not_classified: false + information: true + warning: true + average: true + high: true + disaster: true + active: true + - mediatype: SMS + sendto: example@example.com + period: 1-5,01:00-23:00 + severity: + not_classified: false + information: true + warning: true + average: false + high: true + disaster: true + active: true + register: update_autologin_parameter_existing_user_result + +- assert: + that: + - update_autologin_parameter_existing_user_result.changed is sameas true + +- name: test - Update autologout parameter for existing user + zabbix_user: + alias: example1 + name: example + surname: test + usrgrps: + - Guests + - Zabbix administrators + passwd: update_password + autologout: 500 + user_medias: + - mediatype: Email + sendto: example@example.com + period: 1-7,00:00-24:00 + severity: + not_classified: false + information: true + warning: true + average: true + high: true + disaster: true + active: true + - mediatype: SMS + sendto: example@example.com + period: 1-5,01:00-23:00 + severity: + not_classified: false + information: true + warning: true + average: false + high: true + disaster: true + active: true + register: update_autologout_parameter_existing_user_result + +- assert: + that: + - update_autologout_parameter_existing_user_result.changed is sameas true + +- name: test - Update refresh parameter for existing user + zabbix_user: + alias: example1 + name: example + surname: test + usrgrps: + - Guests + - Zabbix administrators + passwd: update_password + autologout: 500 + refresh: 60 + user_medias: + - mediatype: Email + sendto: example@example.com + period: 1-7,00:00-24:00 + severity: + not_classified: false + information: true + warning: true + average: true + high: true + disaster: true + active: true + - mediatype: SMS + sendto: example@example.com + period: 1-5,01:00-23:00 + severity: + not_classified: false + information: true + warning: true + average: false + high: true + disaster: true + active: true + register: update_refresh_parameter_existing_user_result + +- assert: + that: + - update_refresh_parameter_existing_user_result.changed is sameas true + +- name: test - Update rows_per_page parameter for existing user + zabbix_user: + alias: example1 + name: example + surname: test + usrgrps: + - Guests + - Zabbix administrators + passwd: update_password + autologout: 500 + refresh: 60 + rows_per_page: 300 + user_medias: + - mediatype: Email + sendto: example@example.com + period: 1-7,00:00-24:00 + severity: + not_classified: false + information: true + warning: true + average: true + high: true + disaster: true + active: true + - mediatype: SMS + sendto: example@example.com + period: 1-5,01:00-23:00 + severity: + not_classified: false + information: true + warning: true + average: false + high: true + disaster: true + active: true + register: update_rows_per_page_parameter_existing_user_result + +- assert: + that: + - update_rows_per_page_parameter_existing_user_result.changed is sameas true + +- name: test - Update after_login_url parameter for existing user + zabbix_user: + alias: example1 + name: example + surname: test + usrgrps: + - Guests + - Zabbix administrators + passwd: update_password + autologout: 500 + refresh: 60 + rows_per_page: 300 + after_login_url: http://example.com + user_medias: + - mediatype: Email + sendto: example@example.com + period: 1-7,00:00-24:00 + severity: + not_classified: false + information: true + warning: true + average: true + high: true + disaster: true + active: true + - mediatype: SMS + sendto: example@example.com + period: 1-5,01:00-23:00 + severity: + not_classified: false + information: true + warning: true + average: false + high: true + disaster: true + active: true + register: update_after_login_url_parameter_existing_user_result + +- assert: + that: + - update_after_login_url_parameter_existing_user_result.changed is sameas true + +- name: test - Update theme parameter for existing user + zabbix_user: + alias: example1 + name: example + surname: test + usrgrps: + - Guests + - Zabbix administrators + passwd: update_password + autologout: 500 + refresh: 60 + rows_per_page: 300 + after_login_url: http://example.com + theme: "{{ item }}" + user_medias: + - mediatype: Email + sendto: example@example.com + period: 1-7,00:00-24:00 + severity: + not_classified: false + information: true + warning: true + average: true + high: true + disaster: true + active: true + - mediatype: SMS + sendto: example@example.com + period: 1-5,01:00-23:00 + severity: + not_classified: false + information: true + warning: true + average: false + high: true + disaster: true + active: true + loop: + - blue-theme + - dark-theme + register: update_theme_parameter_existing_user_result + +- assert: + that: + - item.changed is sameas true + loop: "{{ update_theme_parameter_existing_user_result.results }}" + +- name: test - Update type parameter for existing user + zabbix_user: + alias: example1 + name: example + surname: test + usrgrps: + - Guests + - Zabbix administrators + passwd: update_password + autologout: 500 + refresh: 60 + rows_per_page: 300 + after_login_url: http://example.com + theme: dark-theme + type: "{{ item }}" + user_medias: + - mediatype: Email + sendto: example@example.com + period: 1-7,00:00-24:00 + severity: + not_classified: false + information: true + warning: true + average: true + high: true + disaster: true + active: true + - mediatype: SMS + sendto: example@example.com + period: 1-5,01:00-23:00 + severity: + not_classified: false + information: true + warning: true + average: false + high: true + disaster: true + active: true + loop: + - Zabbix admin + - Zabbix super admin + register: update_type_parameter_existing_user_result + +- assert: + that: + - item.changed is sameas true + loop: "{{ update_type_parameter_existing_user_result.results }}" + +- name: test - Update lang parameter for existing user + zabbix_user: + alias: example1 + name: example + surname: test + usrgrps: + - Guests + - Zabbix administrators + passwd: update_password + autologout: 500 + refresh: 60 + rows_per_page: 300 + after_login_url: http://example.com + theme: dark-theme + type: Zabbix super admin + lang: en_US + user_medias: + - mediatype: Email + sendto: example@example.com + period: 1-7,00:00-24:00 + severity: + not_classified: false + information: true + warning: true + average: true + high: true + disaster: true + active: true + - mediatype: SMS + sendto: example@example.com + period: 1-5,01:00-23:00 + severity: + not_classified: false + information: true + warning: true + average: false + high: true + disaster: true + active: true + register: update_lang_parameter_existing_user_result + +- assert: + that: + - update_lang_parameter_existing_user_result.changed is sameas true + +- name: test - Update name and surname parameter for existing user + zabbix_user: + alias: example1 + name: example2 + surname: test2 + usrgrps: + - Guests + - Zabbix administrators + passwd: update_password + autologout: 500 + refresh: 60 + rows_per_page: 300 + after_login_url: http://example.com + theme: dark-theme + type: Zabbix super admin + lang: en_US + user_medias: + - mediatype: Email + sendto: example@example.com + period: 1-7,00:00-24:00 + severity: + not_classified: false + information: true + warning: true + average: true + high: true + disaster: true + active: true + - mediatype: SMS + sendto: example@example.com + period: 1-5,01:00-23:00 + severity: + not_classified: false + information: true + warning: true + average: false + high: true + disaster: true + active: true + register: update_name_and_surname_parameter_existing_user_result + +- assert: + that: + - update_name_and_surname_parameter_existing_user_result.changed is sameas true + +- name: test - Update lang parameter for existing user with check_mode and diff + zabbix_user: + alias: example1 + name: example2 + surname: test2 + usrgrps: + - Guests + - Zabbix administrators + passwd: update_password + autologout: 500 + refresh: 60 + rows_per_page: 300 + after_login_url: http://example.com + theme: dark-theme + type: Zabbix super admin + lang: en_GB + user_medias: + - mediatype: Email + sendto: example@example.com + period: 1-7,00:00-24:00 + severity: + not_classified: false + information: true + warning: true + average: true + high: true + disaster: true + active: true + - mediatype: SMS + sendto: example@example.com + period: 1-5,01:00-23:00 + severity: + not_classified: false + information: true + warning: true + average: false + high: true + disaster: true + active: true + check_mode: true + diff: true + register: update_lang_parameter_existing_user_with_check_mode_diff_result + +- assert: + that: + - update_lang_parameter_existing_user_with_check_mode_diff_result.changed is sameas true + +- name: test - Update lang parameter for existing user + zabbix_user: + alias: example1 + name: example2 + surname: test2 + usrgrps: + - Guests + - Zabbix administrators + passwd: update_password + autologout: 500 + refresh: 60 + rows_per_page: 300 + after_login_url: http://example.com + theme: dark-theme + type: Zabbix super admin + lang: en_GB + user_medias: + - mediatype: Email + sendto: example@example.com + period: 1-7,00:00-24:00 + severity: + not_classified: false + information: true + warning: true + average: true + high: true + disaster: true + active: true + - mediatype: SMS + sendto: example@example.com + period: 1-5,01:00-23:00 + severity: + not_classified: false + information: true + warning: true + average: false + high: true + disaster: true + active: true + register: update_lang_parameter_existing_user_result + +- assert: + that: + - update_lang_parameter_existing_user_result.changed is sameas true + +- name: test - Update lang parameter for existing user(again) + zabbix_user: + alias: example1 + name: example2 + surname: test2 + usrgrps: + - Guests + - Zabbix administrators + passwd: update_password + autologout: 500 + refresh: 60 + rows_per_page: 300 + after_login_url: http://example.com + theme: dark-theme + type: Zabbix super admin + lang: en_GB + user_medias: + - mediatype: Email + sendto: example@example.com + period: 1-7,00:00-24:00 + severity: + not_classified: false + information: true + warning: true + average: true + high: true + disaster: true + active: true + - mediatype: SMS + sendto: example@example.com + period: 1-5,01:00-23:00 + severity: + not_classified: false + information: true + warning: true + average: false + high: true + disaster: true + active: true + register: update_lang_parameter_existing_user_result + +- assert: + that: + - not update_lang_parameter_existing_user_result.changed is sameas true + +# Parameter delete test from here from existing user +- name: test - Delete user medias(SMS) for existing user with check_mode and diff + zabbix_user: + alias: example1 + name: example2 + surname: test2 + usrgrps: + - Guests + - Zabbix administrators + passwd: update_password + autologout: 500 + refresh: 60 + rows_per_page: 300 + after_login_url: http://example.com + theme: dark-theme + type: Zabbix super admin + lang: en_GB + user_medias: + - mediatype: Email + sendto: example@example.com + period: 1-7,00:00-24:00 + severity: + not_classified: false + information: true + warning: true + average: true + high: true + disaster: true + active: true + check_mode: true + diff: true + register: delete_user_medias_existing_user_result + +- assert: + that: + - delete_user_medias_existing_user_result.changed is sameas true + +- name: test - Delete user medias(SMS) for existing user + zabbix_user: + alias: example1 + name: example2 + surname: test2 + usrgrps: + - Guests + - Zabbix administrators + passwd: update_password + autologout: 500 + refresh: 60 + rows_per_page: 300 + after_login_url: http://example.com + theme: dark-theme + type: Zabbix super admin + lang: en_GB + user_medias: + - mediatype: Email + sendto: example@example.com + period: 1-7,00:00-24:00 + severity: + not_classified: false + information: true + warning: true + average: true + high: true + disaster: true + active: true + register: delete_user_medias_existing_user_result + +- assert: + that: + - delete_user_medias_existing_user_result.changed is sameas true + +- name: test - Delete user group for existing user + zabbix_user: + alias: example1 + name: example2 + surname: test2 + usrgrps: + - Zabbix administrators + passwd: update_password + autologout: 500 + refresh: 60 + rows_per_page: 300 + after_login_url: http://example.com + theme: dark-theme + type: Zabbix super admin + lang: en_GB + user_medias: + - mediatype: Email + sendto: example@example.com + period: 1-7,00:00-24:00 + severity: + not_classified: false + information: true + warning: true + average: true + high: true + disaster: true + active: true + register: delete_user_group_existing_user_result + +- assert: + that: + - delete_user_group_existing_user_result.changed is sameas true + +- name: test - optional user_medias + zabbix_user: + alias: example1 + name: example2 + surname: test2 + usrgrps: + - Zabbix administrators + passwd: update_password + autologout: 500 + refresh: 60 + rows_per_page: 300 + after_login_url: http://example.com + theme: dark-theme + type: Zabbix super admin + lang: en_GB + register: update_user_optional_user_medias_existing_user_result + +- assert: + that: + - update_user_optional_user_medias_existing_user_result.changed is sameas False + +- name: test - Delete existing user with check_mode and diff + zabbix_user: + alias: example1 + state: absent + check_mode: true + diff: true + register: delete_existing_user_result + +- assert: + that: + - delete_existing_user_result.changed is sameas true + +- name: test - Delete existing user + zabbix_user: + alias: example1 + state: absent + register: delete_existing_user_result + +- assert: + that: + - delete_existing_user_result.changed is sameas true + +- name: test - Delete existing user(again) + zabbix_user: + alias: example1 + state: absent + register: delete_existing_user_result + +- assert: + that: + - not delete_existing_user_result.changed is sameas true + +- when: zabbix_version is version('4.0', '<') + block: + - name: test - Create new password-less user without LDAP group (fail, <4.0) + zabbix_user: + alias: example2alias + name: example2 + surname: testldap + usrgrps: + - Guests + register: create_zabbix_user_ldap_fail + ignore_errors: true + + - assert: + that: + - create_zabbix_user_ldap_fail.failed is sameas True + +- when: zabbix_version is version('4.0', '>=') + block: + - name: test prepare - Create LDAP user group + zabbix_usergroup: + name: testLDAPgrp + gui_access: LDAP + register: zbxuser_create_ldap_group + + - assert: + that: + - zbxuser_create_ldap_group.changed is sameas True + + - name: test - Create new password-less user without LDAP group (fail) + zabbix_user: + alias: example2alias + name: example2 + surname: testldap + usrgrps: + - Guests + register: create_zabbix_user_ldap_fail + ignore_errors: true + + - assert: + that: + - create_zabbix_user_ldap_fail.failed is sameas True + + - name: test - Create new password-less user as member in LDAP group + zabbix_user: + alias: example2alias + name: example2 + surname: testldap + usrgrps: + - testLDAPgrp + register: create_zabbix_user_ldap_result + + - assert: + that: + - create_zabbix_user_ldap_result.changed is sameas True + + - name: test - Create new password-less user as member in LDAP group (again) + zabbix_user: + alias: example2alias + name: example2 + surname: testldap + usrgrps: + - testLDAPgrp + register: create_zabbix_user_ldap_result + + - assert: + that: + - create_zabbix_user_ldap_result.changed is sameas False + + - name: test - Delete existing user + zabbix_user: + alias: example2alias + state: absent + register: delete_existing_user_result + + - assert: + that: + - delete_existing_user_result.changed is sameas true + +# The tests are to check the patch for PR hasn't a problem. +# https://github.com/ansible-collections/community.zabbix/pull/382 +- name: test - Create a zabbix user with minimum parameters + zabbix_user: + alias: example2 + usrgrps: + - Guests + passwd: password + register: create_zabbix_user_with_minimum_params_result + +- assert: + that: + - create_zabbix_user_with_minimum_params_result.changed is sameas true + +- name: test - Create a zabbix user with minimum parameters(again) + zabbix_user: + alias: example2 + usrgrps: + - Guests + passwd: password + register: create_zabbix_user_with_minimum_params_result + +- assert: + that: + - create_zabbix_user_with_minimum_params_result.changed is sameas false + +- name: test - Update the parameters without role_name + zabbix_user: + alias: example2 + name: example2 + surname: test + usrgrps: + - Guests + passwd: password + register: update_params_without_role_name_result + +- assert: + that: + - update_params_without_role_name_result.changed is sameas true + +- name: test - Update the parameters without role_name(again) + zabbix_user: + alias: example2 + name: example2 + surname: test + usrgrps: + - Guests + passwd: password + register: update_params_without_role_name_result + +- assert: + that: + - update_params_without_role_name_result.changed is sameas false + +- name: test - Add user medias(Email) as list to existing user + zabbix_user: + alias: example2 + name: example2 + surname: test + usrgrps: + - Guests + passwd: G$jd_79!jw + user_medias: + - mediatype: Email + sendto: + - example@example.com + - example1@example.com + period: 1-7,00:00-24:00 + severity: + not_classified: false + information: true + warning: true + average: true + high: true + disaster: true + active: true + register: add_user_email_media_as_list_to_existing_user_result + +- assert: + that: + - add_user_email_media_as_list_to_existing_user_result.changed is sameas true + +- name: test - Add user medias(Email) as list to existing user(again) + zabbix_user: + alias: example2 + name: example2 + surname: test + usrgrps: + - Guests + passwd: G$jd_79!jw + user_medias: + - mediatype: Email + sendto: + - example@example.com + - example1@example.com + period: 1-7,00:00-24:00 + severity: + not_classified: false + information: true + warning: true + average: true + high: true + disaster: true + active: true + register: add_user_email_media_as_list_to_existing_user_result + +- assert: + that: + - add_user_email_media_as_list_to_existing_user_result.changed is sameas false + +- name: test - Delete existing user + zabbix_user: + alias: example2 + state: absent + +- name: test prepare - Delete LDAP user group + zabbix_usergroup: + name: testLDAPgrp + state: absent diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_user/tasks/for_zabbix_54_higher.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_user/tasks/for_zabbix_54_higher.yml new file mode 100644 index 000000000..9d3d913ce --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_user/tasks/for_zabbix_54_higher.yml @@ -0,0 +1,1100 @@ +--- +# New user create test from here +- name: test - Create a new Zabbix user with check_mode and diff + zabbix_user: + alias: example1 + name: example + surname: test + usrgrps: + - Guests + passwd: G$jd_79!jw + check_mode: true + diff: true + register: create_zabbix_user_result + +- assert: + that: + - create_zabbix_user_result.changed is sameas true + +- name: test - Create a new Zabbix user + zabbix_user: + alias: example1 + name: example + surname: test + usrgrps: + - Guests + passwd: G$jd_79!jw + register: create_zabbix_user_result + +- assert: + that: + - create_zabbix_user_result.changed is sameas true + +- name: test - Create a new Zabbix user(again) + zabbix_user: + alias: example1 + name: example + surname: test + usrgrps: + - Guests + passwd: G$jd_79!jw + register: create_zabbix_user_result + +- assert: + that: + - not create_zabbix_user_result.changed is sameas true + +# Parameter add test from here to existing user +- name: test - Add user group to existing user + zabbix_user: + alias: example1 + name: example + surname: test + usrgrps: + - Guests + - Zabbix administrators + passwd: G$jd_79!jw + register: add_usergroup_to_existing_user_result + +- assert: + that: + - add_usergroup_to_existing_user_result.changed is sameas true + +- name: test - Add user medias(Email) to existing user + zabbix_user: + alias: example1 + name: example + surname: test + usrgrps: + - Guests + - Zabbix administrators + passwd: G$jd_79!jw + user_medias: + - mediatype: Email + sendto: example@example.com + period: 1-7,00:00-24:00 + severity: + not_classified: false + information: true + warning: true + average: true + high: true + disaster: true + active: true + register: add_user_medias_to_existing_user_result + +- assert: + that: + - add_user_medias_to_existing_user_result.changed is sameas true + +- name: test - Add multiple user medias(Email and SMS) to existing user + zabbix_user: + alias: example1 + name: example + surname: test + usrgrps: + - Guests + - Zabbix administrators + passwd: G$jd_79!jw + user_medias: + - mediatype: Email + sendto: example@example.com + period: 1-7,00:00-24:00 + severity: + not_classified: false + information: true + warning: true + average: true + high: true + disaster: true + active: true + - mediatype: SMS + sendto: example@example.com + period: 1-5,01:00-23:00 + severity: + not_classified: false + information: true + warning: true + average: false + high: true + disaster: true + active: true + register: add_user_medias_to_existing_user_result + +- assert: + that: + - add_user_medias_to_existing_user_result.changed is sameas true + +# Existing parameter updates test from here +- name: test - Update password parameter for existing user + zabbix_user: + alias: example1 + name: example + surname: test + usrgrps: + - Guests + - Zabbix administrators + passwd: update_password + override_passwd: true + user_medias: + - mediatype: Email + sendto: example@example.com + period: 1-7,00:00-24:00 + severity: + not_classified: false + information: true + warning: true + average: true + high: true + disaster: true + active: true + - mediatype: SMS + sendto: example@example.com + period: 1-5,01:00-23:00 + severity: + not_classified: false + information: true + warning: true + average: false + high: true + disaster: true + active: true + register: update_password_parameter_existing_user_result + +- assert: + that: + - update_password_parameter_existing_user_result.changed is sameas true + +- name: test - Update autologin parameter for existing user + zabbix_user: + alias: example1 + name: example + surname: test + usrgrps: + - Guests + - Zabbix administrators + passwd: update_password + autologin: true + user_medias: + - mediatype: Email + sendto: example@example.com + period: 1-7,00:00-24:00 + severity: + not_classified: false + information: true + warning: true + average: true + high: true + disaster: true + active: true + - mediatype: SMS + sendto: example@example.com + period: 1-5,01:00-23:00 + severity: + not_classified: false + information: true + warning: true + average: false + high: true + disaster: true + active: true + register: update_autologin_parameter_existing_user_result + +- assert: + that: + - update_autologin_parameter_existing_user_result.changed is sameas true + +- name: test - Update autologout parameter for existing user + zabbix_user: + alias: example1 + name: example + surname: test + usrgrps: + - Guests + - Zabbix administrators + passwd: update_password + autologout: 500 + user_medias: + - mediatype: Email + sendto: example@example.com + period: 1-7,00:00-24:00 + severity: + not_classified: false + information: true + warning: true + average: true + high: true + disaster: true + active: true + - mediatype: SMS + sendto: example@example.com + period: 1-5,01:00-23:00 + severity: + not_classified: false + information: true + warning: true + average: false + high: true + disaster: true + active: true + register: update_autologout_parameter_existing_user_result + +- assert: + that: + - update_autologout_parameter_existing_user_result.changed is sameas true + +- name: test - Update refresh parameter for existing user + zabbix_user: + alias: example1 + name: example + surname: test + usrgrps: + - Guests + - Zabbix administrators + passwd: update_password + autologout: 500 + refresh: 60 + user_medias: + - mediatype: Email + sendto: example@example.com + period: 1-7,00:00-24:00 + severity: + not_classified: false + information: true + warning: true + average: true + high: true + disaster: true + active: true + - mediatype: SMS + sendto: example@example.com + period: 1-5,01:00-23:00 + severity: + not_classified: false + information: true + warning: true + average: false + high: true + disaster: true + active: true + register: update_refresh_parameter_existing_user_result + +- assert: + that: + - update_refresh_parameter_existing_user_result.changed is sameas true + +- name: test - Update rows_per_page parameter for existing user + zabbix_user: + alias: example1 + name: example + surname: test + usrgrps: + - Guests + - Zabbix administrators + passwd: update_password + autologout: 500 + refresh: 60 + rows_per_page: 300 + user_medias: + - mediatype: Email + sendto: example@example.com + period: 1-7,00:00-24:00 + severity: + not_classified: false + information: true + warning: true + average: true + high: true + disaster: true + active: true + - mediatype: SMS + sendto: example@example.com + period: 1-5,01:00-23:00 + severity: + not_classified: false + information: true + warning: true + average: false + high: true + disaster: true + active: true + register: update_rows_per_page_parameter_existing_user_result + +- assert: + that: + - update_rows_per_page_parameter_existing_user_result.changed is sameas true + +- name: test - Update after_login_url parameter for existing user + zabbix_user: + alias: example1 + name: example + surname: test + usrgrps: + - Guests + - Zabbix administrators + passwd: update_password + autologout: 500 + refresh: 60 + rows_per_page: 300 + after_login_url: http://example.com + user_medias: + - mediatype: Email + sendto: example@example.com + period: 1-7,00:00-24:00 + severity: + not_classified: false + information: true + warning: true + average: true + high: true + disaster: true + active: true + - mediatype: SMS + sendto: example@example.com + period: 1-5,01:00-23:00 + severity: + not_classified: false + information: true + warning: true + average: false + high: true + disaster: true + active: true + register: update_after_login_url_parameter_existing_user_result + +- assert: + that: + - update_after_login_url_parameter_existing_user_result.changed is sameas true + +- name: test - Update theme parameter for existing user + zabbix_user: + alias: example1 + name: example + surname: test + usrgrps: + - Guests + - Zabbix administrators + passwd: update_password + autologout: 500 + refresh: 60 + rows_per_page: 300 + after_login_url: http://example.com + theme: "{{ item }}" + user_medias: + - mediatype: Email + sendto: example@example.com + period: 1-7,00:00-24:00 + severity: + not_classified: false + information: true + warning: true + average: true + high: true + disaster: true + active: true + - mediatype: SMS + sendto: example@example.com + period: 1-5,01:00-23:00 + severity: + not_classified: false + information: true + warning: true + average: false + high: true + disaster: true + active: true + loop: + - blue-theme + - dark-theme + register: update_theme_parameter_existing_user_result + +- assert: + that: + - item.changed is sameas true + loop: "{{ update_theme_parameter_existing_user_result.results }}" + +- name: test - Update role_name parameter for existing user + zabbix_user: + alias: example1 + name: example + surname: test + usrgrps: + - Guests + - Zabbix administrators + passwd: update_password + autologout: 500 + refresh: 60 + rows_per_page: 300 + after_login_url: http://example.com + theme: dark-theme + role_name: "{{ item }}" + user_medias: + - mediatype: Email + sendto: example@example.com + period: 1-7,00:00-24:00 + severity: + not_classified: false + information: true + warning: true + average: true + high: true + disaster: true + active: true + - mediatype: SMS + sendto: example@example.com + period: 1-5,01:00-23:00 + severity: + not_classified: false + information: true + warning: true + average: false + high: true + disaster: true + active: true + loop: + - Guest role + - Admin role + register: update_type_parameter_existing_user_result + +- assert: + that: + - item.changed is sameas true + loop: "{{ update_type_parameter_existing_user_result.results }}" + +- name: test - Update lang parameter for existing user + zabbix_user: + alias: example1 + name: example + surname: test + usrgrps: + - Guests + - Zabbix administrators + passwd: update_password + autologout: 500 + refresh: 60 + rows_per_page: 300 + after_login_url: http://example.com + theme: dark-theme + role_name: Admin role + lang: en_US + user_medias: + - mediatype: Email + sendto: example@example.com + period: 1-7,00:00-24:00 + severity: + not_classified: false + information: true + warning: true + average: true + high: true + disaster: true + active: true + - mediatype: SMS + sendto: example@example.com + period: 1-5,01:00-23:00 + severity: + not_classified: false + information: true + warning: true + average: false + high: true + disaster: true + active: true + register: update_lang_parameter_existing_user_result + +- assert: + that: + - update_lang_parameter_existing_user_result.changed is sameas true + +- name: test - Update timezone parameter for existing user + zabbix_user: + alias: example1 + name: example + surname: test + usrgrps: + - Guests + - Zabbix administrators + passwd: update_password + autologout: 500 + refresh: 60 + rows_per_page: 300 + after_login_url: http://example.com + theme: dark-theme + role_name: Admin role + timezone: Asia/Tokyo + lang: en_US + user_medias: + - mediatype: Email + sendto: example@example.com + period: 1-7,00:00-24:00 + severity: + not_classified: false + information: true + warning: true + average: true + high: true + disaster: true + active: true + - mediatype: SMS + sendto: example@example.com + period: 1-5,01:00-23:00 + severity: + not_classified: false + information: true + warning: true + average: false + high: true + disaster: true + active: true + register: update_timezone_parameter_existing_user_result + +- assert: + that: + - update_timezone_parameter_existing_user_result.changed is sameas true + +- name: test - Update name and surname parameter for existing user + zabbix_user: + alias: example1 + name: example2 + surname: test2 + usrgrps: + - Guests + - Zabbix administrators + passwd: update_password + autologout: 500 + refresh: 60 + rows_per_page: 300 + after_login_url: http://example.com + theme: dark-theme + role_name: Admin role + timezone: Asia/Tokyo + lang: en_US + user_medias: + - mediatype: Email + sendto: example@example.com + period: 1-7,00:00-24:00 + severity: + not_classified: false + information: true + warning: true + average: true + high: true + disaster: true + active: true + - mediatype: SMS + sendto: example@example.com + period: 1-5,01:00-23:00 + severity: + not_classified: false + information: true + warning: true + average: false + high: true + disaster: true + active: true + register: update_name_and_surname_parameter_existing_user_result + +- assert: + that: + - update_name_and_surname_parameter_existing_user_result.changed is sameas true + +- name: test - Update lang parameter for existing user with check_mode and diff + zabbix_user: + alias: example1 + name: example2 + surname: test2 + usrgrps: + - Guests + - Zabbix administrators + passwd: update_password + autologout: 500 + refresh: 60 + rows_per_page: 300 + after_login_url: http://example.com + theme: dark-theme + role_name: Admin role + timezone: Asia/Tokyo + lang: fr_FR + user_medias: + - mediatype: Email + sendto: example@example.com + period: 1-7,00:00-24:00 + severity: + not_classified: false + information: true + warning: true + average: true + high: true + disaster: true + active: true + - mediatype: SMS + sendto: example@example.com + period: 1-5,01:00-23:00 + severity: + not_classified: false + information: true + warning: true + average: false + high: true + disaster: true + active: true + check_mode: true + diff: true + register: update_lang_parameter_existing_user_with_check_mode_diff_result + +- assert: + that: + - update_lang_parameter_existing_user_with_check_mode_diff_result.changed is sameas true + +- name: test - Update lang parameter for existing user + zabbix_user: + alias: example1 + name: example2 + surname: test2 + usrgrps: + - Guests + - Zabbix administrators + passwd: update_password + autologout: 500 + refresh: 60 + rows_per_page: 300 + after_login_url: http://example.com + theme: dark-theme + role_name: Admin role + timezone: Asia/Tokyo + lang: fr_FR + user_medias: + - mediatype: Email + sendto: example@example.com + period: 1-7,00:00-24:00 + severity: + not_classified: false + information: true + warning: true + average: true + high: true + disaster: true + active: true + - mediatype: SMS + sendto: example@example.com + period: 1-5,01:00-23:00 + severity: + not_classified: false + information: true + warning: true + average: false + high: true + disaster: true + active: true + register: update_lang_parameter_existing_user_result + +- assert: + that: + - update_lang_parameter_existing_user_result.changed is sameas true + +- name: test - Update lang parameter for existing user(again) + zabbix_user: + alias: example1 + name: example2 + surname: test2 + usrgrps: + - Guests + - Zabbix administrators + passwd: update_password + autologout: 500 + refresh: 60 + rows_per_page: 300 + after_login_url: http://example.com + theme: dark-theme + role_name: Admin role + timezone: Asia/Tokyo + lang: fr_FR + user_medias: + - mediatype: Email + sendto: example@example.com + period: 1-7,00:00-24:00 + severity: + not_classified: false + information: true + warning: true + average: true + high: true + disaster: true + active: true + - mediatype: SMS + sendto: example@example.com + period: 1-5,01:00-23:00 + severity: + not_classified: false + information: true + warning: true + average: false + high: true + disaster: true + active: true + register: update_lang_parameter_existing_user_result + +- assert: + that: + - not update_lang_parameter_existing_user_result.changed is sameas true + +# Parameter delete test from here from existing user +- name: test - Delete user medias(SMS) for existing user with check_mode and diff + zabbix_user: + alias: example1 + name: example2 + surname: test2 + usrgrps: + - Guests + - Zabbix administrators + passwd: update_password + autologout: 500 + refresh: 60 + rows_per_page: 300 + after_login_url: http://example.com + theme: dark-theme + role_name: Admin role + timezone: Asia/Tokyo + lang: fr_FR + user_medias: + - mediatype: Email + sendto: example@example.com + period: 1-7,00:00-24:00 + severity: + not_classified: false + information: true + warning: true + average: true + high: true + disaster: true + active: true + check_mode: true + diff: true + register: delete_user_medias_existing_user_result + +- assert: + that: + - delete_user_medias_existing_user_result.changed is sameas true + +- name: test - Delete user medias(SMS) for existing user + zabbix_user: + alias: example1 + name: example2 + surname: test2 + usrgrps: + - Guests + - Zabbix administrators + passwd: update_password + autologout: 500 + refresh: 60 + rows_per_page: 300 + after_login_url: http://example.com + theme: dark-theme + role_name: Admin role + timezone: Asia/Tokyo + lang: fr_FR + user_medias: + - mediatype: Email + sendto: example@example.com + period: 1-7,00:00-24:00 + severity: + not_classified: false + information: true + warning: true + average: true + high: true + disaster: true + active: true + register: delete_user_medias_existing_user_result + +- assert: + that: + - delete_user_medias_existing_user_result.changed is sameas true + +- name: test - Delete user group for existing user + zabbix_user: + alias: example1 + name: example2 + surname: test2 + usrgrps: + - Zabbix administrators + passwd: update_password + autologout: 500 + refresh: 60 + rows_per_page: 300 + after_login_url: http://example.com + theme: dark-theme + role_name: Admin role + timezone: Asia/Tokyo + lang: fr_FR + user_medias: + - mediatype: Email + sendto: example@example.com + period: 1-7,00:00-24:00 + severity: + not_classified: false + information: true + warning: true + average: true + high: true + disaster: true + active: true + register: delete_user_group_existing_user_result + +- assert: + that: + - delete_user_group_existing_user_result.changed is sameas true + +- name: test - optional user_medias + zabbix_user: + alias: example1 + name: example2 + surname: test2 + usrgrps: + - Zabbix administrators + passwd: update_password + autologout: 500 + refresh: 60 + rows_per_page: 300 + after_login_url: http://example.com + theme: dark-theme + role_name: Admin role + timezone: Asia/Tokyo + lang: fr_FR + register: update_user_optional_user_medias_existing_user_result + +- assert: + that: + - update_user_optional_user_medias_existing_user_result.changed is sameas False + +- name: test - Delete existing user with check_mode and diff + zabbix_user: + alias: example1 + state: absent + check_mode: true + diff: true + register: delete_existing_user_result + +- assert: + that: + - delete_existing_user_result.changed is sameas true + +- name: test - Delete existing user + zabbix_user: + alias: example1 + state: absent + register: delete_existing_user_result + +- assert: + that: + - delete_existing_user_result.changed is sameas true + +- name: test - Delete existing user(again) + zabbix_user: + alias: example1 + state: absent + register: delete_existing_user_result + +- assert: + that: + - not delete_existing_user_result.changed is sameas true + +- when: zabbix_version is version('4.0', '<') + block: + - name: test - Create new password-less user without LDAP group (fail, <4.0) + zabbix_user: + alias: example2alias + name: example2 + surname: testldap + usrgrps: + - Guests + register: create_zabbix_user_ldap_fail + ignore_errors: true + + - assert: + that: + - create_zabbix_user_ldap_fail.failed is sameas True + +- when: zabbix_version is version('4.0', '>=') + block: + - name: test prepare - Create LDAP user group + zabbix_usergroup: + name: testLDAPgrp + gui_access: LDAP + register: zbxuser_create_ldap_group + + - assert: + that: + - zbxuser_create_ldap_group.changed is sameas True + + - name: test - Create new password-less user without LDAP group (fail) + zabbix_user: + alias: example2alias + name: example2 + surname: testldap + usrgrps: + - Guests + register: create_zabbix_user_ldap_fail + ignore_errors: true + + - assert: + that: + - create_zabbix_user_ldap_fail.failed is sameas True + + - name: test - Create new password-less user as member in LDAP group + zabbix_user: + alias: example2alias + name: example2 + surname: testldap + usrgrps: + - testLDAPgrp + register: create_zabbix_user_ldap_result + + - assert: + that: + - create_zabbix_user_ldap_result.changed is sameas True + + - name: test - Create new password-less user as member in LDAP group (again) + zabbix_user: + alias: example2alias + name: example2 + surname: testldap + usrgrps: + - testLDAPgrp + register: create_zabbix_user_ldap_result + + - assert: + that: + - create_zabbix_user_ldap_result.changed is sameas False + + - name: test - Delete existing user + zabbix_user: + alias: example2alias + state: absent + register: delete_existing_user_result + + - assert: + that: + - delete_existing_user_result.changed is sameas true + +# The tests are to check the patch for PR hasn't a problem. +# https://github.com/ansible-collections/community.zabbix/pull/382 +- name: test - Create a zabbix user with minimum parameters + zabbix_user: + alias: example2 + usrgrps: + - Guests + passwd: G$jd_79!jw + role_name: "User role" + register: create_zabbix_user_with_minimum_params_result + +- assert: + that: + - create_zabbix_user_with_minimum_params_result.changed is sameas true + +- name: test - Create a zabbix user with minimum parameters(again) + zabbix_user: + alias: example2 + usrgrps: + - Guests + passwd: G$jd_79!jw + role_name: "User role" + register: create_zabbix_user_with_minimum_params_result + +- assert: + that: + - create_zabbix_user_with_minimum_params_result.changed is sameas false + +- name: test - Update the parameters without role_name + zabbix_user: + alias: example2 + name: example2 + surname: test + usrgrps: + - Guests + passwd: G$jd_79!jw + register: update_params_without_role_name_result + +- assert: + that: + - update_params_without_role_name_result.changed is sameas true + +- name: test - Update the parameters without role_name(again) + zabbix_user: + alias: example2 + name: example2 + surname: test + usrgrps: + - Guests + passwd: G$jd_79!jw + register: update_params_without_role_name_result + +- assert: + that: + - update_params_without_role_name_result.changed is sameas false + +- name: test - Add user medias(Email) as list to existing user + zabbix_user: + alias: example2 + name: example2 + surname: test + usrgrps: + - Guests + passwd: G$jd_79!jw + user_medias: + - mediatype: Email + sendto: + - example@example.com + - example1@example.com + period: 1-7,00:00-24:00 + severity: + not_classified: false + information: true + warning: true + average: true + high: true + disaster: true + active: true + register: add_user_email_media_as_list_to_existing_user_result + +- assert: + that: + - add_user_email_media_as_list_to_existing_user_result.changed is sameas true + +- name: test - Add user medias(Email) as list to existing user(again) + zabbix_user: + alias: example2 + name: example2 + surname: test + usrgrps: + - Guests + passwd: G$jd_79!jw + user_medias: + - mediatype: Email + sendto: + - example@example.com + - example1@example.com + period: 1-7,00:00-24:00 + severity: + not_classified: false + information: true + warning: true + average: true + high: true + disaster: true + active: true + register: add_user_email_media_as_list_to_existing_user_result + +- assert: + that: + - add_user_email_media_as_list_to_existing_user_result.changed is sameas false + +- name: test - Delete existing user + zabbix_user: + alias: example2 + state: absent + +- name: test prepare - Delete LDAP user group + zabbix_usergroup: + name: testLDAPgrp + state: absent diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_user/tasks/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_user/tasks/main.yml new file mode 100644 index 000000000..f762591cf --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_user/tasks/main.yml @@ -0,0 +1,10 @@ +--- +- name: Execute the integration test for Zabbix 5.0 and lower + include_tasks: for_zabbix_50_lower.yml + when: + - zabbix_version | float <= 5.0 + +- name: Execute the integration test for Zabbix 5.4 and higher + include_tasks: for_zabbix_54_higher.yml + when: + - zabbix_version | float >= 5.4 diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_user_directory/meta/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_user_directory/meta/main.yml new file mode 100644 index 000000000..acdb704c8 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_user_directory/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - setup_zabbix diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_user_directory/tasks/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_user_directory/tasks/main.yml new file mode 100644 index 000000000..6c697a2e5 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_user_directory/tasks/main.yml @@ -0,0 +1,10 @@ +--- +- block: + - include_tasks: zabbix_user_directory_tests.yml + + always: + - name: Cleanup + zabbix_user_directory: + name: TestUserDirectory + state: absent + ignore_errors: true diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_user_directory/tasks/zabbix_user_directory_tests.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_user_directory/tasks/zabbix_user_directory_tests.yml new file mode 100644 index 000000000..db057a5d0 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_user_directory/tasks/zabbix_user_directory_tests.yml @@ -0,0 +1,437 @@ +--- +- name: test - do not run tests for Zabbix < 6.2 + meta: end_play + when: zabbix_version is version('6.2', '<') + +- name: test - user directory for Zabbix < 6.4 + module_defaults: + community.zabbix.zabbix_user_directory: + state: present + name: TestUserDirectory + + block: + - name: test - create new user directory in check mode + zabbix_user_directory: + host: 'test.com' + port: 389 + base_dn: 'ou=Users,dc=example,dc=org' + search_attribute: 'uid' + check_mode: true + register: directory_check_result + + - assert: + that: directory_check_result.changed is sameas True + + - name: test - attempt to create new user directory with not all mandatory parameters + zabbix_user_directory: + host: 'test.com' + port: 389 + ignore_errors: true + register: directory_expect_fail_result + + - assert: + that: directory_expect_fail_result.failed is sameas True + + - name: test - create new user directory withoud bind_password + zabbix_user_directory: + host: 'test.com' + port: 389 + base_dn: 'ou=Users,dc=example,dc=org' + search_attribute: 'uid' + register: directory_result + + - assert: + that: directory_result.changed is sameas True + + - name: test - create new user directory without bind_password again + zabbix_user_directory: + host: 'test.com' + port: 389 + base_dn: 'ou=Users,dc=example,dc=org' + search_attribute: 'uid' + register: directory_again_result + + - assert: + that: directory_again_result.changed is sameas False + + - name: test - delete user directory + zabbix_user_directory: + state: absent + register: directory_delete_result + + - assert: + that: directory_delete_result.changed is sameas True + + - name: test - create new user directory with bind_password + zabbix_user_directory: + host: 'test.com' + port: 389 + base_dn: 'ou=Users,dc=example,dc=org' + search_attribute: 'uid' + bind_password: 'password' + register: directory_result + + - assert: + that: directory_result.changed is sameas True + + - name: test - create new user directory with bind_password again + zabbix_user_directory: + host: 'test.com' + port: 389 + base_dn: 'ou=Users,dc=example,dc=org' + search_attribute: 'uid' + bind_password: 'password' + register: directory_again_result + + - assert: + that: directory_again_result.changed is sameas True + + - name: test - update only host parameter in user directory + zabbix_user_directory: + host: 'test.ca' + register: directory_update_result + + - assert: + that: directory_update_result.changed is sameas True + + - name: test - update only host parameter in user directory again + zabbix_user_directory: + host: 'test.ca' + register: directory_update_again_result + + - assert: + that: directory_update_again_result.changed is sameas False + + when: zabbix_version is version('6.4', '<') + +- name: test - user directory for Zabbix >= 6.4 + module_defaults: + community.zabbix.zabbix_user_directory: + state: present + name: TestUserDirectory + + block: + - name: test - create new LDAP user directory in check mode + zabbix_user_directory: + idp_type: ldap + host: 'test.com' + port: 389 + base_dn: 'ou=Users,dc=example,dc=org' + search_attribute: 'uid' + check_mode: true + register: directory_check_result + + - assert: + that: directory_check_result.changed is sameas True + + - name: test - attempt to create new LDAP user directory with not all mandatory parameters + zabbix_user_directory: + idp_type: ldap + host: 'test.com' + port: 389 + ignore_errors: true + register: directory_expect_fail_result + + - assert: + that: directory_expect_fail_result.failed is sameas True + + - name: test - create new LDAP user directory withoud bind_password + zabbix_user_directory: + idp_type: ldap + host: 'test.com' + port: 389 + base_dn: 'ou=Users,dc=example,dc=org' + search_attribute: 'uid' + register: directory_result + + - assert: + that: directory_result.changed is sameas True + + - name: test - create new LDAP user directory without bind_password again + zabbix_user_directory: + idp_type: ldap + host: 'test.com' + port: 389 + base_dn: 'ou=Users,dc=example,dc=org' + search_attribute: 'uid' + register: directory_again_result + + - assert: + that: directory_again_result.changed is sameas False + + - name: test - delete LDAP user directory + zabbix_user_directory: + state: absent + register: directory_delete_result + + - assert: + that: directory_delete_result.changed is sameas True + + - name: test - create new LDAP user directory with bind_password + zabbix_user_directory: + idp_type: ldap + host: 'test.com' + port: 389 + base_dn: 'ou=Users,dc=example,dc=org' + search_attribute: 'uid' + bind_password: 'password' + register: directory_result + + - assert: + that: directory_result.changed is sameas True + + - name: test - create new LDAP user directory with bind_password again + zabbix_user_directory: + idp_type: ldap + host: 'test.com' + port: 389 + base_dn: 'ou=Users,dc=example,dc=org' + search_attribute: 'uid' + bind_password: 'password' + register: directory_again_result + + - assert: + that: directory_again_result.changed is sameas True + + - name: test - update host parameter in LDAP user directory + zabbix_user_directory: + idp_type: ldap + host: 'test.ca' + port: 389 + base_dn: 'ou=Users,dc=example,dc=org' + search_attribute: 'uid' + register: directory_update_result + + - assert: + that: directory_update_result.changed is sameas True + + - name: test - update host parameter in LDAP user directory again + zabbix_user_directory: + idp_type: ldap + host: 'test.ca' + port: 389 + base_dn: 'ou=Users,dc=example,dc=org' + search_attribute: 'uid' + register: directory_update_again_result + + - assert: + that: directory_update_again_result.changed is sameas False + + - name: test - add media type mapping with non-existing media type + zabbix_user_directory: + idp_type: ldap + host: 'test.ca' + port: 389 + base_dn: 'ou=Users,dc=example,dc=org' + search_attribute: 'uid' + provision_status: True + provision_media: + - name: Media1 + mediatype: EmailX + attribute: email + provision_groups: + - name: idpname1 + role: Guest role + user_groups: + - Guests + ignore_errors: True + register: directory_update_media_fail_result + + - assert: + that: directory_update_media_fail_result.failed is sameas True + + - name: test - add mappings + zabbix_user_directory: + idp_type: ldap + host: 'test.ca' + port: 389 + base_dn: 'ou=Users,dc=example,dc=org' + search_attribute: 'uid' + provision_status: True + group_name: cn + group_basedn: ou=Group,dc=example,dc=org + group_member: member + user_ref_attr: uid + group_filter: '(member=uid=%{ref},ou=Users,dc=example,dc=com)' + user_username: first_name + user_lastname: last_name + provision_media: + - name: Media1 + mediatype: Email + attribute: email1 + provision_groups: + - name: idpname1 + role: Guest role + user_groups: + - Guests + register: directory_update_media_result + + - assert: + that: directory_update_media_result.changed is sameas True + + - name: test - add mappings again + zabbix_user_directory: + idp_type: ldap + host: 'test.ca' + port: 389 + base_dn: 'ou=Users,dc=example,dc=org' + search_attribute: 'uid' + provision_status: True + group_name: cn + group_basedn: ou=Group,dc=example,dc=org + group_member: member + user_ref_attr: uid + group_filter: '(member=uid=%{ref},ou=Users,dc=example,dc=com)' + user_username: first_name + user_lastname: last_name + provision_media: + - name: Media1 + mediatype: Email + attribute: email1 + provision_groups: + - name: idpname1 + role: Guest role + user_groups: + - Guests + register: directory_update_media_again_result + + - assert: + that: directory_update_media_again_result.changed is sameas False + + - name: test - delete LDAP user directory + zabbix_user_directory: + state: absent + + - name: test - create new SAML user directory in check mode + zabbix_user_directory: + idp_type: saml + idp_entityid: http://okta.com/xxxxx + sp_entityid: zabbix + sso_url: http://xxxx.okta.com/app/xxxxxx_123dhu8o3 + username_attribute: usrEmail + check_mode: true + register: directory_check_result + + - assert: + that: directory_check_result.changed is sameas True + + - name: test - attempt to create new SAML user directory with not all mandatory parameters + zabbix_user_directory: + idp_type: saml + ignore_errors: true + register: directory_expect_fail_result + + - assert: + that: directory_expect_fail_result.failed is sameas True + + - name: test - create new SAML user directory + zabbix_user_directory: + idp_type: saml + idp_entityid: http://okta.com/xxxxx + sp_entityid: zabbix + sso_url: http://xxxx.okta.com/app/xxxxxx_123dhu8o3 + username_attribute: usrEmail + register: directory_create_result + + - assert: + that: directory_create_result.changed is sameas True + + - name: test - update SAML user directory with all optional parameters + zabbix_user_directory: + idp_type: saml + idp_entityid: http://okta.com/xxxxx + sp_entityid: zabbix + sso_url: http://xxxx.okta.com/app/xxxxxx_123dhu8o3 + username_attribute: usrEmail + slo_url: http://yyyy.okta.com + nameid_format: 'urn:oasis' + scim_status: true + encrypt_nameid: true + encrypt_assertions: true + sign_messages: true + sign_assertions: true + sign_authn_requests: true + sign_logout_requests: true + sign_logout_responses: true + register: directory_create_all_result + + - assert: + that: directory_create_all_result.changed is sameas True + + - name: test - update SAML user directory with all optional parameters again + zabbix_user_directory: + idp_type: saml + idp_entityid: http://okta.com/xxxxx + sp_entityid: zabbix + sso_url: http://xxxx.okta.com/app/xxxxxx_123dhu8o3 + username_attribute: usrEmail + slo_url: http://yyyy.okta.com + nameid_format: 'urn:oasis' + scim_status: true + encrypt_nameid: true + encrypt_assertions: true + sign_messages: true + sign_assertions: true + sign_authn_requests: true + sign_logout_requests: true + sign_logout_responses: true + register: directory_create_all_again_result + + - assert: + that: directory_create_all_again_result.changed is sameas False + + - name: test - delete SAML user directory + zabbix_user_directory: + state: absent + + - name: test - create new SAML user directory with mappings + zabbix_user_directory: + idp_type: saml + idp_entityid: http://okta.com/xxxxx + sp_entityid: zabbix + sso_url: http://xxxx.okta.com/app/xxxxxx_123dhu8o3 + username_attribute: usrEmail + provision_status: True + group_name: cn + user_username: first_name + user_lastname: last_name + provision_media: + - name: Media1 + mediatype: Email + attribute: email1 + provision_groups: + - name: idpname1 + role: Guest role + user_groups: + - Guests + register: directory_create_mappings_result + + - assert: + that: directory_create_mappings_result.changed is sameas True + + - name: test - create new SAML user directory with mappings again + zabbix_user_directory: + idp_type: saml + idp_entityid: http://okta.com/xxxxx + sp_entityid: zabbix + sso_url: http://xxxx.okta.com/app/xxxxxx_123dhu8o3 + username_attribute: usrEmail + provision_status: True + group_name: cn + user_username: first_name + user_lastname: last_name + provision_media: + - name: Media1 + mediatype: Email + attribute: email1 + provision_groups: + - name: idpname1 + role: Guest role + user_groups: + - Guests + register: directory_create_mappings_again_result + + - assert: + that: directory_create_mappings_again_result.changed is sameas False + + when: zabbix_version is version('6.4', '>=') diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_user_info/meta/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_user_info/meta/main.yml new file mode 100644 index 000000000..acdb704c8 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_user_info/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - setup_zabbix diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_user_info/tasks/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_user_info/tasks/main.yml new file mode 100644 index 000000000..7228e12eb --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_user_info/tasks/main.yml @@ -0,0 +1,199 @@ +--- +# New user create test from here +- when: zabbix_version is version('5.4', '<') + block: + - name: test - Create a new Zabbix user + zabbix_user: + alias: example + name: user name + surname: user surname + usrgrps: + - Guests + - Disabled + passwd: G$jd_79!jw + lang: en_US + theme: blue-theme + autologin: false + autologout: '0' + refresh: '30' + rows_per_page: '200' + after_login_url: '' + user_medias: + - mediatype: Email + sendto: example@example.com + period: 1-7,00:00-24:00 + severity: + not_classified: false + information: true + warning: true + average: true + high: true + disaster: true + active: false + type: Zabbix super admin + state: present + register: create_zabbix_user_result + + - assert: + that: + - create_zabbix_user_result.changed is sameas true + + - name: test - Set definition_of_results variable of Zabbix 5.0 and lower + set_fact: + definition_of_results: + - get_user_info_result[user_info_key].alias == "example" + - get_user_info_result[user_info_key].autologin is defined + - get_user_info_result[user_info_key].autologout is defined + - get_user_info_result[user_info_key].lang is defined + - get_user_info_result[user_info_key].medias.0.active is defined + - get_user_info_result[user_info_key].medias.0.mediaid is defined + - get_user_info_result[user_info_key].medias.0.period is defined + - get_user_info_result[user_info_key].medias.0.sendto is defined + - get_user_info_result[user_info_key].medias.0.severity is defined + - get_user_info_result[user_info_key].medias.0.userid is defined + - get_user_info_result[user_info_key].name is defined + - get_user_info_result[user_info_key].refresh is defined + - get_user_info_result[user_info_key].rows_per_page is defined + - get_user_info_result[user_info_key].surname is defined + - get_user_info_result[user_info_key].theme is defined + - get_user_info_result[user_info_key].type is defined + - get_user_info_result[user_info_key].url is defined + - get_user_info_result[user_info_key].userid is defined + - get_user_info_result[user_info_key].users_status is defined + - get_user_info_result[user_info_key].usrgrps | length == 2 + - get_user_info_result[user_info_key].usrgrps.0.debug_mode is defined + - get_user_info_result[user_info_key].usrgrps.0.gui_access is defined + - get_user_info_result[user_info_key].usrgrps.0.name is defined + - get_user_info_result[user_info_key].usrgrps.0.users_status is defined + - get_user_info_result[user_info_key].usrgrps.0.usrgrpid is defined + - get_user_info_result[user_info_key].usrgrps.1.debug_mode is defined + - get_user_info_result[user_info_key].usrgrps.1.gui_access is defined + - get_user_info_result[user_info_key].usrgrps.1.name is defined + - get_user_info_result[user_info_key].usrgrps.1.users_status is defined + - get_user_info_result[user_info_key].usrgrps.1.usrgrpid is defined + +- when: zabbix_version is version('5.4', '>=') + block: + - name: test - Create a new Zabbix user + zabbix_user: + alias: example + name: user name + surname: user surname + usrgrps: + - Guests + - Disabled + passwd: G$jd_79!jw + lang: en_US + theme: blue-theme + autologin: false + autologout: '0' + refresh: '30' + rows_per_page: '200' + after_login_url: '' + user_medias: + - mediatype: Email + sendto: example@example.com + period: 1-7,00:00-24:00 + severity: + not_classified: false + information: true + warning: true + average: true + high: true + disaster: true + active: false + role_name: Super admin role + timezone: Asia/Tokyo + state: present + register: create_zabbix_user_result + + - assert: + that: + - create_zabbix_user_result.changed is sameas true + + - name: test - Set definition_of_results variable of Zabbix 5.4 and higher + set_fact: + definition_of_results: + - get_user_info_result[user_info_key].alias == "example" + - get_user_info_result[user_info_key].autologin is defined + - get_user_info_result[user_info_key].autologout is defined + - get_user_info_result[user_info_key].lang is defined + - get_user_info_result[user_info_key].medias.0.active is defined + - get_user_info_result[user_info_key].medias.0.mediaid is defined + - get_user_info_result[user_info_key].medias.0.period is defined + - get_user_info_result[user_info_key].medias.0.sendto is defined + - get_user_info_result[user_info_key].medias.0.severity is defined + - get_user_info_result[user_info_key].medias.0.userid is defined + - get_user_info_result[user_info_key].name is defined + - get_user_info_result[user_info_key].refresh is defined + - get_user_info_result[user_info_key].rows_per_page is defined + - get_user_info_result[user_info_key].surname is defined + - get_user_info_result[user_info_key].theme is defined + - get_user_info_result[user_info_key].roleid is defined + - get_user_info_result[user_info_key].url is defined + - get_user_info_result[user_info_key].userid is defined + - get_user_info_result[user_info_key].users_status is defined + - get_user_info_result[user_info_key].timezone is defined + - get_user_info_result[user_info_key].usrgrps | length == 2 + - get_user_info_result[user_info_key].usrgrps.0.debug_mode is defined + - get_user_info_result[user_info_key].usrgrps.0.gui_access is defined + - get_user_info_result[user_info_key].usrgrps.0.name is defined + - get_user_info_result[user_info_key].usrgrps.0.users_status is defined + - get_user_info_result[user_info_key].usrgrps.0.usrgrpid is defined + - get_user_info_result[user_info_key].usrgrps.1.debug_mode is defined + - get_user_info_result[user_info_key].usrgrps.1.gui_access is defined + - get_user_info_result[user_info_key].usrgrps.1.name is defined + - get_user_info_result[user_info_key].usrgrps.1.users_status is defined + - get_user_info_result[user_info_key].usrgrps.1.usrgrpid is defined + +- name: "test - Get a zabbix user information" + zabbix_user_info: + alias: example + register: get_user_info_result + +- name: "test - Set key to user_info_key variable(This deals with the key being masked)" + set_fact: + user_info_key: "{{ item }}" + loop: "{{ get_user_info_result.keys() | list }}" + when: + - item | regex_search('_user') + +- assert: + that: definition_of_results + + +- name: test - Create a new Zabbix user + zabbix_user: + alias: example2 + usrgrps: + - Guests + - Disabled + passwd: G$jd_79!jw + state: present + register: create_zabbix_user_result2 + +- assert: + that: + - create_zabbix_user_result2.changed is sameas true + +- name: "test - Get a zabbix user information" + zabbix_user_info: + alias: example2 + register: get_user_info_result2 + +- name: "test - Set key to user_info_key variable(This deals with the key being masked)" + set_fact: + user_info_key: "{{ item }}" + loop: "{{ get_user_info_result2.keys() | list }}" + when: + - item | regex_search('_user') + +- assert: + that: + - get_user_info_result2[user_info_key].alias == "example2" + when: zabbix_version is version('5.4', '<') + +- assert: + that: + - get_user_info_result2[user_info_key].username == "example2" + when: zabbix_version is version('5.4', '>=') diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_user_role/meta/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_user_role/meta/main.yml new file mode 100644 index 000000000..acdb704c8 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_user_role/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - setup_zabbix diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_user_role/tasks/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_user_role/tasks/main.yml new file mode 100644 index 000000000..799bef30b --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_user_role/tasks/main.yml @@ -0,0 +1,106 @@ +--- +# New user role create test from here, only 6.0 and higher +- when: zabbix_version is version('6.0', '>=') + block: + - name: test - Create a new Zabbix role + zabbix_user_role: + state: present + name: Operators + type: User + rules: + ui.default_access: 0 + ui: + - name: "monitoring.hosts" + status: 0 + - name: "monitoring.maps" + status: 1 + register: create_zabbix_user_role_result + + - assert: + that: + - create_zabbix_user_role_result.changed is sameas true + + # Check user role idempotency + - name: test - Update a Zabbix role with same rules + zabbix_user_role: + state: present + name: Operators + type: User + rules: + ui.default_access: 0 + ui: + - name: "monitoring.hosts" + status: 0 + - name: "monitoring.maps" + status: 1 + register: create_zabbix_user_role_result + + - assert: + that: + - create_zabbix_user_role_result.changed is sameas false + + # Check user role change + - name: test - Update a Zabbix role with new rules + zabbix_user_role: + state: present + name: Operators + type: User + rules: + ui.default_access: 0 + ui: + - name: "monitoring.hosts" + status: 1 + - name: "monitoring.maps" + status: 0 + register: create_zabbix_user_role_result + + - assert: + that: + - create_zabbix_user_role_result.changed is sameas true + + # Check user role remove + - name: test - Remove Zabbix role + zabbix_user_role: + state: absent + name: Operators + register: create_zabbix_user_role_result + + - assert: + that: + - create_zabbix_user_role_result.changed is sameas true + + - name: test - Create a new Zabbix role type Admin + zabbix_user_role: + state: present + name: Admins + type: Admin + rules: + ui.default_access: 0 + register: create_zabbix_user_role_admin_result + + - assert: + that: + - create_zabbix_user_role_admin_result.changed is sameas true + + - name: test - Remove Zabbix role type Admin + zabbix_user_role: + state: absent + name: Admins + + - name: test - Create a new Zabbix role type Super Admin + zabbix_user_role: + state: present + name: Super Admins + type: Super Admin + rules: + ui.default_access: 0 + register: create_zabbix_user_role_super_admin_result + + - assert: + that: + - create_zabbix_user_role_super_admin_result.changed is sameas true + + - name: test - Remove Zabbix role type Super Admin + zabbix_user_role: + state: absent + name: Super Admins diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_usergroup/meta/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_usergroup/meta/main.yml new file mode 100644 index 000000000..acdb704c8 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_usergroup/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - setup_zabbix diff --git a/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_usergroup/tasks/main.yml b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_usergroup/tasks/main.yml new file mode 100644 index 000000000..f7a6aa60e --- /dev/null +++ b/ansible_collections/community/zabbix/tests/integration/targets/test_zabbix_usergroup/tasks/main.yml @@ -0,0 +1,278 @@ +--- +- name: test - do not run tests for Zabbix 3.0 + meta: end_play + when: zabbix_version is version('3.0', '=') + +- name: test - Zabbix user group + module_defaults: + community.zabbix.zabbix_usergroup: + name: ACME + + block: + - name: test - create new Zabbix user group + zabbix_usergroup: + state: present + register: usergroup_new + + - name: assert that user group was created + assert: + that: usergroup_new is changed + + - name: test - create new Zabbix user group (again) + zabbix_usergroup: + state: present + register: usergroup_again + + - name: assert that user group was created + assert: + that: not usergroup_again is changed + + - name: test - update Zabbix user group with disabled gui_access + zabbix_usergroup: + gui_access: disable + register: usergroup_updated + + - name: assert that user group was updated + assert: + that: usergroup_updated is changed + + - name: test - update Zabbix user group with disabled gui_access (again) + zabbix_usergroup: + gui_access: disable + register: usergroup_updated_again + + - name: assert that user group was updated + assert: + that: not usergroup_updated_again is changed + + - name: test - reset Zabbix user group to default + zabbix_usergroup: + register: usergroup_reset + + - name: assert that user group was created + assert: + that: usergroup_reset is changed + + - when: zabbix_version is version('6.2', '<') + block: + - name: test - update Zabbix user group with one right + zabbix_usergroup: + rights: + - host_group: Discovered hosts + permission: read-only + register: usergroup_updated_right + + - name: assert that user group was updated + assert: + that: usergroup_updated_right is changed + + - name: test - update Zabbix user group with multiple rights + zabbix_usergroup: + rights: + - host_group: Discovered hosts + permission: read-only + - host_group: Zabbix servers + permission: read-write + register: usergroup_updated_rights + + - name: assert that user group was updated + assert: + that: usergroup_updated_rights is changed + + - name: test - update Zabbix user group with multiple rights (again) + zabbix_usergroup: + rights: + - host_group: Discovered hosts + permission: read-only + - host_group: Zabbix servers + permission: read-write + register: usergroup_updated_rights_again + + - name: assert that user group was not updated + assert: + that: not usergroup_updated_rights_again is changed + + - when: zabbix_version is version('6.2', '>=') + block: + - name: test - update Zabbix user group with one hostgroup right + zabbix_usergroup: + hostgroup_rights: + - host_group: Discovered hosts + permission: read-only + register: usergroup_updated_hostgroup_right + + - name: assert that user group was updated + assert: + that: usergroup_updated_hostgroup_right is changed + + - name: test - update Zabbix user group with multiple hostgroup rights + zabbix_usergroup: + hostgroup_rights: + - host_group: Discovered hosts + permission: read-only + - host_group: Zabbix servers + permission: read-write + register: usergroup_updated_hostgroup_rights + + - name: assert that user group was updated + assert: + that: usergroup_updated_hostgroup_rights is changed + + - name: test - update Zabbix user group with multiple hostgroup rights (again) + zabbix_usergroup: + hostgroup_rights: + - host_group: Discovered hosts + permission: read-only + - host_group: Zabbix servers + permission: read-write + register: usergroup_updated_hostgroup_rights_again + + - name: assert that user group was not updated + assert: + that: not usergroup_updated_hostgroup_rights_again is changed + + - name: test - update Zabbix user group with one template group right + zabbix_usergroup: + hostgroup_rights: + - host_group: Discovered hosts + permission: read-only + - host_group: Zabbix servers + permission: read-write + templategroup_rights: + - template_group: Templates + permission: read-only + register: usergroup_updated_templategroup_right + + - name: assert that user group was updated + assert: + that: usergroup_updated_templategroup_right is changed + + - name: test - update Zabbix user group with multiple template group rights + zabbix_usergroup: + hostgroup_rights: + - host_group: Discovered hosts + permission: read-only + - host_group: Zabbix servers + permission: read-write + templategroup_rights: + - template_group: Templates + permission: read-only + - template_group: Templates/Applications + permission: read-write + register: usergroup_updated_templategroup_rights + + - name: assert that user group was updated + assert: + that: usergroup_updated_templategroup_right is changed + + - name: test - update Zabbix user group with multiple template group rights (again) + zabbix_usergroup: + hostgroup_rights: + - host_group: Discovered hosts + permission: read-only + - host_group: Zabbix servers + permission: read-write + templategroup_rights: + - template_group: Templates + permission: read-only + - template_group: Templates/Applications + permission: read-write + register: usergroup_updated_templategroup_rights_again + + - name: assert that user group was not updated + assert: + that: not usergroup_updated_templategroup_rights_again is changed + + - name: test - reset Zabbix user group to default + zabbix_usergroup: + register: usergroup_reset + + - name: assert that user group was created + assert: + that: usergroup_reset is changed + + - name: test - update Zabbix user group with one tag_filter + zabbix_usergroup: + tag_filters: + - host_group: Discovered hosts + tag: Service + value: JIRA + register: usergroup_updated_tag_filter + + - name: assert that user group was updated + assert: + that: usergroup_updated_tag_filter is changed + + - name: test - update Zabbix user group with multiple tag_filters + zabbix_usergroup: + tag_filters: + - host_group: Discovered hosts + tag: Service + value: JIRA + - host_group: Discovered hosts + tag: Service + value: Zabbix + register: usergroup_updated_tag_filters + + - name: assert that user group was updated + assert: + that: usergroup_updated_tag_filters is changed + + - name: test - reset Zabbix user group to default + zabbix_usergroup: + + - when: zabbix_version is version('6.2', '>=') + block: + - name: test - create new user directory + zabbix_user_directory: + name: LDAP infra 1 + host: 'test.com' + port: 389 + base_dn: 'ou=Users,dc=example,dc=org' + search_attribute: 'uid' + when: zabbix_version is version('6.4', '<') + + - name: test - create new user directory + zabbix_user_directory: + name: LDAP infra 1 + idp_type: ldap + host: 'test.com' + port: 389 + base_dn: 'ou=Users,dc=example,dc=org' + search_attribute: 'uid' + when: zabbix_version is version('6.4', '>=') + + - name: test - update Zabbix user group with user directory + zabbix_usergroup: + userdirectory: LDAP infra 1 + register: usergroup_create_userdir + + - name: assert that user group was updated + assert: + that: usergroup_create_userdir is changed + + - name: test - update Zabbix user group with user directory (again) + zabbix_usergroup: + userdirectory: LDAP infra 1 + register: usergroup_create_userdir_again + + - name: assert that user group was not updated + assert: + that: not usergroup_create_userdir_again is changed + + - name: test - delete Zabbix user group + zabbix_usergroup: + state: absent + register: usergroup_delete + + - name: assert that Zabbix user group has been deleted + assert: + that: usergroup_delete is changed + + + - name: test - delete user directory + zabbix_user_directory: + name: LDAP infra 1 + host: 'test.com' + state: absent + when: zabbix_version is version('6.2', '>=') diff --git a/ansible_collections/community/zabbix/tests/sanity/ignore-2.10.txt b/ansible_collections/community/zabbix/tests/sanity/ignore-2.10.txt new file mode 100644 index 000000000..8854fcd2d --- /dev/null +++ b/ansible_collections/community/zabbix/tests/sanity/ignore-2.10.txt @@ -0,0 +1,34 @@ +scripts/inventory/zabbix.py future-import-boilerplate +scripts/inventory/zabbix.py metaclass-boilerplate +plugins/modules/zabbix_action.py validate-modules:doc-choices-do-not-match-spec +plugins/modules/zabbix_action.py validate-modules:doc-default-does-not-match-spec +plugins/modules/zabbix_action.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_action.py validate-modules:doc-required-mismatch +plugins/modules/zabbix_action.py validate-modules:invalid-argument-name +plugins/modules/zabbix_action.py validate-modules:missing-suboption-docs +plugins/modules/zabbix_action.py validate-modules:nonexistent-parameter-documented +plugins/modules/zabbix_action.py validate-modules:parameter-list-no-elements +plugins/modules/zabbix_action.py validate-modules:parameter-type-not-in-doc +plugins/modules/zabbix_action.py validate-modules:undocumented-parameter +plugins/modules/zabbix_group.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_group.py validate-modules:parameter-list-no-elements +plugins/modules/zabbix_group_info.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_group_info.py validate-modules:parameter-list-no-elements +plugins/modules/zabbix_host.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_host.py validate-modules:parameter-list-no-elements +plugins/modules/zabbix_host_info.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_host_info.py validate-modules:parameter-list-no-elements +plugins/modules/zabbix_maintenance.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_maintenance.py validate-modules:parameter-list-no-elements +plugins/modules/zabbix_mediatype.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_mediatype.py validate-modules:parameter-list-no-elements +plugins/modules/zabbix_template.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_template.py validate-modules:parameter-list-no-elements +plugins/modules/zabbix_user.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_user.py validate-modules:parameter-list-no-elements +plugins/doc_fragments/zabbix.py future-import-boilerplate +plugins/doc_fragments/zabbix.py metaclass-boilerplate +roles/zabbix_agent/molecule/with-server/tests/test_agent.py future-import-boilerplate +roles/zabbix_agent/molecule/with-server/tests/test_default.py future-import-boilerplate +roles/zabbix_agent/molecule/with-server/tests/test_agent.py metaclass-boilerplate +roles/zabbix_agent/molecule/with-server/tests/test_default.py metaclass-boilerplate
\ No newline at end of file diff --git a/ansible_collections/community/zabbix/tests/sanity/ignore-2.11.txt b/ansible_collections/community/zabbix/tests/sanity/ignore-2.11.txt new file mode 100644 index 000000000..8854fcd2d --- /dev/null +++ b/ansible_collections/community/zabbix/tests/sanity/ignore-2.11.txt @@ -0,0 +1,34 @@ +scripts/inventory/zabbix.py future-import-boilerplate +scripts/inventory/zabbix.py metaclass-boilerplate +plugins/modules/zabbix_action.py validate-modules:doc-choices-do-not-match-spec +plugins/modules/zabbix_action.py validate-modules:doc-default-does-not-match-spec +plugins/modules/zabbix_action.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_action.py validate-modules:doc-required-mismatch +plugins/modules/zabbix_action.py validate-modules:invalid-argument-name +plugins/modules/zabbix_action.py validate-modules:missing-suboption-docs +plugins/modules/zabbix_action.py validate-modules:nonexistent-parameter-documented +plugins/modules/zabbix_action.py validate-modules:parameter-list-no-elements +plugins/modules/zabbix_action.py validate-modules:parameter-type-not-in-doc +plugins/modules/zabbix_action.py validate-modules:undocumented-parameter +plugins/modules/zabbix_group.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_group.py validate-modules:parameter-list-no-elements +plugins/modules/zabbix_group_info.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_group_info.py validate-modules:parameter-list-no-elements +plugins/modules/zabbix_host.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_host.py validate-modules:parameter-list-no-elements +plugins/modules/zabbix_host_info.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_host_info.py validate-modules:parameter-list-no-elements +plugins/modules/zabbix_maintenance.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_maintenance.py validate-modules:parameter-list-no-elements +plugins/modules/zabbix_mediatype.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_mediatype.py validate-modules:parameter-list-no-elements +plugins/modules/zabbix_template.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_template.py validate-modules:parameter-list-no-elements +plugins/modules/zabbix_user.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_user.py validate-modules:parameter-list-no-elements +plugins/doc_fragments/zabbix.py future-import-boilerplate +plugins/doc_fragments/zabbix.py metaclass-boilerplate +roles/zabbix_agent/molecule/with-server/tests/test_agent.py future-import-boilerplate +roles/zabbix_agent/molecule/with-server/tests/test_default.py future-import-boilerplate +roles/zabbix_agent/molecule/with-server/tests/test_agent.py metaclass-boilerplate +roles/zabbix_agent/molecule/with-server/tests/test_default.py metaclass-boilerplate
\ No newline at end of file diff --git a/ansible_collections/community/zabbix/tests/sanity/ignore-2.12.txt b/ansible_collections/community/zabbix/tests/sanity/ignore-2.12.txt new file mode 100644 index 000000000..628f32ff1 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/sanity/ignore-2.12.txt @@ -0,0 +1,26 @@ +plugins/modules/zabbix_action.py validate-modules:doc-choices-do-not-match-spec +plugins/modules/zabbix_action.py validate-modules:doc-default-does-not-match-spec +plugins/modules/zabbix_action.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_action.py validate-modules:doc-required-mismatch +plugins/modules/zabbix_action.py validate-modules:invalid-argument-name +plugins/modules/zabbix_action.py validate-modules:missing-suboption-docs +plugins/modules/zabbix_action.py validate-modules:nonexistent-parameter-documented +plugins/modules/zabbix_action.py validate-modules:parameter-list-no-elements +plugins/modules/zabbix_action.py validate-modules:parameter-type-not-in-doc +plugins/modules/zabbix_action.py validate-modules:undocumented-parameter +plugins/modules/zabbix_group.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_group.py validate-modules:parameter-list-no-elements +plugins/modules/zabbix_group_info.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_group_info.py validate-modules:parameter-list-no-elements +plugins/modules/zabbix_host.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_host.py validate-modules:parameter-list-no-elements +plugins/modules/zabbix_host_info.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_host_info.py validate-modules:parameter-list-no-elements +plugins/modules/zabbix_maintenance.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_maintenance.py validate-modules:parameter-list-no-elements +plugins/modules/zabbix_mediatype.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_mediatype.py validate-modules:parameter-list-no-elements +plugins/modules/zabbix_template.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_template.py validate-modules:parameter-list-no-elements +plugins/modules/zabbix_user.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_user.py validate-modules:parameter-list-no-elements
\ No newline at end of file diff --git a/ansible_collections/community/zabbix/tests/sanity/ignore-2.13.txt b/ansible_collections/community/zabbix/tests/sanity/ignore-2.13.txt new file mode 100644 index 000000000..628f32ff1 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/sanity/ignore-2.13.txt @@ -0,0 +1,26 @@ +plugins/modules/zabbix_action.py validate-modules:doc-choices-do-not-match-spec +plugins/modules/zabbix_action.py validate-modules:doc-default-does-not-match-spec +plugins/modules/zabbix_action.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_action.py validate-modules:doc-required-mismatch +plugins/modules/zabbix_action.py validate-modules:invalid-argument-name +plugins/modules/zabbix_action.py validate-modules:missing-suboption-docs +plugins/modules/zabbix_action.py validate-modules:nonexistent-parameter-documented +plugins/modules/zabbix_action.py validate-modules:parameter-list-no-elements +plugins/modules/zabbix_action.py validate-modules:parameter-type-not-in-doc +plugins/modules/zabbix_action.py validate-modules:undocumented-parameter +plugins/modules/zabbix_group.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_group.py validate-modules:parameter-list-no-elements +plugins/modules/zabbix_group_info.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_group_info.py validate-modules:parameter-list-no-elements +plugins/modules/zabbix_host.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_host.py validate-modules:parameter-list-no-elements +plugins/modules/zabbix_host_info.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_host_info.py validate-modules:parameter-list-no-elements +plugins/modules/zabbix_maintenance.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_maintenance.py validate-modules:parameter-list-no-elements +plugins/modules/zabbix_mediatype.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_mediatype.py validate-modules:parameter-list-no-elements +plugins/modules/zabbix_template.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_template.py validate-modules:parameter-list-no-elements +plugins/modules/zabbix_user.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_user.py validate-modules:parameter-list-no-elements
\ No newline at end of file diff --git a/ansible_collections/community/zabbix/tests/sanity/ignore-2.14.txt b/ansible_collections/community/zabbix/tests/sanity/ignore-2.14.txt new file mode 100644 index 000000000..628f32ff1 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/sanity/ignore-2.14.txt @@ -0,0 +1,26 @@ +plugins/modules/zabbix_action.py validate-modules:doc-choices-do-not-match-spec +plugins/modules/zabbix_action.py validate-modules:doc-default-does-not-match-spec +plugins/modules/zabbix_action.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_action.py validate-modules:doc-required-mismatch +plugins/modules/zabbix_action.py validate-modules:invalid-argument-name +plugins/modules/zabbix_action.py validate-modules:missing-suboption-docs +plugins/modules/zabbix_action.py validate-modules:nonexistent-parameter-documented +plugins/modules/zabbix_action.py validate-modules:parameter-list-no-elements +plugins/modules/zabbix_action.py validate-modules:parameter-type-not-in-doc +plugins/modules/zabbix_action.py validate-modules:undocumented-parameter +plugins/modules/zabbix_group.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_group.py validate-modules:parameter-list-no-elements +plugins/modules/zabbix_group_info.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_group_info.py validate-modules:parameter-list-no-elements +plugins/modules/zabbix_host.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_host.py validate-modules:parameter-list-no-elements +plugins/modules/zabbix_host_info.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_host_info.py validate-modules:parameter-list-no-elements +plugins/modules/zabbix_maintenance.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_maintenance.py validate-modules:parameter-list-no-elements +plugins/modules/zabbix_mediatype.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_mediatype.py validate-modules:parameter-list-no-elements +plugins/modules/zabbix_template.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_template.py validate-modules:parameter-list-no-elements +plugins/modules/zabbix_user.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_user.py validate-modules:parameter-list-no-elements
\ No newline at end of file diff --git a/ansible_collections/community/zabbix/tests/sanity/ignore-2.15.txt b/ansible_collections/community/zabbix/tests/sanity/ignore-2.15.txt new file mode 100644 index 000000000..628f32ff1 --- /dev/null +++ b/ansible_collections/community/zabbix/tests/sanity/ignore-2.15.txt @@ -0,0 +1,26 @@ +plugins/modules/zabbix_action.py validate-modules:doc-choices-do-not-match-spec +plugins/modules/zabbix_action.py validate-modules:doc-default-does-not-match-spec +plugins/modules/zabbix_action.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_action.py validate-modules:doc-required-mismatch +plugins/modules/zabbix_action.py validate-modules:invalid-argument-name +plugins/modules/zabbix_action.py validate-modules:missing-suboption-docs +plugins/modules/zabbix_action.py validate-modules:nonexistent-parameter-documented +plugins/modules/zabbix_action.py validate-modules:parameter-list-no-elements +plugins/modules/zabbix_action.py validate-modules:parameter-type-not-in-doc +plugins/modules/zabbix_action.py validate-modules:undocumented-parameter +plugins/modules/zabbix_group.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_group.py validate-modules:parameter-list-no-elements +plugins/modules/zabbix_group_info.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_group_info.py validate-modules:parameter-list-no-elements +plugins/modules/zabbix_host.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_host.py validate-modules:parameter-list-no-elements +plugins/modules/zabbix_host_info.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_host_info.py validate-modules:parameter-list-no-elements +plugins/modules/zabbix_maintenance.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_maintenance.py validate-modules:parameter-list-no-elements +plugins/modules/zabbix_mediatype.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_mediatype.py validate-modules:parameter-list-no-elements +plugins/modules/zabbix_template.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_template.py validate-modules:parameter-list-no-elements +plugins/modules/zabbix_user.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_user.py validate-modules:parameter-list-no-elements
\ No newline at end of file diff --git a/ansible_collections/community/zabbix/tests/sanity/ignore-2.9.txt b/ansible_collections/community/zabbix/tests/sanity/ignore-2.9.txt new file mode 100644 index 000000000..0b5abb56b --- /dev/null +++ b/ansible_collections/community/zabbix/tests/sanity/ignore-2.9.txt @@ -0,0 +1,30 @@ +scripts/inventory/zabbix.py future-import-boilerplate +scripts/inventory/zabbix.py metaclass-boilerplate +plugins/modules/zabbix_action.py validate-modules:doc-choices-do-not-match-spec +plugins/modules/zabbix_action.py validate-modules:doc-default-does-not-match-spec +plugins/modules/zabbix_action.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_action.py validate-modules:doc-required-mismatch +plugins/modules/zabbix_action.py validate-modules:invalid-argument-name +plugins/modules/zabbix_action.py validate-modules:missing-suboption-docs +plugins/modules/zabbix_action.py validate-modules:nonexistent-parameter-documented +plugins/modules/zabbix_action.py validate-modules:parameter-list-no-elements +plugins/modules/zabbix_action.py validate-modules:parameter-type-not-in-doc +plugins/modules/zabbix_action.py validate-modules:undocumented-parameter +plugins/modules/zabbix_group.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_group.py validate-modules:parameter-list-no-elements +plugins/modules/zabbix_group_info.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_group_info.py validate-modules:parameter-list-no-elements +plugins/modules/zabbix_host.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_host.py validate-modules:parameter-list-no-elements +plugins/modules/zabbix_host_info.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_host_info.py validate-modules:parameter-list-no-elements +plugins/modules/zabbix_maintenance.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_maintenance.py validate-modules:parameter-list-no-elements +plugins/modules/zabbix_mediatype.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_mediatype.py validate-modules:parameter-list-no-elements +plugins/modules/zabbix_template.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_template.py validate-modules:parameter-list-no-elements +plugins/modules/zabbix_user.py validate-modules:doc-elements-mismatch +plugins/modules/zabbix_user.py validate-modules:parameter-list-no-elements +plugins/doc_fragments/zabbix.py future-import-boilerplate +plugins/doc_fragments/zabbix.py metaclass-boilerplate
\ No newline at end of file |