---
- name: Prepare Windows for rdiff-backup development
  hosts: windows_hosts
  gather_facts: false
  tasks:
  - name: enable running chocolatey scripts without confirmation
    chocolatey.chocolatey.win_chocolatey_feature:
      name: allowGlobalConfirmation
      state: enabled
  - name: install basis development tools via chocolatey
    chocolatey.chocolatey.win_chocolatey:
      name:
      #- virtio-drivers
      - git
      - cygwin
      - cyg-get  # depends on cygwin
      - 7zip
      - vscode # Visual Studio Code (editor)
      state: present
  - name: install cmake via chocolatey reachable from system
    chocolatey.chocolatey.win_chocolatey:
      name:
        - cmake
      install_args: "ADD_CMAKE_TO_PATH=System"
      state: present
  - name: install python via chocolatey
    chocolatey.chocolatey.win_chocolatey:
      name: "python3"
      version: "{{ python_version_full }}"
      state: upgrade
      package_params: /InstallDir:C:\Python64 /InstallDir32:C:\Python32
  - name: install dependencies, allows for reboot in-between
    chocolatey.chocolatey.win_chocolatey:
      name:
      - ruby  # dependency of asciidoctor, requires reboot
      - dotnetfx
      - vcredist140
      state: present
    register: vs_deps
  - name: execute reboot if something has changed to VS dependencies
    ansible.windows.win_reboot:
    when: vs_deps is changed
  - name: install visual studio tools via chocolatey
    chocolatey.chocolatey.win_chocolatey:
      name:  # VC 2022 is the version available on GitHub actions
      - visualstudio2022buildtools
      - visualstudio2022-workload-python
      - visualstudio2022-workload-vctools
      state: present
    register: vs
  - name: execute reboot if something has been changed to visual studio
    ansible.windows.win_reboot:
    when: vs is changed

  - name: copy requirement files
    ansible.windows.win_copy:
      src: "{{ playbook_dir }}/../../requs"
      dest: "."
  - name: install and validate necessary Python libraries
    ansible.builtin.script:
      cmd: "{{ playbook_dir }}/../win_provision.sh 32 64"
      executable: "\"{{ git_bash_exe | regex_replace('/', '\\\\') }}\""
    register: pipcmd
    changed_when: "'Successfully installed ' in pipcmd.stdout"

  - name: Install NuGet to overcome issue 50332 in Ansible
    # https://github.com/ansible/ansible/issues/50332
    ansible.windows.win_shell: Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
  - name: install the Powershell Community Extensions for win_unzip
    community.windows.win_psmodule:
      name: Pscx
      state: present
      allow_clobber: true
  - name: refresh the environment variables as we need gem in the PATH
    ansible.windows.win_command: refreshenv.cmd
    changed_when: false
  - name: install asciidoctor gem
    ansible.windows.win_command: gem.cmd install asciidoctor

- name: Prepare Linux to be used as Samba server
  hosts: samba_servers
  become: true
  gather_facts: true
  pre_tasks:
  - name: set hostname of server
    hostname:
      name: "{{ inventory_hostname_short }}.vagrant.example.com"
  roles:
    #- bertvv.rh-base
  - rh-base
    #- bertvv.samba
  - samba
