From 9bef606607c822c83a82eb8f1a9d1832994be6f7 Mon Sep 17 00:00:00 2001 From: Jose Date: Sun, 14 Dec 2025 20:46:32 +0100 Subject: [PATCH] =?UTF-8?q?feat=20=E2=9C=A8:=20Enable=20Wake-on-LAN=20pers?= =?UTF-8?q?istently?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit introduces persistent Wake-on-LAN support for Proxmox VE via Ansible. It includes YAML configuration options for the interface, verification, and systemd service management, ensuring reliable functionality after Ansible role execution. The changes also address ignoring outputs and temporary files for a cleaner setup. --- .gitignore | 23 ++++++++++++++++++++++- README.md | 27 +++++++++++++++++++++++++++ defaults/main.yml | 9 +++++++++ handlers/main.yml | 9 +++++++++ tasks/main.yml | 32 ++++++++++++++++++++++++++++++++ templates/wol.service.j2 | 10 ++++++++++ 6 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 defaults/main.yml create mode 100644 handlers/main.yml create mode 100644 tasks/main.yml create mode 100644 templates/wol.service.j2 diff --git a/.gitignore b/.gitignore index 5c199eb..c191586 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,24 @@ -# ---> Ansible +# Ansible specific (optional - ignore temporary output or secrets) *.retry +*.vault +*.vault_pass +*.secret +*.log +# VSCode settings +.vscode/ +*.code-workspace + +# Windows system files +Thumbs.db +ehthumbs.db +Desktop.ini +$RECYCLE.BIN/ +*.lnk + +# Backup files +*~ +*.bak +*.swp +*.swo +*.tmp \ No newline at end of file diff --git a/README.md b/README.md index 1a5da87..c3b53b4 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,29 @@ # ansible_proxmox_WOL +This Ansible role enables persistent Wake-on-LAN (WOL) on a Proxmox VE server. + +## Variables + +| Variable | Default | Description | +|--------|---------|-------------| +| wol_interface | eno1 | Network interface | +| wol_mode | g | WOL mode (magic packet) | +| wol_verify | true | Verify WOL status | + + +## Requirements + +Use the physical NIC, not vmbr0, unless your NIC supports WOL through the bridge +Common interfaces: eno1, enp3s0, eth0 +Verify BIOS/UEFI: Enable Wake on LAN +Disable ErP / Deep Sleep + +## Example Playbook + +```yaml +- hosts: proxmox + become: true + roles: + - role: ansible_proxmox_WOL + vars: + wol_interface: vmbr0 diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..8f64823 --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,9 @@ +# Network interface to enable Wake-on-LAN on +wol_interface: "eno1" + +# WOL mode: +# g = magic packet (most common) +wol_mode: "g" + +# Enable verification task +wol_verify: true diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..a3d4555 --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,9 @@ +--- +- name: Reload systemd + command: systemctl daemon-reexec + +- name: Enable and start WOL service + systemd: + name: wol.service + enabled: yes + state: started diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..f2041d6 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,32 @@ +--- +- name: Install required packages + apt: + name: ethtool + state: present + update_cache: yes + +- name: Create systemd service for Wake-on-LAN + template: + src: wol.service.j2 + dest: /etc/systemd/system/wol.service + owner: root + group: root + mode: '0644' + notify: + - Reload systemd + - Enable and start WOL service + +- name: Enable WOL immediately (without reboot) + command: ethtool -s {{ wol_interface }} wol {{ wol_mode }} + changed_when: false + +- name: Verify Wake-on-LAN status + command: ethtool {{ wol_interface }} + register: wol_status + changed_when: false + when: wol_verify + +- name: Show WOL status + debug: + msg: "{{ wol_status.stdout_lines }}" + when: wol_verify diff --git a/templates/wol.service.j2 b/templates/wol.service.j2 new file mode 100644 index 0000000..32e5d42 --- /dev/null +++ b/templates/wol.service.j2 @@ -0,0 +1,10 @@ +[Unit] +Description=Enable Wake-on-LAN +After=network.target + +[Service] +Type=oneshot +ExecStart=/sbin/ethtool -s {{ wol_interface }} wol {{ wol_mode }} + +[Install] +WantedBy=multi-user.target