Skip to content

Commit

Permalink
Finish task with failed if host_group parameter is empty list
Browse files Browse the repository at this point in the history
  • Loading branch information
masa-orca committed Jan 17, 2024
1 parent 15188b1 commit 8794ceb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- zabbix_host - Finish task with failed if host_group parameter is empty list
7 changes: 5 additions & 2 deletions plugins/modules/zabbix_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8794ceb

Please sign in to comment.