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

Don't reset IPMI setting when update inventory #1162

Merged
merged 2 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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/1162-do_not_update_ipmi_options.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- zabbix_host - Don't reset IPMI setting when update inventory
Copy link
Collaborator

@BGmot BGmot Jan 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- - zabbix_host - Don't reset IPMI setting when update inventory
+ - zabbix_host - Don't reset IPMI setting when update inventory data of a host

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I have changed to the sentence which you wrote.

47 changes: 12 additions & 35 deletions plugins/modules/zabbix_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ def add_host(self, host_name, group_ids, status, interfaces, proxy_id, visible_n

def update_host(self, host_name, group_ids, status, host_id, interfaces, exist_interface_list, proxy_id,
visible_name, description, tls_connect, tls_accept, tls_psk_identity, tls_psk, tls_issuer,
tls_subject, ipmi_authtype, ipmi_privilege, ipmi_username, ipmi_password, macros, tags, discovered_host):
tls_subject, ipmi_authtype, ipmi_privilege, ipmi_username, ipmi_password, macros, tags, discovered_host, zabbix_host_obj):
try:
if self._module.check_mode:
self._module.exit_json(changed=True)
Expand All @@ -525,7 +525,7 @@ def update_host(self, host_name, group_ids, status, host_id, interfaces, exist_i
parameters = {"hostid": host_id, "groups": group_ids, "status": status}
if proxy_id >= 0:
parameters["proxy_hostid"] = proxy_id
if visible_name:
if (visible_name is not None and visible_name != zabbix_host_obj["name"]):
parameters["name"] = visible_name
if tls_connect:
parameters["tls_connect"] = tls_connect
Expand All @@ -535,19 +535,19 @@ def update_host(self, host_name, group_ids, status, host_id, interfaces, exist_i
parameters["tls_psk_identity"] = tls_psk_identity
if tls_psk:
parameters["tls_psk"] = tls_psk
if tls_issuer:
if (tls_issuer is not None and tls_issuer != zabbix_host_obj["tls_issuer"]):
parameters["tls_issuer"] = tls_issuer
if tls_subject:
if (tls_subject is not None and tls_subject != zabbix_host_obj["tls_subject"]):
parameters["tls_subject"] = tls_subject
if description:
if (description is not None and description != zabbix_host_obj["description"]):
parameters["description"] = description
if ipmi_authtype:
parameters["ipmi_authtype"] = ipmi_authtype
if ipmi_privilege:
parameters["ipmi_privilege"] = ipmi_privilege
if ipmi_username:
if (ipmi_username is not None and ipmi_username != zabbix_host_obj["ipmi_username"]):
parameters["ipmi_username"] = ipmi_username
if ipmi_password:
if (ipmi_password is not None and ipmi_password != zabbix_host_obj["ipmi_password"]):
parameters["ipmi_password"] = ipmi_password
if interfaces:
parameters["interfaces"] = interfaces
Expand Down Expand Up @@ -809,8 +809,7 @@ def check_all_properties(self, host_id, group_ids, status, interfaces, template_
return False

# link or clear template of the host
def link_or_clear_template(self, host_id, template_id_list, tls_connect, tls_accept, tls_psk_identity, tls_psk,
tls_issuer, tls_subject, ipmi_authtype, ipmi_privilege, ipmi_username, ipmi_password, discovered_host):
def link_or_clear_template(self, host_id, template_id_list):
# get host's exist template ids
exist_template_id_list = self.get_host_templates_by_host_id(host_id)

Expand All @@ -821,25 +820,7 @@ def link_or_clear_template(self, host_id, template_id_list, tls_connect, tls_acc
# get unlink and clear templates
templates_clear = exist_template_ids.difference(template_ids)
templates_clear_list = list(templates_clear)
if discovered_host:
# The host was discovered via Discovery Rule
request_str = {"hostid": host_id, "templates": template_id_list, "templates_clear": templates_clear_list}
else:
# A "plain" host
request_str = {"hostid": host_id, "templates": template_id_list, "templates_clear": templates_clear_list,
"ipmi_authtype": ipmi_authtype, "ipmi_privilege": ipmi_privilege, "ipmi_username": ipmi_username, "ipmi_password": ipmi_password}
if tls_connect:
request_str["tls_connect"] = tls_connect
if tls_accept:
request_str["tls_accept"] = tls_accept
if tls_psk_identity is not None:
request_str["tls_psk_identity"] = tls_psk_identity
if tls_psk is not None:
request_str["tls_psk"] = tls_psk
if tls_issuer is not None:
request_str["tls_issuer"] = tls_issuer
if tls_subject is not None:
request_str["tls_subject"] = tls_subject
request_str = {"hostid": host_id, "templates": template_id_list, "templates_clear": templates_clear_list}
try:
if self._module.check_mode:
self._module.exit_json(changed=True)
Expand Down Expand Up @@ -1204,11 +1185,9 @@ def main():
host.update_host(
host_name, group_ids, status, host_id, interfaces, exist_interfaces, proxy_id, visible_name,
description, tls_connect, tls_accept, tls_psk_identity, tls_psk, tls_issuer, tls_subject,
ipmi_authtype, ipmi_privilege, ipmi_username, ipmi_password, macros, tags, discovered_host)
ipmi_authtype, ipmi_privilege, ipmi_username, ipmi_password, macros, tags, discovered_host, zabbix_host_obj)

host.link_or_clear_template(
host_id, template_ids, tls_connect, tls_accept, tls_psk_identity, tls_psk, tls_issuer,
tls_subject, ipmi_authtype, ipmi_privilege, ipmi_username, ipmi_password, discovered_host)
host.link_or_clear_template(host_id, template_ids)

host.update_inventory_mode(host_id, inventory_mode)
host.update_inventory_zabbix(host_id, inventory_zabbix)
Expand All @@ -1235,9 +1214,7 @@ def main():
tls_psk_identity, tls_psk, tls_issuer, tls_subject, ipmi_authtype, ipmi_privilege, ipmi_username,
ipmi_password, macros, tags)

host.link_or_clear_template(
host_id, template_ids, tls_connect, tls_accept, tls_psk_identity, tls_psk, tls_issuer, tls_subject,
ipmi_authtype, ipmi_privilege, ipmi_username, ipmi_password, discovered_host)
host.link_or_clear_template(host_id, template_ids)

host.update_inventory_mode(host_id, inventory_mode)
host.update_inventory_zabbix(host_id, inventory_zabbix)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1348,6 +1348,61 @@
ansible.builtin.assert:
that: zbx_host_create_interfaceless is not changed

- name: "test: attempt to delete host created earlier"
community.zabbix.zabbix_host:
host_name: ExampleHost
state: absent
register: zabbix_host1

- name: deleting a host is a change, right?
ansible.builtin.assert:
that:
- "zabbix_host1 is changed"

- name: "test: create host with IPMI values"
community.zabbix.zabbix_host:
host_name: ExampleHost
host_groups:
- Linux servers
- Zabbix servers
ipmi_authtype: 1
ipmi_privilege: 1
ipmi_username: "test"
ipmi_password: "test"
register: zabbix_ipmi_host

- name: expect to succeed and that things have changed
ansible.builtin.assert:
that:
- "zabbix_ipmi_host is changed"

- name: "test: update inventory of the created host"
community.zabbix.zabbix_host:
host_name: ExampleHost
inventory_mode: manual
inventory_zabbix:
notes: "Update inventory"
register: zabbix_ipmi_host

- name: expect to succeed and that things have changed
ansible.builtin.assert:
that:
- "zabbix_ipmi_host is changed"

- name: "test: create host with IPMI values without changes"
community.zabbix.zabbix_host:
host_name: ExampleHost
ipmi_authtype: 1
ipmi_privilege: 1
ipmi_username: "test"
ipmi_password: "test"
register: zabbix_ipmi_host

- name: expect to succeed and that things have not changed
ansible.builtin.assert:
that:
- "zabbix_ipmi_host is not changed"

- name: "cleanup"
community.zabbix.zabbix_host:
host_name: ExampleHost
Expand Down