Skip to content

Commit c7e2978

Browse files
committed
feat: Support extra dracut settings for static IP
Feature: Introduce the nbde_client_extra_dracut_settings variable. This is a list of strings written to /etc/dracut.conf.d/nbde_client.conf in addition to the implicit platform-specific __nbde_client_dracut_settings. Reason: NBDE clients with static IP addressing need custom early-boot network settings in dracut (for example kernel_cmdline with a static ip= and nameserver). Previously the role only wrote fixed platform settings, so users had to disable early boot or manage dracut config outside the role. Result: Users can pass extra dracut configuration lines via nbde_client_extra_dracut_settings (documented in README.md) while keeping the role's implicit settings. A new integration test verifies the static IP kernel_cmdline example is written to the conf file. Assisted-by: Cursor using models Cursor Grok 4.5, Composer 2.5, Sonnet 5 Signed-off-by: Rich Megginson <rmeggins@redhat.com>
1 parent fac2be5 commit c7e2978

7 files changed

Lines changed: 151 additions & 2 deletions

File tree

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ These are the variables that can be passed to the role:
2424
|----------|-------------|------|
2525
| `nbde_client_provider` | `clevis`| identifies the provider for the `nbde_client` role. We currently support `clevis`.|
2626
| `nbde_client_bindings` | | a list containing binding configurations, which include e.g. devices and slots. |
27-
| `nbde_client_early_boot` | `true` | by default nbde_client will configure the initrd to unlock the volume. This may need to be disabled if the managed host is using static IP addressing, or if the volume should be unlocked by clevis-luks-askpass |
27+
| `nbde_client_early_boot` | `true` | by default nbde_client will configure the initrd to unlock the volume. This may need to be disabled if the volume should be unlocked by clevis-luks-askpass. For managed hosts with static IP addressing, prefer `nbde_client_extra_dracut_settings` instead of disabling early boot. |
2828
| `nbde_client_secure_logging` | `true` | If true, suppress potentially sensitive output from tasks that handle credentials, secrets, and other sensitive data. Set to false for debugging issues with credential handling or secret management, but be aware this may expose sensitive information in logs. |
29+
| `nbde_client_extra_dracut_settings` | `[]` | a list of extra dracut configuration lines written to `/etc/dracut.conf.d/nbde_client.conf` in addition to the role's implicit platform settings. Use this for static IP early-boot networking and other custom dracut options. Requires `nbde_client_early_boot: true` (the default); the role fails if early boot is disabled. |
2930

3031
### nbde_client_bindings
3132

@@ -57,6 +58,24 @@ nbde_client_bindings:
5758
- http://server2.example.com
5859
```
5960
61+
### nbde_client_extra_dracut_settings
62+
63+
`nbde_client_extra_dracut_settings` is a list of strings. Each string is written
64+
as a line in `/etc/dracut.conf.d/nbde_client.conf`, after the implicit
65+
platform-specific settings from `__nbde_client_dracut_settings`.
66+
67+
This is useful for NBDE clients that use static IP addressing and need network
68+
configuration available during early boot. For example:
69+
70+
```yaml
71+
nbde_client_extra_dracut_settings:
72+
- kernel_cmdline+=" ip=192.0.2.10::192.0.2.1:255.255.255.0::ens3:none nameserver=192.0.2.100 "
73+
```
74+
75+
**Note:** You cannot set `nbde_client_early_boot: false` when using
76+
`nbde_client_extra_dracut_settings`. Extra dracut settings are only written when
77+
early boot is enabled. The role fails if both are set this way.
78+
6079
## Example Playbooks
6180

6281
### Example 1: high availability

defaults/main.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,10 @@ nbde_client_early_boot: true
2323
nbde_client_bindings: []
2424
nbde_client_secure_logging: true
2525

26+
# Extra lines written to /etc/dracut.conf.d/nbde_client.conf in addition to
27+
# the platform-specific __nbde_client_dracut_settings. Each list item is a
28+
# full dracut configuration line, for example:
29+
# - kernel_cmdline+=" ip=192.0.2.10::192.0.2.1:255.255.255.0::ens3:none nameserver=192.0.2.100 "
30+
nbde_client_extra_dracut_settings: []
31+
2632
# vim:set ts=2 sw=2 et:

tasks/main-clevis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
owner: root
2323
mode: '0444'
2424
when: nbde_client_early_boot | bool
25+
notify: Handle nbde_client update initramfs
2526

2627
- name: Check whether devices are at the desired state
2728
when:

tasks/main.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# SPDX-License-Identifier: MIT
22
---
3+
- name: Fail when extra dracut settings are set but early boot is disabled
4+
fail:
5+
msg: >-
6+
nbde_client_extra_dracut_settings requires nbde_client_early_boot
7+
to be true. nbde_client_extra_dracut_settings has
8+
{{ nbde_client_extra_dracut_settings | length }} entries, but
9+
nbde_client_early_boot is false so they will not be written.
10+
when:
11+
- not nbde_client_early_boot
12+
- nbde_client_extra_dracut_settings | length > 0
13+
314
# Set up internal variables.
415
- name: Set version specific variables
516
include_tasks: set_vars.yml

templates/nbde_client.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# nbde_client dracut config
22
{{ ansible_managed | comment }}
33
{{ "system_role:nbde_client" | comment(prefix="", postfix="") }}
4-
{% for line in __nbde_client_dracut_settings %}
4+
{% for line in __nbde_client_dracut_settings + nbde_client_extra_dracut_settings %}
55
{{ line }}
66
{% endfor %}

tests/tests_default_vars.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@
1414
that:
1515
- nbde_client_provider is defined
1616
- nbde_client_bindings is defined
17+
- nbde_client_extra_dracut_settings is defined
1718

1819
# vim:set ts=2 sw=2 et:
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# Generated by: Cursor using models Cursor Grok 4.5, Composer 2.5, Sonnet 5
2+
---
3+
- name: Test nbde_client_extra_dracut_settings
4+
hosts: all
5+
vars:
6+
__nbde_client_test_extra_dracut_line: >-
7+
kernel_cmdline+=" ip=192.0.2.10::192.0.2.1:255.255.255.0::ens3:none nameserver=192.0.2.100 "
8+
nbde_client_extra_dracut_settings:
9+
- "{{ __nbde_client_test_extra_dracut_line }}"
10+
11+
tasks:
12+
- name: Run the test
13+
block:
14+
- name: Use nbde_client role
15+
include_tasks: tasks/run_role_with_clear_facts.yml
16+
vars:
17+
__sr_public: true
18+
19+
- name: Read generated dracut config
20+
slurp:
21+
src: /etc/dracut.conf.d/nbde_client.conf
22+
register: __nbde_client_dracut_conf
23+
24+
- name: Decode dracut config content
25+
set_fact:
26+
__nbde_client_dracut_conf_content: "{{
27+
__nbde_client_dracut_conf.content | b64decode }}"
28+
29+
- name: Verify extra dracut setting is present
30+
assert:
31+
that:
32+
- __nbde_client_test_extra_dracut_line in
33+
__nbde_client_dracut_conf_content
34+
fail_msg: >-
35+
Expected /etc/dracut.conf.d/nbde_client.conf to contain
36+
{{ __nbde_client_test_extra_dracut_line }}. Content was:
37+
{{ __nbde_client_dracut_conf_content }}
38+
39+
- name: Verify implicit dracut settings are present
40+
assert:
41+
that:
42+
- item in __nbde_client_dracut_conf_content
43+
fail_msg: >-
44+
Expected /etc/dracut.conf.d/nbde_client.conf to contain
45+
implicit setting {{ item }}. Content was:
46+
{{ __nbde_client_dracut_conf_content }}
47+
loop: "{{ __nbde_client_dracut_settings }}"
48+
49+
- name: Use nbde_client role again for idempotency
50+
include_tasks: tasks/run_role_with_clear_facts.yml
51+
vars:
52+
__sr_public: true
53+
54+
- name: Re-read generated dracut config
55+
slurp:
56+
src: /etc/dracut.conf.d/nbde_client.conf
57+
register: __nbde_client_dracut_conf_again
58+
59+
- name: Verify dracut config is unchanged after second run
60+
assert:
61+
that:
62+
- __nbde_client_dracut_conf.content ==
63+
__nbde_client_dracut_conf_again.content
64+
fail_msg: Dracut config changed on second role run
65+
66+
- name: Run the role with early boot disabled
67+
vars:
68+
nbde_client_early_boot: false
69+
nbde_client_extra_dracut_settings:
70+
- >-
71+
kernel_cmdline+=" ip=192.0.2.10::192.0.2.1:255.255.255.0::ens3:none
72+
nameserver=192.0.2.100 "
73+
block:
74+
- name: Use nbde_client role with conflicting settings
75+
include_tasks: tasks/run_role_with_clear_facts.yml
76+
77+
- name: Fail if the role did not reject conflicting settings
78+
fail:
79+
msg: >-
80+
Role should fail when nbde_client_early_boot is false and
81+
nbde_client_extra_dracut_settings is set
82+
83+
rescue:
84+
- name: Assert the early boot conflict error message
85+
assert:
86+
that:
87+
- >-
88+
'nbde_client_extra_dracut_settings requires
89+
nbde_client_early_boot' in ansible_failed_result.msg
90+
fail_msg: >-
91+
Unexpected failure:
92+
{{ ansible_failed_result.msg | default(ansible_failed_result) }}
93+
94+
always:
95+
- name: Clean up generated dracut config
96+
file:
97+
path: /etc/dracut.conf.d/nbde_client.conf
98+
state: absent
99+
tags:
100+
- tests::cleanup
101+
102+
- name: Run the role with no settings to clean up
103+
include_tasks: tasks/run_role_with_clear_facts.yml
104+
vars:
105+
nbde_client_extra_dracut_settings: []
106+
nbde_client_early_boot: true
107+
nbde_client_bindings: []
108+
tags:
109+
- tests::cleanup
110+
111+
# vim:set ts=2 sw=2 et:

0 commit comments

Comments
 (0)