---
# tasks file for ansible-cgit
- name: Install packages
  apt:
      name: '{{ item }}'
      state: present
      update_cache: yes
      cache_valid_time: 3600
  with_items:
      - cgit
      - git
      - apache2
      - python-docutils

- name: Enable mod-cgi
  notify:
      - Restart Apache
  apache2_module:
      name: cgi
      state: present

- name: Add configuration for cgit css
  template:
      src: cgit-css.conf.j2
      dest: /etc/apache2/conf-enabled/cgit-css.conf
      owner: root
      group: root
      mode: '0644'

- name: Create git repostories directory
  file:
      path: /srv/git
      owner: root
      group: www-data
      mode: '0777'
      state: directory

- name: Add symlink for rst2html (hack)
  file:
      src: /usr/share/docutils/scripts/python2/rst2html
      dest: /usr/local/bin/rst2html.py
      owner: root
      group: root
      state: link

- name: Configure cgit
  lineinfile:
      dest: /etc/cgitrc
      line: '{{ item.line }}'
      regexp: '{{ item.regexp|default(omit) }}'
      insertbefore: '{{ item.insertbefore|default(omit) }}'
  with_items:
      - line: 'scan-path=/srv/git'
        regexp: 'scan-path='
      - line: 'css=/cgit/css/cgit.css'
        regexp: '^css='
      - line: 'logo=/cgit/css/cgit.png'
        regexp: '^logo='
      - line: 'favicon=/cgit/css/favicon.ico'
        regexp: '^favicon='
      - line: 'about-filter=/usr/lib/cgit/filters/about-formatting.sh'
        regexp: '^about-filter='
        insertbefore: 'scan-path='
      - line: 'enable-git-config=1'
        regexp: '^enable-git-config='
      - line: 'readme=:README.md'
      - line: 'readme=:readme.md'
      - line: 'readme=:README.mkd'
      - line: 'readme=:readme.mkd'
      - line: 'readme=:README.rst'
      - line: 'readme=:readme.rst'
      - line: 'readme=:README.html'
      - line: 'readme=:readme.html'
      - line: 'readme=:README.htm'
      - line: 'readme=:readme.htm'
      - line: 'readme=:README.txt'
      - line: 'readme=:readme.txt'
      - line: 'readme=:README'
      - line: 'readme=:readme'
      - line: 'readme=:INSTALL.md'
      - line: 'readme=:install.md'
      - line: 'readme=:INSTALL.mkd'
      - line: 'readme=:install.mkd'
      - line: 'readme=:INSTALL.rst'
      - line: 'readme=:install.rst'
      - line: 'readme=:INSTALL.html'
      - line: 'readme=:install.html'
      - line: 'readme=:INSTALL.htm'
      - line: 'readme=:install.htm'
      - line: 'readme=:INSTALL.txt'
      - line: 'readme=:install.txt'
      - line: 'readme=:INSTALL'
      - line: 'readme=:install'
