Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ These are the variables that can be passed to the role:
|----------|-------------|------|
| `nbde_client_provider` | `clevis`| identifies the provider for the `nbde_client` role. We currently support `clevis`.|
| `nbde_client_bindings` | | a list containing binding configurations, which include e.g. devices and slots. |
| `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 |
| `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. |
| `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. |
| `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. |

### nbde_client_bindings

Expand Down Expand Up @@ -57,6 +58,20 @@ nbde_client_bindings:
- http://server2.example.com
```

### nbde_client_extra_dracut_settings

`nbde_client_extra_dracut_settings` is a list of strings. Each string is written
as a line in `/etc/dracut.conf.d/nbde_client.conf`, after the implicit
platform-specific settings from `__nbde_client_dracut_settings`.

This is useful for NBDE clients that use static IP addressing and need network
configuration available during early boot. For example:

```yaml
nbde_client_extra_dracut_settings:
- kernel_cmdline="ip=192.0.2.10::192.0.2.1:255.255.255.0::ens3:none nameserver=192.0.2.100"
```

## Example Playbooks

### Example 1: high availability
Expand Down
6 changes: 6 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,10 @@ nbde_client_early_boot: true
nbde_client_bindings: []
nbde_client_secure_logging: true

# Extra lines written to /etc/dracut.conf.d/nbde_client.conf in addition to
# the platform-specific __nbde_client_dracut_settings. Each list item is a
# full dracut configuration line, for example:
# - kernel_cmdline="ip=192.0.2.10::192.0.2.1:255.255.255.0::ens3:none nameserver=192.0.2.100"
nbde_client_extra_dracut_settings: []

# vim:set ts=2 sw=2 et:
2 changes: 1 addition & 1 deletion templates/nbde_client.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# nbde_client dracut config
{{ ansible_managed | comment }}
{{ "system_role:nbde_client" | comment(prefix="", postfix="") }}
{% for line in __nbde_client_dracut_settings %}
{% for line in __nbde_client_dracut_settings + nbde_client_extra_dracut_settings %}
{{ line }}
{% endfor %}
1 change: 1 addition & 0 deletions tests/tests_default_vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
that:
- nbde_client_provider is defined
- nbde_client_bindings is defined
- nbde_client_extra_dracut_settings is defined

# vim:set ts=2 sw=2 et:
74 changes: 74 additions & 0 deletions tests/tests_extra_dracut_settings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Generated by: Cursor using models Cursor Grok 4.5, Composer 2.5, Sonnet 5
---
- name: Test nbde_client_extra_dracut_settings
hosts: all
vars:
__nbde_client_test_extra_dracut_line: >-
kernel_cmdline="ip=192.0.2.10::192.0.2.1:255.255.255.0::ens3:none nameserver=192.0.2.100"
nbde_client_extra_dracut_settings:
- "{{ __nbde_client_test_extra_dracut_line }}"

tasks:
- name: Run the test
block:
Comment on lines +11 to +13

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Verify failure scenarios in the test.

As per path instructions, "Tests should verify both success and failure scenarios". This test currently only validates the success path and idempotency. Please add an additional task block that expects a failure (for example, by intentionally providing an invalid type, such as a dictionary instead of a list of strings, to nbde_client_extra_dracut_settings and asserting that the role execution fails).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/tests_extra_dracut_settings.yml` around lines 11 - 13, Extend the test
task block in tests_extra_dracut_settings.yml with a failure scenario for
nbde_client_extra_dracut_settings, passing an invalid value such as a dictionary
instead of a list of strings and asserting that role execution fails. Preserve
the existing success and idempotency checks.

Source: Path instructions

- name: Use nbde_client role
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
__sr_public: true

Comment on lines +8 to +18

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Align role invocations with path instructions.
Both role invocations in this test define the input variables at the play level and omit the ansible.builtin. prefix, which violates the role invocation pattern required by the path instructions. The role configuration variables must be passed directly within the vars block of the centrally managed wrapper.

  • tests/tests_extra_dracut_settings.yml#L8-L18: Use ansible.builtin.include_tasks and move nbde_client_extra_dracut_settings from the play's vars into this task's vars block.
  • tests/tests_extra_dracut_settings.yml#L49-L53: Apply the same correction to the idempotency run, using the FQCN and including nbde_client_extra_dracut_settings in its vars block.

(Note: Consider adding the ansible.builtin. prefix to the other tasks in this file—such as slurp, set_fact, assert, and file—to fully align with modern Ansible best practices.)

📍 Affects 1 file
  • tests/tests_extra_dracut_settings.yml#L8-L18 (this comment)
  • tests/tests_extra_dracut_settings.yml#L49-L53
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/tests_extra_dracut_settings.yml` around lines 8 - 18, Update
tests/tests_extra_dracut_settings.yml at lines 8-18 and 49-53: use
ansible.builtin.include_tasks for both wrapper invocations, and move
nbde_client_extra_dracut_settings from the play-level vars into each
invocation’s vars block. Do not alter the other tasks unless required for these
corrections.

Source: Path instructions

- name: Read generated dracut config
slurp:
src: /etc/dracut.conf.d/nbde_client.conf
register: __nbde_client_dracut_conf

- name: Decode dracut config content
set_fact:
__nbde_client_dracut_conf_content: "{{
__nbde_client_dracut_conf.content | b64decode }}"

- name: Verify extra dracut setting is present
assert:
that:
- __nbde_client_test_extra_dracut_line in
__nbde_client_dracut_conf_content
fail_msg: >-
Expected /etc/dracut.conf.d/nbde_client.conf to contain
{{ __nbde_client_test_extra_dracut_line }}. Content was:
{{ __nbde_client_dracut_conf_content }}

- name: Verify implicit dracut settings are present
assert:
that:
- item in __nbde_client_dracut_conf_content
fail_msg: >-
Expected /etc/dracut.conf.d/nbde_client.conf to contain
implicit setting {{ item }}. Content was:
{{ __nbde_client_dracut_conf_content }}
loop: "{{ __nbde_client_dracut_settings }}"

- name: Use nbde_client role again for idempotency
include_tasks: tasks/run_role_with_clear_facts.yml
vars:
__sr_public: true

- name: Re-read generated dracut config
slurp:
src: /etc/dracut.conf.d/nbde_client.conf
register: __nbde_client_dracut_conf_again

- name: Verify dracut config is unchanged after second run
assert:
that:
- __nbde_client_dracut_conf.content ==
__nbde_client_dracut_conf_again.content
fail_msg: Dracut config changed on second role run

always:
- name: Clean up generated dracut config
file:
path: /etc/dracut.conf.d/nbde_client.conf
state: absent
tags:
- tests::cleanup

# vim:set ts=2 sw=2 et:
Loading