- name: Install ethtool
  become: true
  ansible.builtin.package:
    name: ethtool
    state: present

- name: Enable WOL on the network interface
  become: true
  ansible.builtin.command: ethtool -s {{ network_interface }} wol g
  changed_when: false

- name: Create systemd-networkd WOL config
  become: true
  ansible.builtin.copy:
    dest: "/etc/systemd/network/10-wol.network"
    content: |
      [Match]
      Name={{ network_interface }}

      [Link]
      WakeOnLan=magic
    owner: root
    group: root
    mode: "0644"

- name: Enable and restart systemd-networkd
  become: true
  ansible.builtin.systemd:
    name: systemd-networkd
    enabled: true
    state: restarted

- name: Confirm WOL setting applied
  become: true
  ansible.builtin.command: ethtool {{ network_interface }}
  register: wol_status
  changed_when: false

- name: Show WOL setting
  ansible.builtin.debug:
    var: wol_status.stdout_lines
