-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathLinux.yml
More file actions
287 lines (265 loc) · 11.6 KB
/
Copy pathLinux.yml
File metadata and controls
287 lines (265 loc) · 11.6 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
---
- name: "{{ ansible_facts['system'] }}: Get RPM or APT package facts."
ansible.builtin.package_facts:
manager: "auto"
tags:
- get-package-facts
- name: "{{ ansible_facts['system'] }}: Populate service facts."
ansible.builtin.service_facts:
tags:
- configure-firewall
- name: "{{ ansible_facts['system'] }}: Prepare legacy agent support."
when: |
checkmk_agent_prep_legacy | bool
and ansible_facts['packages']['systemd'][0]['version'] | regex_search('\d{1,}') | int < 220
block:
- name: "{{ ansible_facts['system'] }}: Install xinetd."
become: true
ansible.builtin.package:
name: xinetd
state: present
tags:
- install-package
- install-prerequisites
- name: "{{ ansible_facts['system'] }}: Enable xinetd."
become: true
ansible.builtin.service:
name: xinetd
state: started
enabled: true
tags:
- enable-xinetd
- name: "{{ ansible_facts['os_family'] }}: Run OS Family specific tasks."
ansible.builtin.include_tasks: "{{ ansible_facts['os_family'] }}.yml"
tags:
- always
- name: "{{ ansible_facts['system'] }}: Ensure Host Folder is present."
checkmk.general.folder:
server_url: "{{ checkmk_agent_server_protocol }}://{{ checkmk_agent_server }}:{{ checkmk_agent_server_port }}/"
site: "{{ checkmk_agent_site }}"
validate_certs: "{{ checkmk_agent_server_validate_certs | bool }}"
api_user: "{{ checkmk_agent_user }}"
api_secret: "{{ __checkmk_agent_auth }}"
path: "{{ checkmk_agent_folder }}"
state: "present"
become: false
delegate_to: "{{ checkmk_agent_delegate_api_calls }}"
when: checkmk_agent_folder_create | bool and checkmk_agent_add_host | bool
notify: "Activate changes"
tags:
- manage-host
- name: "{{ ansible_facts['system'] }}: Ensure Host is present in the correct Folder."
checkmk.general.host:
server_url: "{{ checkmk_agent_server_protocol }}://{{ checkmk_agent_server }}:{{ checkmk_agent_server_port }}/"
site: "{{ checkmk_agent_site }}"
validate_certs: "{{ checkmk_agent_server_validate_certs | bool }}"
api_user: "{{ checkmk_agent_user }}"
api_secret: "{{ __checkmk_agent_auth }}"
folder: "{{ checkmk_agent_folder }}"
name: "{{ checkmk_agent_host_name }}"
state: "present"
become: false
register: __checkmk_agent_create_result
delegate_to: "{{ checkmk_agent_delegate_api_calls }}"
when: checkmk_agent_add_host | bool
notify: "Activate changes"
tags:
- manage-host
- name: "{{ ansible_facts['system'] }}: Update Host Attributes."
checkmk.general.host:
server_url: "{{ checkmk_agent_server_protocol }}://{{ checkmk_agent_server }}:{{ checkmk_agent_server_port }}/"
site: "{{ checkmk_agent_site }}"
validate_certs: "{{ checkmk_agent_server_validate_certs | bool }}"
api_user: "{{ checkmk_agent_user }}"
api_secret: "{{ __checkmk_agent_auth }}"
name: "{{ checkmk_agent_host_name }}"
attributes: "{{ checkmk_agent_host_attributes }}"
state: "present"
become: false
register: __checkmk_agent_update_attributes_result
delegate_to: "{{ checkmk_agent_delegate_api_calls }}"
when: checkmk_agent_add_host | bool
notify: "Activate changes"
tags:
- manage-host
- name: "Ensure registration readiness." # noqa no-handler
tags:
- always
block:
- name: "Trigger activation of changes."
ansible.builtin.meta: flush_handlers
- name: "{{ ansible_facts['system'] }}: Check for Agent Updater Binary."
ansible.builtin.stat:
path: /usr/bin/cmk-update-agent
register: __checkmk_agent_updater_binary
tags:
- register-agent
- name: "{{ ansible_facts['system'] }}: Check for Agent Controller Binary."
ansible.builtin.stat:
path: /usr/bin/cmk-agent-ctl
register: __checkmk_agent_controller_binary
tags:
- register-agent
- name: "{{ ansible_facts['system'] }}: Read Updater State."
become: true
ansible.builtin.command: cat /var/lib/check_mk_agent/cache/plugins_cmk-update-agent.cache
register: __checkmk_agent_updater_state
changed_when: false
failed_when: |
not __checkmk_agent_updater_state.rc == 0
and not __checkmk_agent_updater_state.rc == 1
tags:
- register-agent
- name: "{{ ansible_facts['system'] }}: Read Agent Controller State."
become: true
ansible.builtin.command: cat /var/lib/cmk-agent/registered_connections.json
register: __checkmk_agent_registered_connections
changed_when: false
failed_when: |
not __checkmk_agent_registered_connections.rc == 0
and not __checkmk_agent_registered_connections.rc == 1
tags:
- register-agent
- name: "{{ ansible_facts['system'] }}: Register Agent for automatic Updates using User Password."
become: true
ansible.builtin.shell: |
cmk-update-agent register -H {{ checkmk_agent_host_name }} \
-s {{ checkmk_agent_registration_server }} -i {{ checkmk_agent_registration_site }} -p {{ checkmk_agent_registration_server_protocol }} \
-U {{ checkmk_agent_user }} -P {{ __checkmk_agent_auth | ansible.builtin.quote }}
no_log: "{{ checkmk_agent_no_log | bool }}"
register: __checkmk_agent_update_state
when: |
checkmk_agent_edition | lower != "community"
and __checkmk_agent_updater_binary.stat.exists | bool
and checkmk_agent_update | bool
and (checkmk_agent_pass is defined and checkmk_agent_pass | length > 0)
and (checkmk_agent_secret is not defined)
and not ((checkmk_agent_registration_server + '/' + checkmk_agent_registration_site in __checkmk_agent_updater_state.stdout)
and ('"error": null' in __checkmk_agent_updater_state.stdout) )
changed_when: "'Successfully registered agent of host' in __checkmk_agent_update_state.stderr"
tags:
- register-agent
- name: "{{ ansible_facts['system'] }}: Register Agent for automatic Updates using Automation Secret."
become: true
ansible.builtin.shell: |
cmk-update-agent register -H {{ checkmk_agent_host_name }} \
-s {{ checkmk_agent_registration_server }} -i {{ checkmk_agent_registration_site }} -p {{ checkmk_agent_registration_server_protocol }} \
-U {{ checkmk_agent_user }} -S {{ __checkmk_agent_auth | ansible.builtin.quote }}
no_log: "{{ checkmk_agent_no_log | bool }}"
register: __checkmk_agent_update_state
when: |
checkmk_agent_edition | lower != "community"
and __checkmk_agent_updater_binary.stat.exists | bool
and checkmk_agent_update | bool
and (checkmk_agent_secret is defined and checkmk_agent_secret | length > 0)
and not ((checkmk_agent_registration_server + '/' + checkmk_agent_registration_site in __checkmk_agent_updater_state.stdout)
and ('"error": null' in __checkmk_agent_updater_state.stdout) )
changed_when: "'Successfully registered agent of host' in __checkmk_agent_update_state.stderr"
tags:
- register-agent
- name: "{{ ansible_facts['system'] }}: Register Agent for TLS directly."
become: true
ansible.builtin.shell: |
cmk-agent-ctl register -H {{ checkmk_agent_host_name }} \
-s {{ checkmk_agent_registration_server }} -i {{ checkmk_agent_registration_site }} \
-U {{ checkmk_agent_user }} -P {{ __checkmk_agent_auth | ansible.builtin.quote }} --trust-cert
no_log: "{{ checkmk_agent_no_log | bool }}"
register: __checkmk_agent_tls_state
when: |
__checkmk_agent_controller_binary.stat.exists | bool
and checkmk_agent_tls | bool
and not checkmk_agent_delegate_registration | bool
and (__checkmk_agent_auth is defined and __checkmk_agent_auth | length > 0)
and not checkmk_agent_registration_server + '/' + checkmk_agent_registration_site in __checkmk_agent_registered_connections.stdout
changed_when: "'Registration complete' in __checkmk_agent_tls_state.stdout"
tags:
- register-agent
- name: "{{ ansible_facts['system'] }}: Register Agent for TLS with proxy-register."
become: true
ansible.builtin.shell: |
cmk-agent-ctl proxy-register -H {{ checkmk_agent_host_name }} \
-s {{ checkmk_agent_registration_server }} -i {{ checkmk_agent_registration_site }} \
-U {{ checkmk_agent_user }} -P {{ __checkmk_agent_auth | ansible.builtin.quote }} --trust-cert
no_log: "{{ checkmk_agent_no_log | bool }}"
register: __checkmk_agent_proxy_registration_state
when: |
__checkmk_agent_controller_binary.stat.exists | bool
and checkmk_agent_tls | bool
and checkmk_agent_delegate_registration | bool
and (__checkmk_agent_auth is defined and __checkmk_agent_auth | length > 0)
and not checkmk_agent_registration_server + '/' + checkmk_agent_registration_site in __checkmk_agent_registered_connections.stdout
delegate_to: "{{ checkmk_agent_delegate_registration_target }}"
changed_when: "'-----BEGIN PRIVATE KEY-----' in __checkmk_agent_proxy_registration_state.stdout"
tags:
- register-agent
- name: "{{ ansible_facts['system'] }}: Create temporary proxy-register file."
become: true
ansible.builtin.copy:
dest: "{{ __checkmk_agent_host_tmp_dir }}/checkmk-import"
mode: u=r,g=,o=
owner: cmk-agent
group: cmk-agent
content: "{{ __checkmk_agent_proxy_registration_state.stdout }}"
no_log: "{{ checkmk_agent_no_log | bool }}"
when: |
__checkmk_agent_controller_binary.stat.exists | bool
and checkmk_agent_tls | bool
and checkmk_agent_delegate_registration | bool
and (__checkmk_agent_auth is defined and __checkmk_agent_auth | length > 0)
and not checkmk_agent_registration_server + '/' + checkmk_agent_registration_site in __checkmk_agent_registered_connections.stdout
and __checkmk_agent_proxy_registration_state is defined
tags:
- register-agent
- name: "{{ ansible_facts['system'] }}: Import proxy-register file."
become: true
ansible.builtin.command: "cmk-agent-ctl import {{ __checkmk_agent_host_tmp_dir }}/checkmk-import"
no_log: "{{ checkmk_agent_no_log | bool }}"
register: __checkmk_agent_import_result
when: |
__checkmk_agent_controller_binary.stat.exists | bool
and checkmk_agent_tls | bool
and checkmk_agent_delegate_registration | bool
and (__checkmk_agent_auth is defined and __checkmk_agent_auth | length > 0)
and not checkmk_agent_registration_server + '/' + checkmk_agent_registration_site in __checkmk_agent_registered_connections.stdout
and __checkmk_agent_proxy_registration_state is defined
changed_when: __checkmk_agent_import_result.rc == 0
tags:
- register-agent
- name: "{{ ansible_facts['system'] }}: Clean-up proxy-register temporary file."
become: true
ansible.builtin.file:
path: "{{ __checkmk_agent_host_tmp_dir }}/checkmk-import"
state: absent
no_log: "{{ checkmk_agent_no_log | bool }}"
when: |
__checkmk_agent_controller_binary.stat.exists | bool
and checkmk_agent_tls | bool
and checkmk_agent_delegate_registration | bool
and (__checkmk_agent_auth is defined and __checkmk_agent_auth | length > 0)
and not checkmk_agent_registration_server + '/' + checkmk_agent_registration_site in __checkmk_agent_registered_connections.stdout
and __checkmk_agent_proxy_registration_state is defined
tags:
- register-agent
- name: "{{ ansible_facts['system'] }}: Verify Checkmk Agent Port is open."
ansible.builtin.wait_for:
port: "{{ checkmk_agent_port }}"
timeout: 60
when: checkmk_agent_mode == 'pull'
tags:
- register-agent
- name: "{{ ansible_facts['system'] }}: Initial push of data for push agent." # noqa no-changed-when
become: true
ansible.builtin.command: cmk-agent-ctl push
when: checkmk_agent_mode == 'push'
tags:
- register-agent
- name: "{{ ansible_facts['system'] }}: Cleanup Checkmk Agent Setups."
ansible.builtin.file:
path: "{{ item }}"
state: absent
loop:
- "{{ __checkmk_agent_agent.file.upload.community }}"
- "{{ __checkmk_agent_agent.file.upload.pro }}"
- "{{ __checkmk_agent_agent.file.upload.host }}"
tags:
- download-package