From 820f957755b88bec08a60eee5601b1e68e9f6593 Mon Sep 17 00:00:00 2001 From: ONODERA Masaru Date: Tue, 16 Jan 2024 17:45:05 +0000 Subject: [PATCH] Finish task with failed if host_group parameter is empty list --- ...-failed-if-host_group-parameter-is-empty_list.yml | 2 ++ plugins/modules/zabbix_host.py | 7 +++++-- .../test_zabbix_host/tasks/zabbix_host_tests.yml | 12 ++++++++++++ 3 files changed, 19 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..cc595c75a 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 @@ -1397,11 +1397,23 @@ ipmi_username: "test" ipmi_password: "test" register: zabbix_ipmi_host +- 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 succeed and that things have not changed ansible.builtin.assert: that: - "zabbix_ipmi_host is not changed" + - 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: