-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpb-uninstall-win-agent.yaml
86 lines (75 loc) · 3.31 KB
/
pb-uninstall-win-agent.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
- hosts: uninstall_win_agent
become_method: runas
tasks:
- name: "Windows | Set install dir"
set_fact:
zabbix_win_install_dir: 'C:\Zabbix'
- name: "Windows | Set variables specific to Zabbix"
set_fact:
zabbix_win_svc_name: Zabbix Agent
zabbix_win_install_dir_conf: '{{ zabbix_win_install_dir }}\\conf'
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_config_name: 'zabbix_agent2.conf'
- name: "Windows | Check if Zabbix agent is present"
ansible.windows.win_stat:
path: '{{ item }}'
with_items:
- "{{ zabbix_win_exe_path }}"
- "{{ zabbix2_win_exe_path }}"
register: agent_file_info
- name: "Windows | Get Installed Zabbix Agent Version"
community.windows.win_file_version:
path: "{{ item.item }}"
register: zabbix_win_exe_info
when:
- item.stat.exists | bool
with_items: "{{ agent_file_info.results }}"
- 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) }}"
register: zabbix_service_info
when: item.item.stat.exists
with_items: "{{ zabbix_win_exe_info.results }}"
- name: "Windows | Set facts about current zabbix agent service state"
set_fact:
zabbix_agent_1_service_exist: true
when:
- zabbix_service_info.results[0].exists is defined
- zabbix_service_info.results[0].exists
- zabbix_service_info.results[0].display_name == zabbix_win_svc_name
- name: "Windows | Set facts about current zabbix agent service state (agent 2)"
set_fact:
zabbix_agent_2_service_exist: true
when:
- zabbix_service_info.results[1].exists is defined
- zabbix_service_info.results[1].exists
- zabbix_service_info.results[1].display_name == zabbix2_win_svc_name
- name: "Windows | Stop Zabbix agent v1"
ansible.windows.win_service:
name: "{{ zabbix_win_svc_name }}"
start_mode: auto
state: stopped
when:
- zabbix_agent_1_service_exist | default(false)
- name: "Windows | Stop Zabbix agent v2"
ansible.windows.win_service:
name: "{{ zabbix2_win_svc_name }}"
start_mode: auto
state: stopped
when:
- zabbix_agent_2_service_exist | default(false)
- name: "Windows | Uninstall Zabbix agent v1"
ansible.windows.win_command: '"{{ zabbix_win_exe_path }}" --config "{{ zabbix_win_install_dir_conf }}\{{ zabbix_win_config_name }}" --uninstall'
when:
- zabbix_agent_1_service_exist | default(false)
- name: "Windows | Uninstall Zabbix agent v2"
ansible.windows.win_command: '"{{ zabbix2_win_exe_path }}" --config "{{ zabbix_win_install_dir_conf }}\{{ zabbix2_win_config_name }}" --uninstall'
when:
- zabbix_agent_2_service_exist | default(false)
- name: "Windows | Removing Zabbix Directory"
ansible.windows.win_file:
path: '{{ zabbix_win_install_dir }}'
state: absent