- name: Create user
  user: >
    name=fluxbb home="{{ fluxbb_dir }}"
    shell=/bin/false system=yes createhome=no

- name: Clone fluxbb
  git:
    repo: https://gitlab.archlinux.org/archlinux/archbbs.git
    dest: "{{ fluxbb_dir }}"
    version: "{{ fluxbb_version }}"

- name: Fix home permissions
  file: state=directory owner=fluxbb group=fluxbb mode=0755  path="{{ fluxbb_dir }}"
  changed_when: false

- name: Create uploads directory
  file: state=directory owner=fluxbb group=fluxbb mode=0755 path="{{ fluxbb_dir }}/uploads"

- name: Create mariadb database
  mysql_db: name=fluxbb state=present

- name: Create mariadb user
  mysql_user: >
    user=fluxbb host=localhost password={{ fluxbb_db_password }}
    priv='fluxbb.*:ALL'

- name: Create ssl cert
  include_role:
    name: certificate
  vars:
    domains: ["{{ fluxbb_domain }}"]

- name: Create nginx log directory
  file: path=/var/log/nginx/{{ fluxbb_domain }} state=directory owner=root group=root mode=0755

- name: Configure nginx
  template: >
    src=nginx.conf.j2 dest=/etc/nginx/nginx.d/fluxbb.conf
    owner=root group=root mode=0644
  notify: Reload nginx

- name: Install python-passlib
  pacman: name=python-passlib

- name: Create auth file
  htpasswd: >
    path=/etc/nginx/auth/fluxx
    name={{ fluxbb_htpasswd.username }}
    password={{ fluxbb_htpasswd.password }}
    owner=root group=http mode=0640

- name: Install forum config
  template: >
    src=config.php.j2 dest={{ fluxbb_dir }}/config.php
    owner=fluxbb group=fluxbb mode=400

- name: Install php-apcu
  pacman: name=php-apcu,php-intl

- name: Configure php-fpm
  template: >
    src=php-fpm.conf.j2 dest=/etc/php/php-fpm.d/fluxbb.conf
    owner=root group=root mode=0644
  notify: Restart php-fpm@fluxbb

- name: Start and enable systemd socket
  service: name=php-fpm@fluxbb.socket state=started enabled=true
