---
- name: Ensure Stubby is installed
  chocolatey.chocolatey.win_chocolatey:
    name: stubby
    state: "{{ app_state | default('present') }}"

- name: Add stubby to PATH
  ansible.windows.win_path:
    elements: 'C:\Program Files\Stubby'
    state: present
    scope: user

- name: Ensure hostctl is installed
  community.windows.win_scoop:
    name: hostctl
    state: "{{ app_state | default('present') }}"
    global: true

- name: Ensure DNS configuration file is created
  ansible.windows.win_template:
    src: stubby.yml.j2
    dest: "{{ stubby_config_path }}"
    backup: true

- name: Update DNS setting
  ansible.windows.win_shell: '"C:\Program Files\Stubby\stubby_setdns_windows.ps1"'

- name: Setup Scheduled job to start Stubby on boot
  community.windows.win_scheduled_task:
    name: Stubby
    path: '%PROGRAMFILES%\Stubby\stubby.bat'
    actions:
      - path: cmd.exe
    triggers:
      - type: boot
    username: SYSTEM

- name: Run generic configuration tasks
  include_tasks: config-Windows.yml
