- name: Check installed Homebrew formulas
  command: "brew list --versions {{ item }}"
  loop:
    - git
    - git-lfs
    - cmake
    - node
    - python@3.11
    - ollama
  register: courseware_brew_checks
  changed_when: false
  failed_when: false

- name: Install missing Homebrew formulas
  command: "brew install {{ item.item }}"
  loop: "{{ courseware_brew_checks.results }}"
  when: item.rc != 0

- name: Mark Ollama as installed by courseware on macOS
  file:
    path: "{{ courseware_ollama_install_marker }}"
    state: touch
    mode: "0644"
  when:
    - courseware_brew_checks.results
      | selectattr('item', 'equalto', 'ollama')
      | selectattr('rc', 'ne', 0)
      | list
      | length > 0
