Skip to content

Commit f730d40

Browse files
committed
feat: support this role in container builds
Feature: Support running the timesync role during container builds. Reason: This is particularly useful for building bootc derivative OSes. Result: These flags enable running the bootc container scenarios in CI, which ensures that the role works in buildah build environment. This allows us to officially support this role for image mode builds. Signed-off-by: Rich Megginson <rmeggins@redhat.com>
1 parent 7db4750 commit f730d40

File tree

5 files changed

+71
-12
lines changed

5 files changed

+71
-12
lines changed

handlers/main.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,30 @@
33
service:
44
name: chronyd
55
state: restarted
6+
when: __timesync_is_booted | d(false)
67

78
- name: Restart ntpd
89
service:
910
name: ntpd
1011
state: restarted
12+
when: __timesync_is_booted | d(false)
1113

1214
- name: Restart ptp4l
1315
service:
1416
name: ptp4l
1517
state: restarted
18+
when: __timesync_is_booted | d(false)
1619

1720
- name: Restart phc2sys
1821
service:
1922
name: phc2sys
2023
state: restarted
24+
when: __timesync_is_booted | d(false)
2125

2226
# wokeignore:rule=master
2327
- name: Restart timemaster
2428
service:
2529
# wokeignore:rule=master
2630
name: timemaster
2731
state: restarted
32+
when: __timesync_is_booted | d(false)

meta/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ galaxy_info:
1818
galaxy_tags:
1919
- centos
2020
- chrony
21+
- containerbuild
2122
- el6
2223
- el7
2324
- el8

tasks/main.yml

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- name: Populate service facts
66
service_facts:
7+
when: __timesync_is_booted | d(false)
78

89
- name: Set variable `timesync_services` with filtered uniq service names
910
set_fact:
@@ -18,6 +19,24 @@
1819
map('regex_replace', '@$', '') |
1920
unique |
2021
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)
2140

2241
- name: Check that variable 'timesync_services' is defined
2342
assert:
@@ -250,7 +269,7 @@
250269
- name: Disable chronyd
251270
service:
252271
name: chronyd
253-
state: stopped
272+
state: "{{ 'stopped' if __timesync_is_booted else omit }}"
254273
enabled: false
255274
when:
256275
- timesync_mode != 1 or timesync_ntp_provider != 'chrony'
@@ -264,7 +283,7 @@
264283
- name: Disable ntpd
265284
service:
266285
name: ntpd
267-
state: stopped
286+
state: "{{ 'stopped' if __timesync_is_booted else omit }}"
268287
enabled: false
269288
when:
270289
- timesync_mode != 1 or timesync_ntp_provider != 'ntp'
@@ -278,7 +297,7 @@
278297
- name: Disable ntpdate
279298
service:
280299
name: ntpdate
281-
state: stopped
300+
state: "{{ 'stopped' if __timesync_is_booted else omit }}"
282301
enabled: false
283302
when: "'ntpdate' in timesync_services"
284303
register: __disable_result
@@ -290,7 +309,7 @@
290309
- name: Disable sntp
291310
service:
292311
name: sntp
293-
state: stopped
312+
state: "{{ 'stopped' if __timesync_is_booted else omit }}"
294313
enabled: false
295314
when: "'sntp' in timesync_services"
296315
register: __disable_result
@@ -302,7 +321,7 @@
302321
- name: Disable ptp4l
303322
service:
304323
name: ptp4l
305-
state: stopped
324+
state: "{{ 'stopped' if __timesync_is_booted else omit }}"
306325
enabled: false
307326
when:
308327
- timesync_mode != 2
@@ -316,7 +335,7 @@
316335
- name: Disable phc2sys
317336
service:
318337
name: phc2sys
319-
state: stopped
338+
state: "{{ 'stopped' if __timesync_is_booted else omit }}"
320339
enabled: false
321340
when:
322341
- timesync_mode != 2 or not timesync_mode2_hwts
@@ -334,7 +353,7 @@
334353
__timemstr: timemaster
335354
service:
336355
name: "{{ __timemstr }}"
337-
state: stopped
356+
state: "{{ 'stopped' if __timesync_is_booted else omit }}"
338357
enabled: false
339358
when:
340359
- timesync_mode != 3
@@ -348,7 +367,7 @@
348367
- name: Enable chronyd
349368
service:
350369
name: chronyd
351-
state: started
370+
state: "{{ 'started' if __timesync_is_booted else omit }}"
352371
enabled: true
353372
when:
354373
- timesync_mode == 1
@@ -357,7 +376,7 @@
357376
- name: Enable ntpd
358377
service:
359378
name: ntpd
360-
state: started
379+
state: "{{ 'started' if __timesync_is_booted else omit }}"
361380
enabled: true
362381
when:
363382
- timesync_mode == 1
@@ -366,14 +385,14 @@
366385
- name: Enable ptp4l
367386
service:
368387
name: ptp4l
369-
state: started
388+
state: "{{ 'started' if __timesync_is_booted else omit }}"
370389
enabled: true
371390
when: timesync_mode == 2
372391

373392
- name: Enable phc2sys
374393
service:
375394
name: phc2sys
376-
state: started
395+
state: "{{ 'started' if __timesync_is_booted else omit }}"
377396
enabled: true
378397
when:
379398
- timesync_mode == 2
@@ -384,6 +403,6 @@
384403
service:
385404
# wokeignore:rule=master
386405
name: timemaster
387-
state: started
406+
state: "{{ 'started' if __timesync_is_booted else omit }}"
388407
enabled: true
389408
when: timesync_mode == 3

tasks/set_vars.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,23 @@
4343
- "default.yml"
4444
paths:
4545
- "{{ role_path }}/vars"
46+
47+
- name: Determine if system is booted with systemd
48+
when: __timesync_is_booted is not defined
49+
block:
50+
- name: Run systemctl
51+
# noqa command-instead-of-module
52+
command: systemctl is-system-running
53+
register: __is_system_running
54+
changed_when: false
55+
failed_when: false
56+
57+
- name: Require installed systemd
58+
fail:
59+
msg: "Error: This role requires systemd to be installed."
60+
when: '"No such file or directory" in __is_system_running.msg | d("")'
61+
62+
- name: Set flag to indicate that systemd runtime operations are available
63+
set_fact:
64+
# see https://www.man7.org/linux/man-pages/man1/systemctl.1.html#:~:text=is-system-running%20output
65+
__timesync_is_booted: "{{ __is_system_running.stdout != 'offline' }}"

tests/tests_chrony.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@
2525
include_role:
2626
name: linux-system-roles.timesync
2727
public: true
28+
when: not __bootc_validation | d(false)
29+
30+
- name: Run the role only to get vars needed for validation
31+
include_role:
32+
name: linux-system-roles.timesync
33+
public: true
34+
tasks_from: set_vars.yml
35+
when: __bootc_validation | d(false)
2836

2937
- name: Run chrony tests
3038
tags: tests::verify
@@ -36,6 +44,12 @@
3644
wait_for:
3745
timeout: 2
3846

47+
- name: Create QEMU deployment during bootc end-to-end test
48+
delegate_to: localhost
49+
command: bash -x {{ lsr_scriptdir | quote }}/bootc-buildah-qcow.sh {{ ansible_host | quote }}
50+
changed_when: true
51+
when: ansible_connection == "buildah"
52+
3953
- name: Get list of currently used time sources
4054
shell: chronyc -n sources || ntpq -pn
4155
register: sources

0 commit comments

Comments
 (0)