Skip to content

Commit a4d6e51

Browse files
committed
feat: Support this role in container builds
Feature: Support running the cockpit role during container builds. Reason: This is particularly useful for building bootc derivative OSes. Result: The role now works during container builds. The bootc container scenarios run in CI, which ensures that the role works in buildah build environment. This allows us to officially support this role for image mode builds. Detect if the system is booted (with systemd), and skip all runtime operations and checks if not. Also use `firewall-offline-cmd` which works also in non-booted environments -- we are only/primarily interested in the persistent firewall config anyway. Make tests_verify_fullstack.yml a full bootc end-to-end test, as that covers the most code paths. https://issues.redhat.com/browse/RHEL-98911
1 parent a2207ff commit a4d6e51

23 files changed

+94
-27
lines changed

meta/main.yml

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

tasks/main.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,26 @@
66
when: __metrics_required_facts |
77
difference(ansible_facts.keys() | list) | length > 0
88

9+
- name: Determine if system is booted with systemd
10+
when: __metrics_is_booted is not defined
11+
block:
12+
- name: Run systemctl
13+
# noqa command-instead-of-module
14+
command: systemctl is-system-running
15+
register: __is_system_running
16+
changed_when: false
17+
failed_when: false
18+
19+
- name: Require installed systemd
20+
fail:
21+
msg: "Error: This role requires systemd to be installed."
22+
when: '"No such file or directory" in __is_system_running.msg | d("")'
23+
24+
- name: Set flag to indicate that systemd runtime operations are available
25+
set_fact:
26+
# see https://www.man7.org/linux/man-pages/man1/systemctl.1.html#:~:text=is-system-running%20output
27+
__metrics_is_booted: "{{ __is_system_running.stdout != 'offline' }}"
28+
929
- name: Add Elasticsearch to metrics domain list
1030
set_fact:
1131
__metrics_domains: "{{ __metrics_domains + ['elasticsearch'] }}"

tests/check_bpftrace.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
retries: 10
88
delay: 1
99
changed_when: false
10+
when: __metrics_is_booted | bool
1011

1112
- name: Check if allowed users of bpftrace are configured
1213
shell: >-

tests/check_default_datasources.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
- Vector
1616
- bpftrace
1717
when:
18+
- __metrics_is_booted | bool
1819
- ansible_distribution in ['RedHat', 'CentOS']
1920
- ansible_distribution_major_version | int > 6
2021
- ansible_distribution_major_version | int < 10
@@ -32,8 +33,10 @@
3233
- Valkey
3334
- Vector
3435
- bpftrace
35-
when: (ansible_distribution in ['RedHat', 'CentOS'] and
36-
ansible_distribution_major_version | int >= 10) or
37-
ansible_distribution not in ['RedHat', 'CentOS']
36+
when:
37+
- __metrics_is_booted | bool
38+
- (ansible_distribution in ['RedHat', 'CentOS'] and
39+
ansible_distribution_major_version | int >= 10) or
40+
ansible_distribution not in ['RedHat', 'CentOS']
3841

3942
# yamllint enable rule:line-length

tests/check_firewall_selinux.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
block:
1111
- name: "Check firewall service status for grafana;
1212
metrics_manage_firewall is true"
13-
command: firewall-cmd --list-services
13+
command: firewall-offline-cmd --list-services
1414
register: _result
1515
failed_when:
1616
- "'grafana' not in _result.stdout"
@@ -22,7 +22,7 @@
2222
# so for now, we are using the port - see below
2323
# - name: "Check firewall service status for valkey;
2424
# metrics_manage_firewall is true"
25-
# command: firewall-cmd --list-services
25+
# command: firewall-offline-cmd --list-services
2626
# register: _result
2727
# failed_when: "'valkey' not in _result.stdout"
2828
# changed_when: false
@@ -34,7 +34,7 @@
3434

3535
- name: "Check firewall service status for redis;
3636
metrics_manage_firewall is true"
37-
command: firewall-cmd --list-services
37+
command: firewall-offline-cmd --list-services
3838
register: _result
3939
failed_when: "'redis' not in _result.stdout"
4040
changed_when: false
@@ -46,7 +46,7 @@
4646

4747
- name: "Check firewall port status for pmproxy;
4848
metrics_manage_firewall is true"
49-
command: firewall-cmd --list-ports
49+
command: firewall-offline-cmd --list-ports
5050
register: _result
5151
failed_when:
5252
- "'44322/tcp' not in _result.stdout"
@@ -57,14 +57,14 @@
5757

5858
- name: "Check firewall port status for pmcd;
5959
metrics_manage_firewall is true"
60-
command: firewall-cmd --list-ports
60+
command: firewall-offline-cmd --list-ports
6161
register: _result
6262
failed_when: "'44321/tcp' not in _result.stdout"
6363
changed_when: false
6464

6565
- name: "Check firewall port status for valkey;
6666
metrics_manage_firewall is true"
67-
command: firewall-cmd --list-ports
67+
command: firewall-offline-cmd --list-ports
6868
register: _result
6969
failed_when: "'6379/tcp' not in _result.stdout"
7070
changed_when: false

tests/check_from_elasticsearch.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
retries: 10
88
delay: 1
99
changed_when: false
10+
when: __metrics_is_booted | bool
1011

1112
# yamllint disable rule:line-length
1213
- name: Set platform/version specific variables

tests/check_from_spark.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@
77
retries: 10
88
delay: 1
99
changed_when: false
10-
when: "'pcp-pmda-openmetrics' in __spark_packages_pcp"
10+
when:
11+
- "'pcp-pmda-openmetrics' in __spark_packages_pcp"
12+
- __metrics_is_booted | bool

tests/check_fullstack_pmdas.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@
1313
changed_when: false
1414
loop:
1515
- bpftrace
16+
when: __metrics_is_booted | bool

tests/check_grafana.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
url: http://localhost:3000/login
66
method: GET
77
status_code: 200
8+
when: __metrics_is_booted | bool

tests/check_keyserver.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
set -euo pipefail
66
valkey-cli PING | grep PONG
77
changed_when: false
8-
when: (ansible_distribution in ['RedHat', 'CentOS'] and
9-
ansible_distribution_major_version | int >= 10) or
10-
ansible_distribution not in ['RedHat', 'CentOS']
8+
when:
9+
- (ansible_distribution in ['RedHat', 'CentOS'] and
10+
ansible_distribution_major_version | int >= 10) or
11+
ansible_distribution not in ['RedHat', 'CentOS']
12+
- __metrics_is_booted | bool
1113

1214
- name: Check if Redis responds
1315
shell: |
@@ -18,3 +20,4 @@
1820
- ansible_distribution in ['RedHat', 'CentOS']
1921
- ansible_distribution_major_version | int > 6
2022
- ansible_distribution_major_version | int < 10
23+
- __metrics_is_booted | bool

0 commit comments

Comments
 (0)