Skip to content

Commit

Permalink
zabbix_host_info: return all the hosts (#1151)
Browse files Browse the repository at this point in the history
  • Loading branch information
BGmot authored Dec 30, 2023
1 parent c92ad07 commit 9a9863f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/host_info_all_hosts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- zabbix_host_info - added ability to get all the hosts configured in Zabbix
3 changes: 2 additions & 1 deletion plugins/modules/zabbix_host_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
- Name of the host in Zabbix.
- host_name is the unique identifier used and cannot be updated using this module.
- Required when I(host_ip) is not used.
- If neither host_name nor host_ip specified then all the hosts configured in Zabbix returned.
required: false
type: str
default: ""
Expand Down Expand Up @@ -207,7 +208,7 @@ def main():

host = Host(module)

if host_name:
if host_name != "" or (host_name == "" and len(host_ips) == 0):
hosts = host.get_hosts_by_host_name(host_name, exact_match, host_inventory)
if is_remove_duplicate:
hosts = host.delete_duplicate_hosts(hosts)
Expand Down
6 changes: 5 additions & 1 deletion tests/integration/targets/test_zabbix_host/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
always:
- name: "cleanup if tests failed"
community.zabbix.zabbix_host:
host_name: ExampleHost
host_name: "{{ item }}"
state: absent
ignore_errors: true
with_items:
- ExampleHost
- ExampleHost1
- ExampleHost2
13 changes: 13 additions & 0 deletions tests/integration/targets/test_zabbix_host_info/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,16 @@
- ansible.builtin.assert:
that:
- exact_match_host_not_found_result.failed is sameas true

- name: Get all hosts
community.zabbix.zabbix_host_info:
register: get_all_hosts_result

- ansible.builtin.assert:
that:
- get_all_hosts_result.hosts | length == 2

- name: Clean up test host
community.zabbix.zabbix_host:
host_name: ExampleHostForHostInfoModule
state: absent

0 comments on commit 9a9863f

Please sign in to comment.