From f1d05a680a41b03e17cc69cda7b0850ffae25402 Mon Sep 17 00:00:00 2001 From: ONODERA Masaru <46081939+masa-orca@users.noreply.github.com> Date: Sat, 20 Jan 2024 14:17:23 +0900 Subject: [PATCH] Finish task with failed if host_group parameter is empty list (#1168) --- ...ed-if-host_group-parameter-is-empty_list.yml | 2 ++ plugins/modules/zabbix_host.py | 7 +++++-- .../tasks/zabbix_host_tests.yml | 17 +++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/1168-finish-task-with-failed-if-host_group-parameter-is-empty_list.yml diff --git a/changelogs/fragments/1168-finish-task-with-failed-if-host_group-parameter-is-empty_list.yml b/changelogs/fragments/1168-finish-task-with-failed-if-host_group-parameter-is-empty_list.yml new file mode 100644 index 000000000..3537a7bea --- /dev/null +++ b/changelogs/fragments/1168-finish-task-with-failed-if-host_group-parameter-is-empty_list.yml @@ -0,0 +1,2 @@ +bugfixes: + - zabbix_host - Finish task with failed if host_group parameter is empty list diff --git a/plugins/modules/zabbix_host.py b/plugins/modules/zabbix_host.py index 4f8df8779..00c04c221 100644 --- a/plugins/modules/zabbix_host.py +++ b/plugins/modules/zabbix_host.py @@ -1038,8 +1038,11 @@ def main(): group_ids = [] - if host_groups: - group_ids = host.get_group_ids_by_group_names(host_groups) + if host_groups is not None: + if len(host_groups) >= 1: + group_ids = host.get_group_ids_by_group_names(host_groups) + else: + module.fail_json(msg="host_groups must be not empty list.") interfaces, ip = host.construct_host_interfaces(interfaces) diff --git a/tests/integration/targets/test_zabbix_host/tasks/zabbix_host_tests.yml b/tests/integration/targets/test_zabbix_host/tasks/zabbix_host_tests.yml index 1f3318764..20246a16b 100644 --- a/tests/integration/targets/test_zabbix_host/tasks/zabbix_host_tests.yml +++ b/tests/integration/targets/test_zabbix_host/tasks/zabbix_host_tests.yml @@ -1403,6 +1403,23 @@ that: - "zabbix_ipmi_host is not changed" +- name: "test: create host with host group(empty list)" + community.zabbix.zabbix_host: + host_name: ExampleHost + visible_name: ExampleName + description: My ExampleHost Description + host_groups: [] + status: disabled + state: present + ignore_errors: true + register: zbx_host_create_hostgroup_empty_list + +- name: expect to fail updating + ansible.builtin.assert: + that: + - zbx_host_create_hostgroup_empty_list is failed + - zbx_host_create_hostgroup_empty_list.msg == "host_groups must be not empty list." + - name: "cleanup" community.zabbix.zabbix_host: host_name: ExampleHost