Skip to content

Commit

Permalink
Don't reset IPMI setting when update inventory
Browse files Browse the repository at this point in the history
  • Loading branch information
masa-orca committed Jan 11, 2024
1 parent f2287d6 commit 6fb0dfc
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 35 deletions.
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
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

0 comments on commit 6fb0dfc

Please sign in to comment.