summaryrefslogtreecommitdiff
path: root/roles/gitolite/http/tasks/nginx-vhost.yml
blob: 706f5655ff3151212aaf96440de75f6c2059cf01 (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
---
- name: compute nginx locations directives
  set_fact:
    nginx_locations_base:
      '= /':
        return: "303 /cgit/"
      '/':
        root: "/usr/share/cgit/"
    nginx_locations_logo: {}
    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.key }}/cgitrc;

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

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

- name: compute nginx extra location directive for git_backend
  when: "'enable_git_backend' in gitolite_instance.value.http and gitolite_instance.value.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.key }}/repositories;

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

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