---

# Load distribution specific variables
- include_vars: "{{ item }}"
  with_first_found:
    - "{{ role_path }}/vars/{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml"
    - "{{ role_path }}/vars/{{ ansible_os_family }}-{{ ansible_distribution_major_version }}.yml"
    - "{{ role_path }}/vars/{{ ansible_distribution }}.yml"
    - "{{ role_path }}/vars/{{ ansible_os_family }}.yml"
  tags: clojure

- name: Set default install mode
  set_fact: clojure_install_mode='none'
  tags: clojure

- name: Check if clojure is installed
  stat: path=/usr/local/bin/clojure
  register: clojure_bin
  tags: clojure

- name: Set install mode to install
  set_fact: clojure_install_mode='install'
  when: not clojure_bin.stat.exists
  tags: clojure

- name: Detect installed version
  block:
    - shell: clojure --version | perl -ne 'm/version\s(\d+(\.\d+)*)/ && print "$1"'
      changed_when: False
      register: clojure_current_version
    - set_fact: clojure_current_version={{ clojure_current_version.stdout }}
  tags: clojure

- name: Set install mode to upgrade
  set_fact: clojure_install_mode='upgrade'
  when: clojure_current_version != clojure_version
  tags: clojure
