---
- name: Windows | include vars
  include_vars: "{{ ansible_os_family|lower }}.yml"

- name: Windows | Expect reboot_required to false
  set_fact:
    reboot_required: false

- name: Windows | Get the IPv6 disable flags
  win_reg_stat:
    path: '{{ ipv6.reg_path }}'
    name: '{{ ipv6.disable_flags_reg_name }}'
  register: ipv6_flags

- name: Windows | Disable IPv6 (if not already disabled)
  block:
    - name: Windows | Set the IPv6 disable flags
      win_regedit:
        path: '{{ ipv6.reg_path }}'
        name: '{{ ipv6.disable_flags_reg_name }}'
        data: '{{ ipv6.disable_flags_reg_value }}'
        type: dword
    - name: Windows | Set reboot_required to true for the IPv6 disable
      set_fact:
        reboot_required: true
  when: (not ipv6_flags.exists or
         ipv6_flags.type != 'REG_DWORD' or
         ipv6_flags.raw_value != ipv6.disable_flags_reg_value)

- name: Windows | Installing Required features
  win_feature:
    name: "{{item}}"
    state: present
  register: features_installed
  with_items:
    - Containers

- name: Windows | Checking if reboot_required
  set_fact:
    reboot_required: true
  with_items:
    - "{{features_installed.results}}"
  loop_control:
    label: "{{item.item}}"
  when: item.reboot_required

- name: Windows | Reboot the node
  win_reboot:
  when: reboot_required

- name: Windows | Fetch Windows utils
  include_tasks: ./fetch_utils.yml
