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

@@ -74,46 +74,42 @@
- wol_mode == 'd'
- 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
# # ============================================================
# # Enable WOL immediately (only if needed)
# # ============================================================
# - name: Enable Wake-on-LAN immediately on NICs
# ansible.builtin.command: "ethtool -s {{ item }} wol {{ wol_mode }}"
# register: wol_enable_result
# changed_when: true
# loop: "{{ wol_needs_enable }}"
# loop_control:
# label: "{{ item }}"
# when: wol_needs_enable | length > 0
[Service]
Type=oneshot
ExecStart=/bin/bash -c '
{% for intf, enabled, supported in en_interfaces | zip(wol_enabled.results, wol_supported.results) %}
{% if wol_mode in supported.stdout %}
{% if wol_mode not in enabled.stdout %}
/sbin/ethtool -s {{ intf }} wol {{ wol_mode }};
{% endif %}
{% endif %}
{% endfor %}
'
RemainAfterExit=yes
# # ============================================================
# # Persist WOL via udev rules (safe and idempotent)
# # ============================================================
# - name: Create udev rule content
# ansible.builtin.set_fact:
# wol_udev_rules: >-
# {{
# wol_final_interfaces
# | map('regex_replace', '^(.+)$', 'ACTION=="add", SUBSYSTEM=="net", KERNEL=="\1", RUN+="/sbin/ethtool -s \1 wol {{ wol_mode }}"')
# | list
# }}
[Install]
WantedBy=multi-user.target
notify:
- Reload systemd
- name: Enable and start WoL service
ansible.builtin.systemd:
name: wol-interfaces.service
enabled: yes
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