Skip to content

refactor: use firewall role instead of module#19

Merged
richm merged 1 commit into
linux-system-roles:mainfrom
richm:refactor-use-firewall-role
May 11, 2026
Merged

refactor: use firewall role instead of module#19
richm merged 1 commit into
linux-system-roles:mainfrom
richm:refactor-use-firewall-role

Conversation

@richm

@richm richm commented May 11, 2026

Copy link
Copy Markdown
Contributor

We already have the firewall role in the system roles collection. Use that instead
of the firewalld module which adds an extra dependency.

Signed-off-by: Rich Megginson rmeggins@redhat.com

Summary by Sourcery

Replace direct firewalld module usage with the shared firewall system role and update related documentation and collection requirements.

Enhancements:

  • Use the fedora.linux_system_roles.firewall role to open required TCP ports instead of directly invoking the firewalld module.
  • Remove redundant service fact gathering now handled implicitly by the firewall role.

Build:

  • Add the fedora.linux_system_roles collection to role collection requirements.

Documentation:

  • Clarify that the secret registration server port is opened in firewalld without conditioning on the firewalld service state and update the Quadlet description to emphasize role-provided Quadlets.

@richm richm requested a review from spetrosi as a code owner May 11, 2026 13:24
@sourcery-ai

sourcery-ai Bot commented May 11, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Refactors firewall configuration tasks to use the shared fedora.linux_system_roles.firewall role instead of the ansible.posix.firewalld module, removes direct firewalld service checks, updates README docs, and adds the new collection dependency.

Sequence diagram for the new firewall configuration via shared role

sequenceDiagram
    actor Operator
    participant AnsibleController
    participant TrusteeRole
    participant FirewallRole as fedora_linux_system_roles_firewall_role
    participant TargetHost

    Operator->>AnsibleController: Run trustee_server role
    AnsibleController->>TrusteeRole: Execute tasks/secret_registration_server.yml

    TrusteeRole->>FirewallRole: include_role name=fedora.linux_system_roles.firewall
    FirewallRole->>FirewallRole: Process firewall var
    FirewallRole->>TargetHost: Ensure port trustee_server_secret_registration_listen_port/tcp enabled

    AnsibleController->>TrusteeRole: Execute tasks/trustee_quadlet.yml
    TrusteeRole->>FirewallRole: include_role name=fedora.linux_system_roles.firewall
    FirewallRole->>FirewallRole: Process firewall var
    FirewallRole->>TargetHost: Ensure port 8080/tcp enabled
Loading

Flow diagram for updated firewall task in secret_registration_server.yml

flowchart TD
    A[Start secret_registration_server tasks] --> B[Run secret registration server systemd service task]
    B --> C[Allow secret registration server port in firewall]
    C --> D[include_role name=fedora.linux_system_roles.firewall]
    D --> E[Set firewall var with trustee_server_secret_registration_listen_port/tcp
permanent=true
runtime=true
state=enabled]
    E --> F[Firewall role applies rule on managed host]
    F --> G[Append secret_registration_server to __trustee_server_services]
    G --> H[End tasks]
Loading

File-Level Changes

Change Details Files
Refactor firewall port configuration for the secret registration server to use the shared firewall role.
  • Remove explicit service_facts gathering and conditional firewalld running check.
  • Replace ansible.posix.firewalld task with include_role invocation of fedora.linux_system_roles.firewall.
  • Configure the firewall role via the firewall variable to open the secret registration server listen port with permanent and runtime enabled.
tasks/secret_registration_server.yml
Refactor firewall port 8080 configuration in trustee quadlet tasks to use the shared firewall role.
  • Remove explicit service_facts gathering before firewall configuration.
  • Replace direct ansible.posix.firewalld task with include_role invocation of fedora.linux_system_roles.firewall.
  • Configure the firewall role via the firewall variable to open TCP port 8080 with permanent and runtime enabled.
tasks/trustee_quadlet.yml
Align documentation and collection requirements with the new firewall role usage.
  • Update README wording to remove the conditional reference to firewalld running and clarify that Quadlets are installed by the role.
  • Ensure documentation still mentions opening KBS port 8080 in firewalld.
  • Add fedora.linux_system_roles collection to collection-requirements for role availability.
README.md
meta/collection-requirements.yml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

We already have the firewall role in the system roles collection.  Use that instead
of the firewalld module which adds an extra dependency.

Signed-off-by: Rich Megginson <rmeggins@redhat.com>

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="tasks/trustee_quadlet.yml" line_range="65-68" />
<code_context>
-  ansible.builtin.service_facts:
-  no_log: "{{ ansible_verbosity < 2 }}"
-
 - name: Allow port 8080 in firewall
-  ansible.posix.firewalld:
-    port: "8080/tcp"
-    permanent: true
-    immediate: true
-    state: enabled
-  when: (ansible_facts.services | default({})).get('firewalld.service', {}).get('state', '') == 'running'
+  ansible.builtin.include_role:
+    name: fedora.linux_system_roles.firewall
+  vars:
+    firewall:
+      - port: "8080/tcp"
</code_context>
<issue_to_address>
**suggestion (bug_risk):** The new firewall role invocation always runs, changing behavior from the previous firewalld-only conditional.

Previously this only changed the firewall when `firewalld.service` was running; now the role runs unconditionally and will manage whichever backend it detects. If you still intend “no-op unless firewalld is active”, consider restoring that behavior via a conditional around the role invocation or by setting role variables to restrict backend selection, to avoid failures or unintended changes on hosts with a different (or no) firewall backend.

Suggested implementation:

```
- name: Allow port 8080 in firewall
  ansible.builtin.include_role:
    name: fedora.linux_system_roles.firewall
  vars:
    firewall:
      - port: "8080/tcp"
        permanent: true
  when: (ansible_facts.services | default({})).get('firewalld.service', {}).get('state', '') == 'running'

```

To make this condition work, ensure that service facts are gathered before this task runs, for example via:
- A task like `- ansible.builtin.service_facts:` earlier in this play or
- A play-level `gather_facts: true` plus any existing mechanism you use to populate `ansible_facts.services`.

If `service_facts` was removed in the same PR, it should be reintroduced somewhere appropriate before this task.
</issue_to_address>

### Comment 2
<location path="README.md" line_range="99" />
<code_context>
-1. Downloads the Podman Quadlets from designated repo
+1. Installs the Podman Quadlets provided by the role
 2. Generates all required certificates of Trustee server components
 3. Add KBS port 8080 to firewalld
 4. Enables the services by default
</code_context>
<issue_to_address>
**suggestion (typo):** Use "Adds" instead of "Add" for subject-verb agreement.

To keep subject-verb agreement and align with the other items ("Generates", "Enables"), update this line to: `3. Adds KBS port 8080 to firewalld`.

```suggestion
3. Adds KBS port 8080 to firewalld
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread tasks/trustee_quadlet.yml
Comment thread README.md
1. Downloads the Podman Quadlets from designated repo
1. Installs the Podman Quadlets provided by the role
2. Generates all required certificates of Trustee server components
3. Add KBS port 8080 to firewalld

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion (typo): Use "Adds" instead of "Add" for subject-verb agreement.

To keep subject-verb agreement and align with the other items ("Generates", "Enables"), update this line to: 3. Adds KBS port 8080 to firewalld.

Suggested change
3. Add KBS port 8080 to firewalld
3. Adds KBS port 8080 to firewalld

@richm richm force-pushed the refactor-use-firewall-role branch from adc51c1 to 2757d0f Compare May 11, 2026 13:26
@richm

richm commented May 11, 2026

Copy link
Copy Markdown
Contributor Author

[citest]

@richm richm merged commit cec6bbe into linux-system-roles:main May 11, 2026
36 checks passed
@richm richm deleted the refactor-use-firewall-role branch May 11, 2026 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant