feat : Add new handler to reload systemd and restart WOL.
Some checks failed
ansible-lint / Ansible Lint (push) Failing after 10s

This commit introduces a new handler that allows reloading the systemd configuration and restarting the Wake-on-LAN (WOL) service, ensuring persistent wake-up functionality.
This commit is contained in:
2025-12-26 10:36:19 +01:00
parent 55e5aa94d2
commit 0afc2a0461
2 changed files with 38 additions and 37 deletions

View File

@@ -1,4 +1,8 @@
--- ---
- name: Reload systemd
ansible.builtin.systemd:
daemon_reload: yes
- name: Reload systemd and restart WOL - name: Reload systemd and restart WOL
ansible.builtin.systemd: ansible.builtin.systemd:
name: wol name: wol
@@ -13,3 +17,4 @@
- name: Trigger_udev_net - name: Trigger_udev_net
ansible.builtin.command: udevadm trigger --subsystem-match=net ansible.builtin.command: udevadm trigger --subsystem-match=net
changed_when: false changed_when: false

View File

@@ -74,46 +74,42 @@
- wol_mode == 'd' - wol_mode == 'd'
- wol_mode not in item.1.stdout - wol_mode not in item.1.stdout
# -------------------------
# 4. Create systemd service for persistence
# -------------------------
- name: Create systemd service to persist WoL
ansible.builtin.copy:
dest: /etc/systemd/system/wol-interfaces.service
content: |
[Unit]
Description=Set Wake-on-LAN on network interfaces
After=network.target
Wants=network.target
# # ============================================================ [Service]
# # Enable WOL immediately (only if needed) Type=oneshot
# # ============================================================ ExecStart=/bin/bash -c '
# - name: Enable Wake-on-LAN immediately on NICs {% for intf, enabled, supported in en_interfaces | zip(wol_enabled.results, wol_supported.results) %}
# ansible.builtin.command: "ethtool -s {{ item }} wol {{ wol_mode }}" {% if wol_mode in supported.stdout %}
# register: wol_enable_result {% if wol_mode not in enabled.stdout %}
# changed_when: true /sbin/ethtool -s {{ intf }} wol {{ wol_mode }};
# loop: "{{ wol_needs_enable }}" {% endif %}
# loop_control: {% endif %}
# label: "{{ item }}" {% endfor %}
# when: wol_needs_enable | length > 0 '
RemainAfterExit=yes
# # ============================================================ [Install]
# # Persist WOL via udev rules (safe and idempotent) WantedBy=multi-user.target
# # ============================================================ notify:
# - name: Create udev rule content - Reload systemd
# ansible.builtin.set_fact:
# wol_udev_rules: >- - name: Enable and start WoL service
# {{ ansible.builtin.systemd:
# wol_final_interfaces name: wol-interfaces.service
# | map('regex_replace', '^(.+)$', 'ACTION=="add", SUBSYSTEM=="net", KERNEL=="\1", RUN+="/sbin/ethtool -s \1 wol {{ wol_mode }}"') enabled: yes
# | list state: started
# }}
# - name: Create/Update udev rules file
# ansible.builtin.copy:
# dest: /etc/udev/rules.d/90-wol.rules
# owner: root
# group: root
# mode: "0644"
# content: |
# # Wake-on-LAN udev rules - Auto-generated by Ansible
# # Applies to: {{ wol_final_interfaces | join(', ') }}
# {% for rule in wol_udev_rules %}
# {{ rule }}
# {% endfor %}
# notify:
# - Reload_udev_rules
# - Trigger_udev_net
# # ============================================================ # # ============================================================
# # Verification & Reporting # # Verification & Reporting