---
- include: user.yml
  when: solr_create_user

- name: Set solr_filename for Solr 4+.
  set_fact:
    solr_filename: "solr-{{ solr_version }}"
  when: "solr_version.split('.')[0] >= '4'"

- name: Set solr_filename for Solr 3.x.
  set_fact:
    solr_filename: "apache-solr-{{ solr_version }}"
  when: "solr_version.split('.')[0] == '3'"

- name: Check if Solr has been installed already.
  stat:
    path: "{{ solr_install_path }}"
  register: solr_install_path_status

- name: Download Solr.
  get_url:
    url: "{{ solr_mirror }}/lucene/solr/{{ solr_version }}/{{ solr_filename }}.tgz"
    dest: "{{ solr_workspace }}/{{ solr_filename }}.tgz"
    force: no
  when: solr_install_path_status.stat.isdir is not defined
  register: solr_download_status

- name: Expand Solr.
  unarchive:
    src: "{{ solr_workspace }}/{{ solr_filename }}.tgz"
    dest: "{{ solr_workspace }}"
    copy: no
  when: solr_download_status.changed

# Install Solr < 5.
- include: install-pre5.yml
  when: "solr_version.split('.')[0] < '5'"

# Install Solr 5+.
- include: install.yml
  when: "solr_version.split('.')[0] >= '5'"

- name: Ensure solr is started and enabled on boot.
  service:
    name: "{{ solr_service_name }}"
    state: started
    enabled: yes

# Configure solr.
- include: configure.yml
  when: "solr_version.split('.')[0] >= '5'"

# Create cores, if any are configured.
- include: cores.yml
  when: "solr_cores and solr_version.split('.')[0] >= '5'"

- include: trim-fat.yml
  static: no
