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