- name: Install packages
  package:
    name:
      - wireguard-tools
      - qrencode # For generating qr codes to send to phone with `qrencode -t ansiutf8 -r <config_file>`
      - systemd-resolvconf # For wg-quick to regenerate resolv.conf
    state: present

- name: Configure wireguard
  copy:
    src: "{{ item }}"
    dest: /etc/wireguard/
    mode: 0440
    owner: root
    group: root
  with_fileglob: "files/wireguard_configs/{{ wireguard_directory }}/*.conf"

- name: Enable Wireguard
  when: enabled_wireguard is defined
  systemd:
    enabled: yes
    name: "wg-quick@{{ item }}"
    daemon_reload: yes
  loop: "{{ enabled_wireguard }}"
