---
- name: Include variables based on the operating system
  include_vars: "{{ ansible_os_family }}.yml"

# @action Installs PIP
# Ensures PIP is installed on macOS, Linux, and Windows systems
- name: Include tasks based on the operating system
  become: true
  become_method: "{{ 'runas' if ansible_os_family == 'Windows' else 'sudo' }}"
  become_user: "{{ ansible_user if ansible_os_family == 'Windows' else omit }}"
  block:
    - include_tasks: "install-{{ ansible_os_family }}.yml"

# @action Installs PIP packages
# Installs PIP packages specified in the `pip_packages` variable at the system level
- name: Ensure global pip packages are installed
  become: true
  pip:
    name: "{{ item.name | default(item) }}"
    version: "{{ item.version | default(omit) }}"
    virtualenv: "{{ item.virtualenv | default(omit) }}"
    state: "{{ item.state | default(omit) }}"
    executable: "{{ pip_executable }}"
  loop: "{{ pip_packages }}"
  when: ansible_os_family != 'Windows'
  ignore_errors: true

# @action Installs PIP packages
# Installs PIP packages specified in with the `user_configs` variable at the user level
- name: "Ensure PIP Packages are installed"
  become: true
  block:
    - include_tasks: pip-users.yml
