THE HUGE REFACTORING CALENDER WEEK 33; Optimized Matrix and during this updated variables, and implemented better reset and cleanup mode handling, also solved some initial setup bugs

This commit is contained in:
2025-08-15 15:15:48 +02:00
parent 0228014d34
commit 022800425d
271 changed files with 1098 additions and 916 deletions

View File

@@ -0,0 +1,52 @@
# sys-systemctl
Utility role to reset/clean up **systemd** units for a given software stack.
It can install a unit-file remover tool, delete units that match a configured suffix, and reload the systemd daemon. The role is designed to run **once per play** and is commonly included by other roles (e.g., timer/service roles) to ensure a clean state before (re)deployment.
## Overview
When `MODE_RESET` is enabled, the role will:
1. Install the configured remover tool/package (via `pkgmgr-install`).
2. Remove all unit files that match the configured suffix for the current software.
3. Reload the systemd daemon to apply changes.
A run-once guard (`run_once_sys_systemctl`) prevents repeated execution within the same play run.
## Features
- **Idempotent cleanup** of systemd unit files based on a suffix.
- **Pluggable remover tool** via `UNIT_SUFFIX_REMOVER_PACKAGE`.
- **Daemon reload** to immediately apply changes.
- **Run-once safety** across the play to avoid redundant work.
## Variables
| Variable | Type | Default | Description |
|-----------------------------|---------|-------------|---------------------------------------------------------------------------------------------|
| `MODE_RESET` | bool | `false` | If `true`, executes the reset/cleanup tasks. |
| `SYS_SERVICE_SUFFIX` | string | *required* | Suffix used to identify unit files belonging to the software stack (e.g., `.infinito.nexus`). |
| `SOFTWARE_NAME` | string | *required* | Logical software identifier passed to the remover tool. |
| `UNIT_SUFFIX_REMOVER_PACKAGE` | string| `"unsure"` | Package/command used to remove the unit files. Must provide a CLI compatible with `-s`. |
> **Note:** The role expects the remover tool to support a command pattern like:
> ```
> <UNIT_SUFFIX_REMOVER_PACKAGE> -s '<SOFTWARE_NAME>'
> ```
> Replace `UNIT_SUFFIX_REMOVER_PACKAGE` with your actual utility (or wrapper script) that removes all matching unit files.
## Tasks Flow
- `tasks/main.yml`
- Includes `tasks/01_reset.yml` **only when** `MODE_RESET` is `true`.
- Loads `utils/run_once.yml` once to set `run_once_sys_systemctl`.
- `tasks/01_reset.yml`
- Installs `UNIT_SUFFIX_REMOVER_PACKAGE` via `pkgmgr-install`.
- Executes the remover command to purge unit files for `SOFTWARE_NAME` / `SYS_SERVICE_SUFFIX`.
- Runs `systemctl daemon-reload`.
## Dependencies
- `pkgmgr-install` (role): used to install `UNIT_SUFFIX_REMOVER_PACKAGE`.

View File

@@ -0,0 +1,24 @@
---
galaxy_info:
author: "Kevin Veen-Birkenbach"
description: "Utility role to reset/clean up systemd units for a given software stack."
license: "Infinito.Nexus NonCommercial License"
license_url: "https://s.infinito.nexus/license"
company: |
Kevin Veen-Birkenbach
Consulting & Coaching Solutions
https://www.veen.world
min_ansible_version: "2.9"
platforms:
- name: Linux
versions:
- all
galaxy_tags:
- systemd
- services
- cleanup
- reset
- automation
repository: "https://s.infinito.nexus/code"
issue_tracker_url: "https://s.infinito.nexus/issues"
documentation: "https://docs.infinito.nexus"

View File

@@ -0,0 +1,12 @@
- name: "pkgmgr install '{{ SYS_SERVICE_SUFFIX }}'"
include_role:
name: pkgmgr-install
vars:
package_name: "{{ UNIT_SUFFIX_REMOVER_PACKAGE }}"
- name: Remove all '{{ SYS_SERVICE_SUFFIX }}' files with '{{ UNIT_SUFFIX_REMOVER_PACKAGE }}'
command: "{{ UNIT_SUFFIX_REMOVER_PACKAGE }} -s '{{ SOFTWARE_NAME }}'"
- name: Reload systemd daemon
command: systemctl daemon-reload
become: true

View File

@@ -0,0 +1,6 @@
- block:
- name: "reset (if enabled)"
include_tasks: 01_reset.yml
when: MODE_RESET | bool
- include_tasks: utils/run_once.yml
when: run_once_sys_systemctl is not defined

View File

@@ -0,0 +1 @@
UNIT_SUFFIX_REMOVER_PACKAGE: "unsure"