---
-
  name: "Installing SDKMAN"
  ansible.builtin.include_tasks: install.yml

-
  name: "Installing SDKMAN"
  environment:
    SDKMAN_DIR: '{{ sdkman_dir }}'
    SDKMAN_OFFLINE_MODE: 'false'
  become: '{{ service_user != ansible_user_id }}'
  become_user: '{{ service_user }}'
  block:
    -
      name: "Running SDKMAN tasks"
      ansible.builtin.include_tasks: sdkman.yml

    -
      name: "Persisting additional SDKMAN environment variables"
      ansible.builtin.include_tasks: persist_env.yml
      loop:
        - .bash_profile
        - .profile
        - .bashrc
        - .zshrc
      loop_control:
        loop_var: sdkman_profile

-
  name: "Updating alternatives"
  community.general.alternatives:
    name: "{{ item.name }}"
    path: "{{ sdkman_dir }}/candidates/{{ item.candidate }}/current/bin/{{ item.name }}"
    link: "{{ item.link }}"
  loop: "{{ sdkman_update_alternatives }}"
  become: true
  when: ansible_os_family != 'Darwin'
  tags:
    - sdkman_privilege
