# This is for Fedora 18, assumed to be an XO

- name: Install dependent packages (Fedora 18)
  package:
    name: "{{ item }}"
    state: present
  with_items:
    - python-psutil
    - expect
  when: is_F18

- name: Install dependent pip packages (Fedora 18)
  pip:
    name: selenium
  when: internet_available and is_F18

- name: Determine if KA Lite is already downloaded
  stat:
    path: "{{ downloads_dir }}/ka-lite"
  register: kalite

- name: Download the latest KA Lite repo
  git:
    repo: "{{ kalite_repo_url }}"
    dest: "{{ downloads_dir }}/ka-lite"
    depth: 1
    version: 0.13.x
  ignore_errors: yes
  when: internet_available and kalite.stat.exists is defined and not kalite.stat.exists

- name: Create iiab-kalite user and password (Fedora 18)
  user:
    name: "{{ kalite_user }}"
    password: "{{ kalite_password_hash }}"
    update_password: on_create

- name: Create kalite_root directory (Fedora 18)
  file:
    path: "{{ kalite_root }}"
    owner: root
    group: root
    mode: 0755
    state: directory

- name: Copy the KA Lite repo into place (Fedora 18)
  command: "rsync -at {{ downloads_dir }}/ka-lite/ {{ kalite_root }}"

- name: Make kalite_user owner
  file:
    path: "{{ kalite_root }}"
    owner: "{{ kalite_user }}"
    group: "{{ kalite_user }}"
    recurse: yes
    state: directory

# local_settings is deprecated
- name: Copy local_settings file
  template:
    src: f18/local_settings.py.j2
    dest: "{{ kalite_root }}/kalite/local_settings.py"
    owner: "{{ kalite_user }}"
    group: "{{ kalite_user }}"
    mode: 0644

- name: Create kalite-serve & kalite-cron services, and iiab_cronservectl.sh
  template:
    backup: no
    src: "{{ item.src }}"
    dest: "{{ item.dest }}"
    owner: root
    group: root
    mode: "{{ item.mode }}"
  with_items:
    - { src: 'f18/kalite-serve.service.j2', dest: '/etc/systemd/system/kalite-serve.service', mode: '0644'}
    - { src: 'f18/kalite-cron.service.j2', dest: '/etc/systemd/system/kalite-cron.service', mode: '0644'}
    - { src: 'f18/iiab_cronservectl.sh.j2', dest: '{{ kalite_root }}/scripts/iiab_cronservectl.sh', mode: '0755'}
