Skip to content

Commit 8d0e6ac

Browse files
martinpittrichm
authored andcommitted
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. Do *not* enable the role for system containers (the `container`) flag. That currently fails due to SELinux not working properly there, and needs to be looked at separately if desired. 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. Do full bootc end-to-end validation in tests_tangd_custom_port, which is one of the most complex ones (combining nbde_server, firewall, and selinux roles). Run the first scenario with custom port for that. See https://issues.redhat.com/browse/RHEL-78157
1 parent 065e029 commit 8d0e6ac

7 files changed

Lines changed: 61 additions & 11 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ These are the variables that can be passed to the role:
3030
| **Variable** | **Default** | **Description** |
3131
|----------|-------------|------|
3232
| `nbde_server_provider` | `tang` | identifies the provider for `nbde_server` role. We currently support `tang` as an `nbde_server` provider, meaning that the `nbde_server` role is currently able to provision/deploy tang servers.
33-
| `nbde_server_service_state` | `started` | indicates the state the nbde_server should be. It can be either `started` (default) or `stopped`. `started` means the server is accepting connections, whereas `stopped` means it is not accepting connections.
33+
| `nbde_server_service_state` | `started` | indicates the state the nbde_server should be. It can be either `started` (default) or `stopped`. `started` means the server is accepting connections, whereas `stopped` means it is not accepting connections. Ignored for non-booted hosts like container builds, then the service is always started at boot.
3434
| `nbde_server_rotate_keys`| `false` | indicates whether we should rotate existing keys -- if any -- , then create new keys. Default behavior (`false`) is to create new keys, if there are none, and don't touch the keys, if they exist. If set to `true`, existing keys will be rotated and new keys will be created.
3535
|`nbde_server_fetch_keys`| `false` | indicates whether we should fetch keys to the control node, in which case they will be placed in `nbde_server_keys_dir`. You **must** set `nbde_server_keys_dir` to use `nbde_server_fetch_keys`.
3636
|`nbde_server_deploy_keys`| `false` |indicates whether we should deploy the keys located in `nbde_server_keys_dir` directory to the remote hosts. You **must** set `nbde_server_keys_dir` to use `nbde_server_deploy_keys`.

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
- clevis
21+
- containerbuild
2122
- el7
2223
- el8
2324
- el9

tasks/main-tang.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@
3636
- name: Reload the daemons so the new changes take effect
3737
systemd:
3838
daemon_reload: true
39-
when: __nbde_server_port_changed | d(false) | bool
39+
when:
40+
- __nbde_server_port_changed | d(false) | bool
41+
- __nbde_server_is_booted | bool
4042

4143
- name: Ensure required services are enabled and at the right state
4244
service:
@@ -45,8 +47,8 @@
4547
enabled: true
4648
loop: "{{ __nbde_server_services }}"
4749
vars:
48-
__state: "{{ nbde_server_service_state if
49-
nbde_server_service_state != 'started' else
50+
__state: "{{ omit if not __nbde_server_is_booted else
51+
nbde_server_service_state if nbde_server_service_state != 'started' else
5052
'restarted' if __nbde_server_port_changed else
5153
'started' }}"
5254

tasks/set_vars.yml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
difference(ansible_facts.keys() | list) | length > 0
77

88
- name: Determine if system is ostree and set flag
9-
when: not __nbde_server_is_ostree is defined
9+
when: __nbde_server_is_ostree is not defined
1010
block:
1111
- name: Check if system is ostree
1212
stat:
@@ -17,6 +17,27 @@
1717
set_fact:
1818
__nbde_server_is_ostree: "{{ __ostree_booted_stat.stat.exists }}"
1919

20+
- name: Determine if system is booted with systemd
21+
when: __nbde_server_is_booted is not defined
22+
block:
23+
- name: Run systemctl
24+
# noqa command-instead-of-module
25+
command: systemctl is-system-running
26+
register: __is_system_running
27+
changed_when: false
28+
check_mode: false
29+
failed_when: false
30+
31+
- name: Require installed systemd
32+
fail:
33+
msg: "Error: This role requires systemd to be installed."
34+
when: '"No such file or directory" in __is_system_running.msg | d("")'
35+
36+
- name: Set flag to indicate that systemd runtime operations are available
37+
set_fact:
38+
# see https://www.man7.org/linux/man-pages/man1/systemctl.1.html#:~:text=is-system-running%20output
39+
__nbde_server_is_booted: "{{ __is_system_running.stdout != 'offline' }}"
40+
2041
- name: Set platform/version specific variables
2142
include_vars: "{{ lookup('first_found', ffparams) }}"
2243
vars:

tests/tasks/verify-role-results.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
service:
1717
name: "{{ item }}"
1818
enabled: true
19-
state: started
19+
state: "{{ 'started' if __nbde_server_is_booted else omit }}"
2020
check_mode: true
2121
register: nbde_server_services_state
2222
loop: "{{ __nbde_server_services }}"

tests/tests_nbde_server_service_state.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
service:
1919
name: "{{ item }}"
2020
enabled: true
21-
state: started
21+
state: "{{ 'started' if __nbde_server_is_booted else omit }}"
2222
register: nbde_server_state
2323
check_mode: true
2424
loop: "{{ __nbde_server_services }}"
@@ -39,7 +39,7 @@
3939
service:
4040
name: "{{ item }}"
4141
enabled: true
42-
state: stopped
42+
state: "{{ 'stopped' if __nbde_server_is_booted else omit }}"
4343
register: nbde_server_state
4444
check_mode: true
4545
loop: "{{ __nbde_server_services }}"
@@ -60,7 +60,7 @@
6060
service:
6161
name: "{{ item }}"
6262
enabled: true
63-
state: started
63+
state: "{{ 'started' if __nbde_server_is_booted else omit }}"
6464
register: nbde_server_state
6565
check_mode: true
6666
loop: "{{ __nbde_server_services }}"

tests/tests_tangd_custom_port.yml

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,29 @@
1313
include_role:
1414
name: linux-system-roles.nbde_server
1515
public: true
16+
when: not __bootc_validation | d(false)
17+
18+
# role does not run during bootc QEMU validation, thus some vars are undefined
19+
- name: Set __nbde_server_is_booted for bootc validation tests
20+
set_fact:
21+
__nbde_server_is_booted: true
22+
# see vars/main.yml
23+
__nbde_server_tangd_socket_file_path: /etc/systemd/system/tangd.socket.d/override.conf
24+
when: __bootc_validation | d(false)
1625

1726
- name: Ensure iproute package for ss command
1827
package:
1928
name: iproute
2029
state: present
2130
use: "{{ (__nbde_server_is_ostree | d(false)) |
2231
ternary('ansible.posix.rhel_rpm_ostree', omit) }}"
32+
when: not __bootc_validation | d(false)
33+
34+
- name: Create QEMU deployment during bootc end-to-end test
35+
delegate_to: localhost
36+
command: "{{ lsr_scriptdir }}/bootc-buildah-qcow.sh {{ ansible_host }}"
37+
changed_when: true
38+
when: ansible_connection == "buildah"
2339

2440
- name: Check if port is open
2541
shell:
@@ -31,6 +47,7 @@
3147
failed_when: not __open_ports_output.stdout is
3248
search(':' ~ (nbde_server_port | string) ~ '$')
3349
changed_when: false
50+
when: __nbde_server_is_booted | bool
3451

3552
- name: Check if port TCP is open
3653
shell:
@@ -41,10 +58,11 @@
4158
register: __open_ports_output
4259
failed_when: __open_ports_output.stdout != "tcp"
4360
changed_when: false
61+
when: __nbde_server_is_booted | bool
4462

4563
- name: Check if port is opened in firewall
4664
command: >-
47-
firewall-cmd --zone {{ nbde_server_firewall_zone }} --query-port
65+
firewall-offline-cmd --zone {{ nbde_server_firewall_zone }} --query-port
4866
{{ nbde_server_port }}/tcp
4967
register: __firewall_output
5068
changed_when: false
@@ -55,6 +73,12 @@
5573
__file: "{{ __nbde_server_tangd_socket_file_path }}"
5674
__fingerprint: "system_role:nbde_server"
5775

76+
# do just one image/verify cycle for the bootc end-to-end test
77+
- name: Skip remaining steps in bootc end-to-end validation
78+
meta: end_play
79+
when: __bootc_validation | d(false)
80+
81+
5882
- name: Install with default port and firewall zone
5983
include_role:
6084
name: linux-system-roles.nbde_server
@@ -74,6 +98,7 @@
7498
failed_when: not __open_ports_output.stdout is
7599
search(':80$')
76100
changed_when: false
101+
when: __nbde_server_is_booted | bool
77102

78103
- name: Check if port TCP is open
79104
shell:
@@ -83,10 +108,11 @@
83108
register: __open_ports_output
84109
failed_when: __open_ports_output.stdout != "tcp"
85110
changed_when: false
111+
when: __nbde_server_is_booted | bool
86112

87113
- name: Check if port is opened in firewall
88114
command: >-
89-
firewall-cmd --zone {{ nbde_server_firewall_zone }} --query-port
115+
firewall-offline-cmd --zone {{ nbde_server_firewall_zone }} --query-port
90116
80/tcp
91117
register: __firewall_output
92118
changed_when: false

0 commit comments

Comments
 (0)