|
4 | 4 |
|
5 | 5 | - name: Populate service facts |
6 | 6 | service_facts: |
| 7 | + when: __timesync_is_booted | d(false) |
7 | 8 |
|
8 | 9 | - name: Set variable `timesync_services` with filtered uniq service names |
9 | 10 | set_fact: |
|
18 | 19 | map('regex_replace', '@$', '') | |
19 | 20 | unique | |
20 | 21 | list }}" |
| 22 | + when: __timesync_is_booted | d(false) |
| 23 | + |
| 24 | +- name: Populate service facts when in bootc mode |
| 25 | + command: systemctl list-unit-files --type=service -l # noqa command-instead-of-module |
| 26 | + register: timesync_services_output |
| 27 | + changed_when: false |
| 28 | + when: not __timesync_is_booted | d(false) |
| 29 | + |
| 30 | +- name: Set variable `timesync_services` with filtered uniq service names when in bootc mode |
| 31 | + set_fact: |
| 32 | + timesync_services: "{{ timesync_services_output.stdout_lines | |
| 33 | + select('search', ' enabled$') | |
| 34 | + map('regex_replace', ' +enabled$', '') | |
| 35 | + map('regex_replace', '[.]service.*$', '') | |
| 36 | + map('regex_replace', '@$', '') | |
| 37 | + unique | |
| 38 | + list }}" |
| 39 | + when: not __timesync_is_booted | d(false) |
21 | 40 |
|
22 | 41 | - name: Check that variable 'timesync_services' is defined |
23 | 42 | assert: |
|
250 | 269 | - name: Disable chronyd |
251 | 270 | service: |
252 | 271 | name: chronyd |
253 | | - state: stopped |
| 272 | + state: "{{ 'stopped' if __timesync_is_booted else omit }}" |
254 | 273 | enabled: false |
255 | 274 | when: |
256 | 275 | - timesync_mode != 1 or timesync_ntp_provider != 'chrony' |
|
264 | 283 | - name: Disable ntpd |
265 | 284 | service: |
266 | 285 | name: ntpd |
267 | | - state: stopped |
| 286 | + state: "{{ 'stopped' if __timesync_is_booted else omit }}" |
268 | 287 | enabled: false |
269 | 288 | when: |
270 | 289 | - timesync_mode != 1 or timesync_ntp_provider != 'ntp' |
|
278 | 297 | - name: Disable ntpdate |
279 | 298 | service: |
280 | 299 | name: ntpdate |
281 | | - state: stopped |
| 300 | + state: "{{ 'stopped' if __timesync_is_booted else omit }}" |
282 | 301 | enabled: false |
283 | 302 | when: "'ntpdate' in timesync_services" |
284 | 303 | register: __disable_result |
|
290 | 309 | - name: Disable sntp |
291 | 310 | service: |
292 | 311 | name: sntp |
293 | | - state: stopped |
| 312 | + state: "{{ 'stopped' if __timesync_is_booted else omit }}" |
294 | 313 | enabled: false |
295 | 314 | when: "'sntp' in timesync_services" |
296 | 315 | register: __disable_result |
|
302 | 321 | - name: Disable ptp4l |
303 | 322 | service: |
304 | 323 | name: ptp4l |
305 | | - state: stopped |
| 324 | + state: "{{ 'stopped' if __timesync_is_booted else omit }}" |
306 | 325 | enabled: false |
307 | 326 | when: |
308 | 327 | - timesync_mode != 2 |
|
316 | 335 | - name: Disable phc2sys |
317 | 336 | service: |
318 | 337 | name: phc2sys |
319 | | - state: stopped |
| 338 | + state: "{{ 'stopped' if __timesync_is_booted else omit }}" |
320 | 339 | enabled: false |
321 | 340 | when: |
322 | 341 | - timesync_mode != 2 or not timesync_mode2_hwts |
|
334 | 353 | __timemstr: timemaster |
335 | 354 | service: |
336 | 355 | name: "{{ __timemstr }}" |
337 | | - state: stopped |
| 356 | + state: "{{ 'stopped' if __timesync_is_booted else omit }}" |
338 | 357 | enabled: false |
339 | 358 | when: |
340 | 359 | - timesync_mode != 3 |
|
348 | 367 | - name: Enable chronyd |
349 | 368 | service: |
350 | 369 | name: chronyd |
351 | | - state: started |
| 370 | + state: "{{ 'started' if __timesync_is_booted else omit }}" |
352 | 371 | enabled: true |
353 | 372 | when: |
354 | 373 | - timesync_mode == 1 |
|
357 | 376 | - name: Enable ntpd |
358 | 377 | service: |
359 | 378 | name: ntpd |
360 | | - state: started |
| 379 | + state: "{{ 'started' if __timesync_is_booted else omit }}" |
361 | 380 | enabled: true |
362 | 381 | when: |
363 | 382 | - timesync_mode == 1 |
|
366 | 385 | - name: Enable ptp4l |
367 | 386 | service: |
368 | 387 | name: ptp4l |
369 | | - state: started |
| 388 | + state: "{{ 'started' if __timesync_is_booted else omit }}" |
370 | 389 | enabled: true |
371 | 390 | when: timesync_mode == 2 |
372 | 391 |
|
373 | 392 | - name: Enable phc2sys |
374 | 393 | service: |
375 | 394 | name: phc2sys |
376 | | - state: started |
| 395 | + state: "{{ 'started' if __timesync_is_booted else omit }}" |
377 | 396 | enabled: true |
378 | 397 | when: |
379 | 398 | - timesync_mode == 2 |
|
384 | 403 | service: |
385 | 404 | # wokeignore:rule=master |
386 | 405 | name: timemaster |
387 | | - state: started |
| 406 | + state: "{{ 'started' if __timesync_is_booted else omit }}" |
388 | 407 | enabled: true |
389 | 408 | when: timesync_mode == 3 |
0 commit comments