Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zabbix_host_info: return all the hosts #1153

Merged
merged 2 commits into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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