summaryrefslogtreecommitdiff
path: root/roles/gitolite/http/tasks/main.yml
blob: fdc86d6636e3a1cb8257e9a7f9c2aa479c7af03b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
---
- name: install cgit and fcgiwrap
  apt:
    name:
    - cgit
    - python3-pygments
    - fcgiwrap
    state: present

### TODO: this might break stuff..
- name: mask default fcgiwrap systemd units
  loop:
  - socket
  - service
  systemd:
    name: "fcgiwrap.{{ item }}"
    state: stopped
    masked: yes

- name: install fcgiwrap systemd units
  loop:
  - socket
  - service
  template:
    src: "fcgiwrap.{{ item }}.j2"
    dest: "/etc/systemd/system/fcgiwrap-gitolite-{{ gitolite_instance }}.{{ item }}"

- name: make sure fcgiwrap systemd socket unit is enabled and started
  systemd:
    daemon_reload: yes
    name: "fcgiwrap-gitolite-{{ gitolite_instance }}.socket"
    state: started
    enabled: yes

- name: generate cgitrc
  template:
    src: cgitrc.j2
    dest: "{{ gitolite_base_path }}/{{ gitolite_instance }}/cgitrc"

- name: install custom logo
  when: "'logo' in gitolite_instances[gitolite_instance].http"
  block:
  - name: create logo base directory
    file:
      path: /usr/local/share/cgit
      state: directory

  - name: copy logo file
    copy:
      src: "{{ gitolite_instances[gitolite_instance].http.logo }}"
      dest: "/usr/local/share/cgit/{{ gitolite_instance }}.png"

  - name: compute nginx location directive for logo
    set_fact:
      nginx_locations_logo:
        '= /logo.png':
          alias: "/usr/local/share/cgit/{{ gitolite_instance }}.png"

- name: compute nginx locations directives
  set_fact:
    nginx_locations_base:
      '= /':
        return: "303 /cgit/"
      '/cgit-css/':
        alias: "/usr/share/cgit/"
    nginx_locations_main:
      '/cgit/':
        custom: |-
          include fastcgi_params;
          fastcgi_split_path_info ^(/cgit)(.*)$;

          fastcgi_param SCRIPT_FILENAME /usr/lib/cgit/cgit.cgi;
          fastcgi_param PATH_INFO       $fastcgi_path_info;
          fastcgi_param QUERY_STRING    $args;
          fastcgi_param HTTP_HOST       $server_name;
          fastcgi_param CGIT_CONFIG     {{ gitolite_base_path }}/{{ gitolite_instance }}/cgitrc;

          fastcgi_pass unix:/run/fcgiwrap/gitolite-{{ gitolite_instance }}.sock;

- name: compute nginx location directive for git_backend
  when: "'enable_git_backend' in gitolite_instances[gitolite_instance].http and gitolite_instances[gitolite_instance].http.enable_git_backend"
  set_fact:
    nginx_locations_git_backend:
      '~ ^.*/git-receive-pack$':
        return: "403"
      '~ ^.*/(HEAD|info/refs|objects/(info/.*|[0-9a-f]+/[0-9a-f]+|pack/pack-[0-9a-f]+.(pack|idx))|git-upload-pack)$':
        custom: |-
          include fastcgi_params;

          fastcgi_param SCRIPT_FILENAME     /usr/lib/git-core/git-http-backend;
          fastcgi_param PATH_INFO           $uri;
          fastcgi_param GIT_PROJECT_ROOT    {{ gitolite_base_path }}/{{ gitolite_instance }}/repositories;

          fastcgi_pass unix:/run/fcgiwrap/gitolite-{{ gitolite_instance }}.sock;

- name: install nginx vhost
  vars:
    nginx_vhost:
      name: "gitolite-{{ gitolite_instance }}"
      template: generic
      tls:
        certificate_provider: "{{ acme_client }}"
      hostnames: "{{ gitolite_instances[gitolite_instance].http.hostnames }}"
      logs:
        access: "/var/log/nginx/git-{{ gitolite_instance }}_access.log"
        error: "/var/log/nginx/git-{{ gitolite_instance }}_error.log"
      locations: "{{ nginx_locations_base | combine(nginx_locations_logo | default({})) | combine(nginx_locations_main) | combine(nginx_locations_git_backend | default({})) }}"
  include_role:
    name: nginx/vhost