# This is for an OS other than Fedora 18

- name: Install missing packages required for KA Lite startup
  package:
    name: "{{ item }}"
    state: present
  with_items:
    - python-virtualenv

- name: Download KA Lite's requirements file
  get_url:
    url: "{{ kalite_requirements }}"
    dest: "{{ pip_packages_dir }}/kalite.txt"
    timeout: "{{ download_timeout }}"
  when: internet_available

#- name: Install KA Lite non-static + reqs file with pip - (debuntu)
#  pip: requirements={{ pip_packages_dir }}/kalite.txt
#       virtualenv={{ kalite_venv }}
#       virtualenv_site_packages=no
#       extra_args="--no-cache-dir"
#       extra_args="--disable-pip-version-check"
#  when: internet_available and is_debuntu

- name: Install KA Lite static with pip (debuntu)
  pip:
    name: ka-lite-static
    version: "{{ kalite_version }}"
    virtualenv: "{{ kalite_venv }}"
    virtualenv_site_packages: no
    extra_args: "--no-cache-dir"
#       extra_args="--disable-pip-version-check"
  when: internet_available and is_debuntu

#- name: Install KA Lite non-static + reqs file with pip (OS's other than debuntu)
#  pip: requirements={{ pip_packages_dir }}/kalite.txt
#       virtualenv={{ kalite_venv }}
#       virtualenv_site_packages=no
#       extra_args="--no-cache-dir"
#       extra_args="--disable-pip-version-check"
#  when: internet_available and not is_debuntu

- name: Install KA Lite static with pip (OS's other than debuntu)
  pip:
    name: ka-lite-static
    version: "{{ kalite_version }}"
    virtualenv: "{{ kalite_venv }}"
    virtualenv_site_packages: no
#       extra_args="--no-cache-dir"
#       extra_args="--disable-pip-version-check"
  when: internet_available and not is_debuntu

- name: Default is to have cronserve started with KA Lite
  set_fact:
    job_scheduler_stanza: ""

- name: Add --skip-job-scheduler to start if cronserve not enabled
  set_fact:
    job_scheduler_stanza: "--skip-job-scheduler "
  when: not kalite_cron_enabled

- name: Create 'kalite-serve' service, kalite.sh and kalite.conf
  template:
    backup: no
    src: "{{ item.src }}"
    dest: "{{ item.dest }}"
    owner: root
    group: root
    mode: "{{ item.mode }}"
  with_items:
    - { src: 'kalite-serve.service.j2', dest: '/etc/systemd/system/kalite-serve.service', mode: '0644'}
    - { src: 'kalite.sh.j2', dest: '/usr/bin/kalite', mode: '0755'}
    - { src: 'kalite.conf', dest: '/etc/{{ apache_config_dir }}', mode: '0644'}
