---

- fail:
    msg: only compatible with Debian >= 8
  when:
    - ansible_distribution != "Debian" or ansible_distribution_major_version is version('8', '<')

- name: Additional packages are installed
  apt:
    name:
      - zip
      - unzip
    state: present

- name: install info.php
  copy:
    src: info.php
    dest: /var/www/info.php
    mode: "0644"

- name: enable info.php link in default site index
  lineinfile:
    dest: /var/www/index.html
    line: '            <li><a href="/info.php">Infos PHP</a></li>'
    regexp: "Infos PHP"

- name: install opcache.php
  copy:
    src: opcache.php
    dest: /var/www/opcache.php
    mode: "0644"

- name: enable opcache.php link in default site index
  lineinfile:
    dest: /var/www/index.html
    line: '            <li><a href="/opcache.php">Infos OpCache PHP</a></li>'
    regexp: "Infos OpCache PHP"

- name: Add elements to user account template
  file:
    path: "/etc/skel/{{ item.path }}"
    state: "{{ item.state }}"
    mode: "{{ item.mode }}"
  loop:
    - { path: log, mode: "0750", state: directory }
    - { path: awstats, mode: "0750", state: directory }
    - { path: www, mode: "0750", state: directory }

- name: Apache log file (templates) are present
  command: "touch /etc/skel/log/{{ item }}"
  args:
    creates: "/etc/skel/log/{{ item }}"
  loop:
    - access.log
    - error.log

- name: Apache log file (templates) have the proper permissions
  file:
    dest: "/etc/skel/log/{{ item }}"
    mode: "0644"
  loop:
    - access.log
    - error.log

- name: "Install userlogrotate (jessie)"
  copy:
    src: userlogrotate_jessie
    dest: /etc/cron.weekly/userlogrotate
    mode: "0755"
  when: ansible_distribution_release == "jessie"

- name: "Install userlogrotate (Debian 9 or later)"
  copy:
    src: userlogrotate
    dest: /etc/cron.weekly/userlogrotate
    mode: "0755"
  when: ansible_distribution_major_version is version('9', '>=')

- name: Force DIR_MODE to 0750 in /etc/adduser.conf
  lineinfile:
    dest: /etc/adduser.conf
    regexp: '^DIR_MODE='
    line: 'DIR_MODE=0750'

- include: apache.yml

- include: phpmyadmin.yml

- include: awstats.yml

- include: fhs_retrictions.yml
  when: packweb_fhs_retrictions | bool

- name: Periodically cache ftp directory sizes for ftpadmin.sh
  cron:
    name: "ProFTPd directory size caching"
    special_time: daily
    job: "/usr/share/scripts/evoadmin/stats.sh"

- include: multiphp.yml
  when: packweb_multiphp_versions | length > 0
