From c4f6ba45d3cfb8bc50d20ca8577c691c8b4c7a3a Mon Sep 17 00:00:00 2001 From: Martin Eiswirth Date: Thu, 10 Oct 2024 14:56:53 +0200 Subject: [PATCH 1/7] Cleanup initial fact setting + fix zabbix_agent_X_version vars + fix directory creation --- roles/zabbix_agent/tasks/Windows.yml | 35 ++++++---------------------- 1 file changed, 7 insertions(+), 28 deletions(-) diff --git a/roles/zabbix_agent/tasks/Windows.yml b/roles/zabbix_agent/tasks/Windows.yml index 612f1db7c..47f66e703 100644 --- a/roles/zabbix_agent/tasks/Windows.yml +++ b/roles/zabbix_agent/tasks/Windows.yml @@ -5,34 +5,11 @@ zabbix_agent_win_logfile: "{{ zabbix_agent_win_logfile is defined | ternary(zabbix_agent_win_logfile, zabbix_agent2_win_logfile) | default(_win_logfile) }}" zabbix_agent_win_package: "{{ zabbix_agent_win_package is defined | ternary(zabbix_agent_win_package, zabbix_agent2_win_package) | default(_win_package) }}" zabbix_agent_win_include: "{{ zabbix_agent_win_include is defined | ternary(zabbix_agent_win_include, zabbix_agent2_win_include) | default(_win_include) }}" - -- name: "Windows | Set default architecture" - ansible.builtin.set_fact: - windows_arch: 32 - tags: - - always - -- name: "Windows | Override architecture if 64-bit" - ansible.builtin.set_fact: - windows_arch: 64 - when: - - '"64" in ansible_architecture' - tags: - - always - -- name: "Windows | Set path to zabbix.exe" - ansible.builtin.set_fact: - zabbix_win_exe_path: '{{ zabbix_win_install_dir }}\bin\win{{ windows_arch }}\zabbix_agentd.exe' - tags: - - always - -- name: "Windows | Set variables specific to Zabbix" - ansible.builtin.set_fact: zabbix_win_svc_name: Zabbix Agent - zabbix_win_exe_path: '{{ zabbix_win_install_dir }}\bin\zabbix_agentd.exe' + zabbix_win_exe_path: '{{ zabbix_win_install_dir_bin }}\zabbix_agentd.exe' zabbix_win_config_name: "zabbix_agentd.conf" zabbix2_win_svc_name: Zabbix Agent 2 - zabbix2_win_exe_path: '{{ zabbix_win_install_dir }}\bin\zabbix_agent2.exe' + zabbix2_win_exe_path: '{{ zabbix_win_install_dir_bin }}\zabbix_agent2.exe' zabbix2_win_config_name: "zabbix_agent2.conf" tags: - always @@ -60,7 +37,7 @@ - name: "Windows | Set facts current zabbix agent installation" ansible.builtin.set_fact: zabbix_agent_1_binary_exist: true - zabbix_agent_1_version: zabbix_win_exe_info.results[0].win_file_version.product_version + zabbix_agent_1_version: "{{ zabbix_win_exe_info.results[0].win_file_version.product_version }}" when: - zabbix_win_exe_info.results[0] is defined - zabbix_win_exe_info.results[0].item.stat.exists @@ -72,7 +49,7 @@ - name: "Windows | Set facts current zabbix agent installation (agent 2)" ansible.builtin.set_fact: zabbix_agent_2_binary_exist: true - zabbix_agent_2_version: zabbix_win_exe_info.results[1].win_file_version.product_version + zabbix_agent_2_version: "{{ zabbix_win_exe_info.results[1].win_file_version.product_version }}" when: - zabbix_win_exe_info.results[1] is defined - zabbix_win_exe_info.results[1].item.stat.exists @@ -83,7 +60,7 @@ - name: "Windows | Check Zabbix service" ansible.windows.win_service: - name: "{{ (item.item.stat.path == zabbix_win_exe_path ) | ternary(zabbix_win_svc_name,zabbix2_win_svc_name) }}" + name: "{{ (item.item.stat.path == zabbix_win_exe_path) | ternary(zabbix_win_svc_name, zabbix2_win_svc_name) }}" register: zabbix_service_info when: item.item.stat.exists with_items: "{{ zabbix_win_exe_info.results }}" @@ -176,6 +153,8 @@ state: directory with_items: - "{{ zabbix_win_install_dir }}" + - "{{ zabbix_win_install_dir_conf }}" + - "{{ zabbix_win_install_dir_bin }}" tags: - install From cd437d1f1c7dc899166ad3e2aeb07e7a50602e20 Mon Sep 17 00:00:00 2001 From: Martin Eiswirth Date: Thu, 10 Oct 2024 17:40:32 +0200 Subject: [PATCH 2/7] general cleanup of windows agent setup --- roles/zabbix_agent/defaults/main.yml | 1 + roles/zabbix_agent/tasks/Windows.yml | 120 +++++++++++----------- roles/zabbix_agent/tasks/Windows_conf.yml | 2 +- roles/zabbix_agent/vars/agent2_vars.yml | 1 - roles/zabbix_agent/vars/agent_vars.yml | 1 - 5 files changed, 64 insertions(+), 61 deletions(-) diff --git a/roles/zabbix_agent/defaults/main.yml b/roles/zabbix_agent/defaults/main.yml index 9f090a12c..f9aa58f74 100644 --- a/roles/zabbix_agent/defaults/main.yml +++ b/roles/zabbix_agent/defaults/main.yml @@ -110,6 +110,7 @@ zabbix_version_long: 5.2.4 # Windows Related zabbix_win_download_url: https://cdn.zabbix.com/zabbix/binaries/stable +zabbix_win_download_link: "{{ zabbix_win_download_url }}/{{ zabbix_version_long | regex_search('^\\d+\\.\\d+') }}/{{ zabbix_version_long }}/{{ zabbix_win_package | default(_win_package) }}" zabbix_win_install_dir: 'C:\Zabbix' zabbix_win_install_dir_conf: '{{ zabbix_win_install_dir }}\conf' zabbix_win_install_dir_bin: '{{ zabbix_win_install_dir }}\bin' diff --git a/roles/zabbix_agent/tasks/Windows.yml b/roles/zabbix_agent/tasks/Windows.yml index 47f66e703..c833d422d 100644 --- a/roles/zabbix_agent/tasks/Windows.yml +++ b/roles/zabbix_agent/tasks/Windows.yml @@ -1,16 +1,20 @@ --- -- name: "Windows | Set some variables" +- name: "Windows | Set base variables" ansible.builtin.set_fact: - zabbix_agent_win_download_link: "{{ zabbix_agent_win_download_link is defined | ternary(zabbix_agent_win_download_link, zabbix_agent2_win_download_link) | default(_win_download_link) }}" zabbix_agent_win_logfile: "{{ zabbix_agent_win_logfile is defined | ternary(zabbix_agent_win_logfile, zabbix_agent2_win_logfile) | default(_win_logfile) }}" zabbix_agent_win_package: "{{ zabbix_agent_win_package is defined | ternary(zabbix_agent_win_package, zabbix_agent2_win_package) | default(_win_package) }}" zabbix_agent_win_include: "{{ zabbix_agent_win_include is defined | ternary(zabbix_agent_win_include, zabbix_agent2_win_include) | default(_win_include) }}" + zabbix_win_install_dir_setup: '{{ zabbix_win_install_dir }}\setup' + zabbix_win_package: "{{ zabbix_win_package | default(_win_package) }}" zabbix_win_svc_name: Zabbix Agent + zabbix_win_exe_name: 'zabbix_agentd.exe' zabbix_win_exe_path: '{{ zabbix_win_install_dir_bin }}\zabbix_agentd.exe' zabbix_win_config_name: "zabbix_agentd.conf" zabbix2_win_svc_name: Zabbix Agent 2 + zabbix2_win_exe_name: 'zabbix_agent2.exe' zabbix2_win_exe_path: '{{ zabbix_win_install_dir_bin }}\zabbix_agent2.exe' zabbix2_win_config_name: "zabbix_agent2.conf" + tags: - always @@ -108,7 +112,6 @@ - name: "Windows | Stop Zabbix agent v1" ansible.windows.win_service: name: "{{ zabbix_win_svc_name }}" - start_mode: auto state: stopped when: - zabbix_agent_version_change | default(false) or zabbix_agent2 @@ -117,7 +120,6 @@ - name: "Windows | Stop Zabbix agent v2" ansible.windows.win_service: name: "{{ zabbix2_win_svc_name }}" - start_mode: auto state: stopped when: - zabbix_agent_version_change | default(false) or not zabbix_agent2 @@ -139,6 +141,10 @@ ansible.windows.win_file: path: "{{ zabbix_win_install_dir }}" state: absent + register: zabbix_agent_dir_remove_result + until: zabbix_agent_dir_remove_result is succeeded + retries: 5 + delay: 15 when: ((zabbix_agent_version_change | default(false) or zabbix_agent2) and zabbix_agent_1_binary_exist | default(false)) or ((zabbix_agent_version_change | default(false) or not zabbix_agent2) and zabbix_agent_2_binary_exist | default(false)) @@ -147,6 +153,23 @@ # install section # ################### +- name: "Windows | Set installation settings (agent 2)" + ansible.builtin.set_fact: + zabbix_win_exe_path: "{{ zabbix2_win_exe_path }}" + zabbix_win_exe_name: "{{ zabbix2_win_exe_name }}" + zabbix_win_config_name: "{{ zabbix2_win_config_name }}" + zabbix_win_svc_name: "{{ zabbix2_win_svc_name }}" + when: zabbix_agent2 | bool + tags: + - install + +- name: "Windows | Check if agent binaries in place" + ansible.windows.win_stat: + path: "{{ zabbix_win_exe_path }}" + register: zabbix_windows_binaries + tags: + - install + - name: "Windows | Create directory structure" ansible.windows.win_file: path: "{{ item }}" @@ -155,6 +178,8 @@ - "{{ zabbix_win_install_dir }}" - "{{ zabbix_win_install_dir_conf }}" - "{{ zabbix_win_install_dir_bin }}" + - "{{ zabbix_win_install_dir_setup }}" + when: zabbix_agent_version_change | default(false) or not zabbix_windows_binaries.stat.exists tags: - install @@ -169,35 +194,19 @@ tags: - install -- name: "Windows | Set installation settings (agent 2)" - ansible.builtin.set_fact: - zabbix_win_package: "{{ zabbix_win_package | default(_win_package) }}" - zabbix_win_download_link: "{{ zabbix_win_download_link | default(_win_download_link) }}" - zabbix_win_exe_path: "{{ zabbix2_win_exe_path }}" - zabbix_win_config_name: "{{ zabbix2_win_config_name }}" - zabbix_win_svc_name: "{{ zabbix2_win_svc_name }}" - when: zabbix_agent2 | bool - tags: - - install - - name: "Windows | Check if agent file is already downloaded" ansible.windows.win_stat: - path: '{{ zabbix_win_install_dir }}\{{ zabbix_win_package }}' + path: '{{ zabbix_win_install_dir_setup }}\{{ zabbix_win_package }}' + when: + - zabbix_agent_version_change | default(false) or not zabbix_windows_binaries.stat.exists register: file_info tags: - install -- name: "Windows | Check if agent binaries in place" - ansible.windows.win_stat: - path: "{{ zabbix_win_exe_path }}" - register: zabbix_windows_binaries - tags: - - install - - name: "Windows | Download Zabbix Agent Zip file" ansible.windows.win_get_url: url: "{{ zabbix_win_download_link }}" - dest: '{{ zabbix_win_install_dir }}\{{ zabbix_win_package }}' + dest: '{{ zabbix_win_install_dir_setup }}\{{ zabbix_win_package }}' url_username: "{{ zabbix_download_user | default(omit) }}" url_password: "{{ zabbix_download_pass | default(omit) }}" force: false @@ -206,8 +215,8 @@ validate_certs: "{{ zabbix_download_validate_certs | default(False) | bool }}" timeout: "{{ zabbix_download_timeout | default(120) | int }}" when: + - zabbix_agent_version_change | default(false) or not zabbix_windows_binaries.stat.exists - not file_info.stat.exists - - not zabbix_windows_binaries.stat.exists register: zabbix_agent_win_download_zip until: zabbix_agent_win_download_zip is succeeded throttle: "{{ zabbix_download_throttle | default(5) | int }}" @@ -216,61 +225,56 @@ - name: "Windows | Unzip file" community.windows.win_unzip: - src: '{{ zabbix_win_install_dir }}\{{ zabbix_win_package }}' - dest: "{{ zabbix_win_install_dir }}" - creates: "{{ zabbix_win_exe_path }}" - tags: - - install - -- name: "Windows | Cleanup downloaded Zabbix Agent Zip file" - ansible.windows.win_file: - path: '{{ zabbix_win_install_dir }}\{{ zabbix_win_package }}' - state: absent + src: '{{ zabbix_win_install_dir_setup }}\{{ zabbix_win_package }}' + dest: "{{ zabbix_win_install_dir_setup }}" when: - - zabbix_agent_win_download_zip.changed + - zabbix_agent_version_change | default(false) or not zabbix_windows_binaries.stat.exists + - zabbix_agent_win_download_zip is changed or file_info.stat.exists tags: - install - name: "Windows | Copy binary files to expected location" ansible.windows.win_copy: - src: "{{ zabbix_win_install_dir }}\\bin\\{{ item }}" + src: "{{ zabbix_win_install_dir_setup }}\\bin\\{{ item }}" dest: "{{ zabbix_win_install_dir_bin }}\\{{ item }}" - remote_src: yes + remote_src: true loop: - - zabbix_agentd.exe + - "{{ zabbix_win_exe_name }}" - zabbix_sender.exe + - zabbix_get.exe when: - - zabbix_win_install_dir_bin is defined - - not (zabbix_agent2 | bool) + - zabbix_agent_version_change | default(false) or not zabbix_windows_binaries.stat.exists + - zabbix_agent_win_download_zip is changed or file_info.stat.exists tags: - install -- name: "Windows | Copy binary files to expected location (zabbix-agent2)" +- name: "Windows | Copy initial configuration to expected location" ansible.windows.win_copy: - src: "{{ zabbix_win_install_dir }}\\bin\\{{ item }}" - dest: "{{ zabbix_win_install_dir_bin }}\\{{ item }}" - remote_src: yes - loop: - - zabbix_agent2.exe + src: "{{ zabbix_win_install_dir_setup }}\\conf\\{{ zabbix_win_config_name }}" + dest: "{{ zabbix_win_install_dir_conf }}\\{{ zabbix_win_config_name }}" + force: false + remote_src: true when: - - zabbix_win_install_dir_bin is defined - - zabbix_agent2 | bool + - zabbix_agent_win_download_zip is changed or file_info.stat.exists | default(false) tags: - install -- set_fact: - zabbix_win_exe_path: "{{ zabbix_win_install_dir_bin }}\\zabbix_agentd.exe" +- name: "Windows | Copy plugin configuration to expected location on Agent 2" + ansible.windows.win_copy: + src: "{{ zabbix_win_install_dir_setup }}\\conf\\zabbix_agent2.d\\plugins.d" + dest: "{{ zabbix_win_install_dir_conf }}\\zabbix_agent2.d\\plugins.d" + force: false + remote_src: true when: - - zabbix_win_install_dir_bin is defined - - not (zabbix_agent2 | bool) + - zabbix_agent2 + - zabbix_agent_win_download_zip is changed or file_info.stat.exists | default(false) tags: - install -- set_fact: - zabbix_win_exe_path: "{{ zabbix_win_install_dir_bin }}\\zabbix_agent2.exe" - when: - - zabbix_win_install_dir_bin is defined - - zabbix_agent2 | bool +- name: "Windows | Cleanup temporary setup directory" + ansible.windows.win_file: + path: '{{ zabbix_win_install_dir_setup }}' + state: absent tags: - install diff --git a/roles/zabbix_agent/tasks/Windows_conf.yml b/roles/zabbix_agent/tasks/Windows_conf.yml index f97199d11..b3eaf2f0e 100644 --- a/roles/zabbix_agent/tasks/Windows_conf.yml +++ b/roles/zabbix_agent/tasks/Windows_conf.yml @@ -32,7 +32,6 @@ ansible.windows.win_service: name: "{{ zabbix_win_svc_name }}" start_mode: auto - state: started failure_actions: - type: restart delay_ms: 5000 @@ -41,6 +40,7 @@ - type: restart delay_ms: 20000 failure_reset_period_sec: 86400 + notify: restart win zabbix agent tags: - config diff --git a/roles/zabbix_agent/vars/agent2_vars.yml b/roles/zabbix_agent/vars/agent2_vars.yml index 119aa3a93..2202c779b 100644 --- a/roles/zabbix_agent/vars/agent2_vars.yml +++ b/roles/zabbix_agent/vars/agent2_vars.yml @@ -5,7 +5,6 @@ _include: - /etc/zabbix/zabbix_agent2.d/plugins.d _tls_subject: "{{ zabbix_agent_tlsservercertsubject | default(omit) }}" # FIXME this is not correct and should be removed with 2.0.0, here only to prevent regression _win_package: zabbix_agent2-{{ zabbix_version_long }}-windows-amd64-openssl-static.zip -_win_download_link: "{{ zabbix_win_download_url }}/{{ zabbix_version_long | regex_search('^\\d+\\.\\d+') }}/{{ zabbix_version_long }}/{{ zabbix_win_package | default(_win_package) }}" _win_logfile: '{{ zabbix_win_install_dir }}\zabbix_agent2.log' _win_include: '{{ zabbix_win_install_dir_conf }}\zabbix_agent2.d' _agent_service: zabbix-agent2 diff --git a/roles/zabbix_agent/vars/agent_vars.yml b/roles/zabbix_agent/vars/agent_vars.yml index ebd1f4dc8..35640c39d 100644 --- a/roles/zabbix_agent/vars/agent_vars.yml +++ b/roles/zabbix_agent/vars/agent_vars.yml @@ -3,7 +3,6 @@ _logfile: /var/log/zabbix/zabbix_agentd.log _include: /etc/zabbix/zabbix_agentd.d _tls_subject: "{{ zabbix_agent_tlsservercertsubject | default(omit) }}" # FIXME this is not correct and should be removed with 2.0.0, here only to prevent regression _win_package: zabbix_agent-{{ zabbix_version_long }}-windows-amd64-openssl.zip -_win_download_link: "{{ zabbix_win_download_url }}/{{ zabbix_version_long | regex_search('^\\d+\\.\\d+') }}/{{ zabbix_version_long }}/{{ zabbix_win_package | default(_win_package) }}" _win_logfile: '{{ zabbix_win_install_dir }}\zabbix_agentd.log' _win_include: '{{ zabbix_win_install_dir_conf }}\zabbix_agent.d' _agent_service: zabbix-agent From 3e193d8526930c4d48c974c9ca63f75a02eb6a9e Mon Sep 17 00:00:00 2001 From: Martin Eiswirth Date: Fri, 11 Oct 2024 10:06:21 +0200 Subject: [PATCH 3/7] Add zabbix_win_config_remove option --- docs/ZABBIX_AGENT_ROLE.md | 1 + roles/zabbix_agent/defaults/main.yml | 1 + roles/zabbix_agent/handlers/main.yml | 2 ++ roles/zabbix_agent/tasks/Windows.yml | 19 ++++++++++++++++--- 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/docs/ZABBIX_AGENT_ROLE.md b/docs/ZABBIX_AGENT_ROLE.md index 92fc12de9..59bc582b3 100644 --- a/docs/ZABBIX_AGENT_ROLE.md +++ b/docs/ZABBIX_AGENT_ROLE.md @@ -229,6 +229,7 @@ Otherwise it just for the Zabbix Agent or for the Zabbix Agent 2. * `zabbix_win_install_dir_conf`: The directory where Zabbix configuration file needs to be installed. * `zabbix_win_install_dir_bin`: The directory where Zabbix binary file needs to be installed. * `zabbix_win_package`: file name pattern (zip only). This will be used to generate the `zabbix_win_download_link` variable. +* `zabbix_win_config_remove`: Remove all existing configuration on update. Default `True` ## macOS Variables diff --git a/roles/zabbix_agent/defaults/main.yml b/roles/zabbix_agent/defaults/main.yml index f9aa58f74..6890199e3 100644 --- a/roles/zabbix_agent/defaults/main.yml +++ b/roles/zabbix_agent/defaults/main.yml @@ -115,6 +115,7 @@ zabbix_win_install_dir: 'C:\Zabbix' zabbix_win_install_dir_conf: '{{ zabbix_win_install_dir }}\conf' zabbix_win_install_dir_bin: '{{ zabbix_win_install_dir }}\bin' zabbix_win_firewall_management: true +zabbix_win_config_remove: true # macOS Related zabbix_mac_package: zabbix_agent-{{ zabbix_version_long }}-macos-amd64-openssl.pkg diff --git a/roles/zabbix_agent/handlers/main.yml b/roles/zabbix_agent/handlers/main.yml index 9f04b1a9b..12a265077 100644 --- a/roles/zabbix_agent/handlers/main.yml +++ b/roles/zabbix_agent/handlers/main.yml @@ -22,6 +22,8 @@ win_service: name: "{{ zabbix_win_svc_name }}" state: restarted + register: zabbix_win_restart_result + until: zabbix_win_restart_result is succeeded when: - ansible_os_family == "Windows" diff --git a/roles/zabbix_agent/tasks/Windows.yml b/roles/zabbix_agent/tasks/Windows.yml index c833d422d..bd96d5e62 100644 --- a/roles/zabbix_agent/tasks/Windows.yml +++ b/roles/zabbix_agent/tasks/Windows.yml @@ -14,7 +14,6 @@ zabbix2_win_exe_name: 'zabbix_agent2.exe' zabbix2_win_exe_path: '{{ zabbix_win_install_dir_bin }}\zabbix_agent2.exe' zabbix2_win_config_name: "zabbix_agent2.conf" - tags: - always @@ -137,9 +136,9 @@ - zabbix_agent_version_change | default(false) or not zabbix_agent2 - zabbix_agent_2_service_exist | default(false) -- name: "Windows | Removing Zabbix Directory" +- name: "Windows | Removing Zabbix bin Directory" ansible.windows.win_file: - path: "{{ zabbix_win_install_dir }}" + path: "{{ zabbix_win_install_dir_bin }}" state: absent register: zabbix_agent_dir_remove_result until: zabbix_agent_dir_remove_result is succeeded @@ -149,6 +148,20 @@ ((zabbix_agent_version_change | default(false) or zabbix_agent2) and zabbix_agent_1_binary_exist | default(false)) or ((zabbix_agent_version_change | default(false) or not zabbix_agent2) and zabbix_agent_2_binary_exist | default(false)) +- name: "Windows | Removing Zabbix conf Directory" + ansible.windows.win_file: + path: "{{ zabbix_win_install_dir_conf }}" + state: absent + register: zabbix_agent_dir_remove_result + until: zabbix_agent_dir_remove_result is succeeded + retries: 5 + delay: 15 + when: + - zabbix_win_config_remove + - > + ((zabbix_agent_version_change | default(false) or zabbix_agent2) and zabbix_agent_1_binary_exist | default(false)) or + ((zabbix_agent_version_change | default(false) or not zabbix_agent2) and zabbix_agent_2_binary_exist | default(false)) + ################### # install section # ################### From 338fb74b212312ec5fa755b5bd2e7d254c63000a Mon Sep 17 00:00:00 2001 From: Martin Eiswirth Date: Fri, 11 Oct 2024 11:27:44 +0200 Subject: [PATCH 4/7] add zabbix_agent_win_controlsocket and zabbix_agent_win_pluginsocket --- docs/ZABBIX_AGENT_ROLE.md | 2 ++ roles/zabbix_agent/tasks/Windows_conf.yml | 11 +++-------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/docs/ZABBIX_AGENT_ROLE.md b/docs/ZABBIX_AGENT_ROLE.md index 59bc582b3..4c9d20b49 100644 --- a/docs/ZABBIX_AGENT_ROLE.md +++ b/docs/ZABBIX_AGENT_ROLE.md @@ -222,6 +222,8 @@ Otherwise it just for the Zabbix Agent or for the Zabbix Agent 2. * `zabbix_agent_win_include`: The directory in which the Zabbix Agent specific configuration files are stored. * `zabbix_agent_win_logfile`: The full path to the logfile for the Zabbix Agent. +* `zabbix_agent_win_controlsocket`: Windows specific value for `zabbix_agent_controlsocket`. Default: `\\.\pipe\agent.sock` +* `zabbix_agent_win_pluginsocket`: Windows specific value for `zabbix_agent_pluginsocket`. Default: `\\.\pipe\agent.plugin.sock` * `zabbix_version_long`: The long (major.minor.patch) version of the Zabbix Agent. This will be used to generate the `zabbix_win_package` and `zabbix_win_download_link` variables. This takes precedence over `zabbix_agent_version`. * `zabbix_win_download_link`: The download url to the `win.zip` file. * `zabbix_win_firewall_management`: Enable Windows firewall management (add service and port to allow rules). Default: `True` diff --git a/roles/zabbix_agent/tasks/Windows_conf.yml b/roles/zabbix_agent/tasks/Windows_conf.yml index b3eaf2f0e..0b4b65493 100644 --- a/roles/zabbix_agent/tasks/Windows_conf.yml +++ b/roles/zabbix_agent/tasks/Windows_conf.yml @@ -1,15 +1,10 @@ --- -- name: "Set Log File Info" +- name: "Set Windows specific configuration facts" ansible.builtin.set_fact: zabbix_agent_logfile: "{{ zabbix_agent_win_logfile is defined | ternary(zabbix_agent_win_logfile, zabbix_agent2_win_logfile) | default(_win_logfile) }}" - -- name: "Set Include Path Info" - ansible.builtin.set_fact: zabbix_agent_include_dir: "{{ zabbix_agent_win_include is defined | ternary(zabbix_agent_win_include, zabbix_agent2_win_include) | default(_win_include) }}" - -- name: "Set Control Socket" - ansible.builtin.set_fact: - zabbix_agent_controlsocket: "\\\\.\\pipe\\agent.sock" + zabbix_agent_controlsocket: "{{ zabbix_agent_win_controlsocket | default('\\\\.\\pipe\\agent.sock') }}" + zabbix_agent_pluginsocket: "{{ zabbix_agent_win_pluginsocket | default('\\\\.\\pipe\\agent.plugin.sock') }}" - name: "Set default ip address for zabbix_agent_ip" ansible.builtin.set_fact: From d0d54cb1d8e33e16449b98fcf99428a23c00d96d Mon Sep 17 00:00:00 2001 From: Martin Eiswirth Date: Fri, 11 Oct 2024 11:31:09 +0200 Subject: [PATCH 5/7] move zabbix_agent_win_controlsocket and zabbix_agent_win_pluginsocket defaults --- roles/zabbix_agent/defaults/main.yml | 2 ++ roles/zabbix_agent/tasks/Windows_conf.yml | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/roles/zabbix_agent/defaults/main.yml b/roles/zabbix_agent/defaults/main.yml index 6890199e3..fc4cb2f54 100644 --- a/roles/zabbix_agent/defaults/main.yml +++ b/roles/zabbix_agent/defaults/main.yml @@ -116,6 +116,8 @@ zabbix_win_install_dir_conf: '{{ zabbix_win_install_dir }}\conf' zabbix_win_install_dir_bin: '{{ zabbix_win_install_dir }}\bin' zabbix_win_firewall_management: true zabbix_win_config_remove: true +zabbix_agent_win_controlsocket: '\\.\pipe\agent.sock' +zabbix_agent_win_pluginsocket: '\\.\pipe\agent.plugin.sock' # macOS Related zabbix_mac_package: zabbix_agent-{{ zabbix_version_long }}-macos-amd64-openssl.pkg diff --git a/roles/zabbix_agent/tasks/Windows_conf.yml b/roles/zabbix_agent/tasks/Windows_conf.yml index 0b4b65493..11d043e68 100644 --- a/roles/zabbix_agent/tasks/Windows_conf.yml +++ b/roles/zabbix_agent/tasks/Windows_conf.yml @@ -3,8 +3,8 @@ ansible.builtin.set_fact: zabbix_agent_logfile: "{{ zabbix_agent_win_logfile is defined | ternary(zabbix_agent_win_logfile, zabbix_agent2_win_logfile) | default(_win_logfile) }}" zabbix_agent_include_dir: "{{ zabbix_agent_win_include is defined | ternary(zabbix_agent_win_include, zabbix_agent2_win_include) | default(_win_include) }}" - zabbix_agent_controlsocket: "{{ zabbix_agent_win_controlsocket | default('\\\\.\\pipe\\agent.sock') }}" - zabbix_agent_pluginsocket: "{{ zabbix_agent_win_pluginsocket | default('\\\\.\\pipe\\agent.plugin.sock') }}" + zabbix_agent_controlsocket: "{{ zabbix_agent_win_controlsocket }}" + zabbix_agent_pluginsocket: "{{ zabbix_agent_win_pluginsocket }}" - name: "Set default ip address for zabbix_agent_ip" ansible.builtin.set_fact: From 4d22ea657d487aec3d49853054f0207509d217af Mon Sep 17 00:00:00 2001 From: Martin Eiswirth Date: Fri, 11 Oct 2024 11:42:56 +0200 Subject: [PATCH 6/7] cleanup loops and add labels --- roles/zabbix_agent/tasks/Windows.yml | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/roles/zabbix_agent/tasks/Windows.yml b/roles/zabbix_agent/tasks/Windows.yml index bd96d5e62..99852d074 100644 --- a/roles/zabbix_agent/tasks/Windows.yml +++ b/roles/zabbix_agent/tasks/Windows.yml @@ -20,7 +20,7 @@ - name: "Windows | Check if Zabbix agent is present" ansible.windows.win_stat: path: "{{ item }}" - with_items: + loop: - "{{ zabbix_win_exe_path }}" - "{{ zabbix2_win_exe_path }}" register: agent_file_info @@ -33,7 +33,9 @@ register: zabbix_win_exe_info when: - item.stat.exists | bool - with_items: "{{ agent_file_info.results }}" + loop: "{{ agent_file_info.results }}" + loop_control: + label: "{{ item.item }}" tags: - always @@ -66,7 +68,9 @@ name: "{{ (item.item.stat.path == zabbix_win_exe_path) | ternary(zabbix_win_svc_name, zabbix2_win_svc_name) }}" register: zabbix_service_info when: item.item.stat.exists - with_items: "{{ zabbix_win_exe_info.results }}" + loop: "{{ zabbix_win_exe_info.results }}" + loop_control: + label: "{{ item.item.item }}" tags: - always @@ -187,7 +191,7 @@ ansible.windows.win_file: path: "{{ item }}" state: directory - with_items: + loop: - "{{ zabbix_win_install_dir }}" - "{{ zabbix_win_install_dir_conf }}" - "{{ zabbix_win_install_dir_bin }}" @@ -198,10 +202,8 @@ - name: "Windows | Create directory structure, includes" ansible.windows.win_file: - path: "{{ item }}" + path: "{{ zabbix_agent_win_include }}" state: directory - with_items: - - "{{ zabbix_agent_win_include }}" when: - ('.conf' not in zabbix_agent_win_include) tags: From 6afdd5fe7ced134e8c2eb292cda4fa183d15c60d Mon Sep 17 00:00:00 2001 From: Martin Eiswirth Date: Fri, 11 Oct 2024 14:08:37 +0200 Subject: [PATCH 7/7] copy all content of setup folders --- roles/zabbix_agent/tasks/Windows.yml | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/roles/zabbix_agent/tasks/Windows.yml b/roles/zabbix_agent/tasks/Windows.yml index 99852d074..447058bbe 100644 --- a/roles/zabbix_agent/tasks/Windows.yml +++ b/roles/zabbix_agent/tasks/Windows.yml @@ -250,13 +250,9 @@ - name: "Windows | Copy binary files to expected location" ansible.windows.win_copy: - src: "{{ zabbix_win_install_dir_setup }}\\bin\\{{ item }}" - dest: "{{ zabbix_win_install_dir_bin }}\\{{ item }}" + src: "{{ zabbix_win_install_dir_setup }}\\bin\\" + dest: "{{ zabbix_win_install_dir_bin }}\\" remote_src: true - loop: - - "{{ zabbix_win_exe_name }}" - - zabbix_sender.exe - - zabbix_get.exe when: - zabbix_agent_version_change | default(false) or not zabbix_windows_binaries.stat.exists - zabbix_agent_win_download_zip is changed or file_info.stat.exists @@ -265,8 +261,8 @@ - name: "Windows | Copy initial configuration to expected location" ansible.windows.win_copy: - src: "{{ zabbix_win_install_dir_setup }}\\conf\\{{ zabbix_win_config_name }}" - dest: "{{ zabbix_win_install_dir_conf }}\\{{ zabbix_win_config_name }}" + src: "{{ zabbix_win_install_dir_setup }}\\conf\\" + dest: "{{ zabbix_win_install_dir_conf }}\\" force: false remote_src: true when: