---
## Based on 
## https://wiki.koha-community.org/wiki/Debian

- name: Add an Apt signing key, will not download if present
  become: yes
  apt_key:
    url: https://debian.koha-community.org/koha/gpg.asc
    state: present
    keyring: /usr/share/keyrings/koha-community-archive-keyring.gpg 

- name: Add Koha package repository
  become: yes
  apt_repository:
    filename: koha.list
    repo: "deb [signed-by=/usr/share/keyrings/koha-community-archive-keyring.gpg] http://debian.koha-community.org/koha stable main"
    update_cache: yes 

- name: Install koha and mariadb
  become: yes
  apt:
    pkg:
      - koha-common
      - mariadb-server

- name: Configure the defaults
  become: yes
  template:
    src: koha-sites.conf.j2
    dest: /etc/koha/koha-sites.conf

- name: Enable the Apache2 module rewrite
  become: yes
  apache2_module:
    state: present
    name: rewrite

- name: Enable the Apache2 module cgi
  become: yes
  apache2_module:
    state: present
    name: cgi

- name: Make sure apache2 is restarted
  become: yes
  systemd:
    state: restarted
    name: apache2

- name: Create koha instance
  become: yes
  command:
    cmd: koha-create --create-db "{{library_name}}"

- name: Enable the Apache2 module cgi
  become: yes
  apache2_module:
    state: present
    name: headers

- name: Enable the Apache2 module cgi
  become: yes
  apache2_module:
    state: present
    name: proxy_http

- name: Enable plack
  become: yes
  command:
    cmd: koha-plack --enable "{{library_name}}"

- name: Start plack
  become: yes
  command:
    cmd: koha-plack --start "{{library_name}}"

- name: Make sure apache2 is restarted
  become: yes
  systemd:
    state: restarted
    name: apache2



