- name: Start Ollama before model pulls
  command:
    argv:
      - "{{ courseware_root }}/scripts/service_manager.sh"
      - start
      - ollama
  changed_when: false

- name: Pull core Ollama models
  command:
    argv:
      - "{{ courseware_ollama_bin }}"
      - pull
      - "{{ item }}"
  environment:
    OLLAMA_HOST: "{{ courseware_bind_host }}:{{ courseware_ports.ollama }}"
    OLLAMA_MODELS: "{{ courseware_ollama_models_dir }}"
  loop: "{{ courseware_ollama_models }}"

- name: Pull optional heavy Ollama models
  command:
    argv:
      - "{{ courseware_ollama_bin }}"
      - pull
      - "{{ item }}"
  environment:
    OLLAMA_HOST: "{{ courseware_bind_host }}:{{ courseware_ports.ollama }}"
    OLLAMA_MODELS: "{{ courseware_ollama_models_dir }}"
  loop: "{{ courseware_optional_ollama_models }}"
  when: courseware_install_optional_heavy_models | bool
