summaryrefslogtreecommitdiff
path: root/playbooks/git.yaml
blob: d166c4af450f658d0c3ea0bd69a0c6a154934ab1 (plain)
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
- name: Git browser
  hosts: hollyhock
  become: true
  vars:
    git_namespace: "{{ git_repo_root }}/sorantics"
  tasks:
    - name: Install dependencies
      ansible.builtin.apt:
        name:
          - cgit
          - fcgiwrap
          - git
        state: present
        update_cache: true

    - name: Enable fcgiwrap socket
      ansible.builtin.systemd:
        name: fcgiwrap.socket
        state: started
        enabled: true

    - name: Create git repository directory
      ansible.builtin.file:
        path: "{{ git_repo_root }}"
        state: directory
        owner: "{{ git_user }}"
        group: "{{ git_group }}"
        mode: "0755"

    - name: Create Sorantics git namespace
      ansible.builtin.file:
        path: "{{ git_namespace }}"
        state: directory
        owner: "{{ git_user }}"
        group: "{{ git_group }}"
        mode: "0755"

    - name: Create infra repository # noqa: command-instead-of-module
      ansible.builtin.command:
        cmd: git init --bare infra.git
        chdir: "{{ git_namespace }}"
        creates: "{{ git_namespace }}/infra.git/HEAD"
      become: true
      become_user: "{{ git_user }}"

    - name: Setup bare infra repository
      ansible.builtin.file:
        path: "{{ git_namespace }}/infra.git"
        state: directory
        owner: "{{ git_user }}"
        group: "{{ git_group }}"
        recurse: true

    - name: Describe infra repository
      ansible.builtin.copy:
        content: "Remote infrastructure.\n"
        dest: "{{ git_namespace }}/infra.git/description"
        owner: "{{ git_user }}"
        group: "{{ git_group }}"
        mode: "0644"

    - name: Configure cgit
      ansible.builtin.template:
        src: cgitrc.j2
        dest: /etc/cgitrc
        mode: "0644"

    - name: Copy nginx config
      ansible.builtin.template:
        src: nginx/git.conf.j2
        dest: /etc/nginx/sites-available/git
        mode: "0644"
      notify: Test and restart nginx

    - name: Disable http and https nginx sites
      ansible.builtin.file:
        path: "{{ item }}"
        state: absent
      loop:
        - /etc/nginx/sites-enabled/git-http
        - /etc/nginx/sites-enabled/git-https
      notify:
        - Test and restart nginx

    - name: Enable nginx config
      ansible.builtin.file:
        src: /etc/nginx/sites-available/git
        dest: /etc/nginx/sites-enabled/git
        state: link
        owner: "{{ nginx_user }}"
        group: "{{ nginx_group }}"
      notify:
        - Test and restart nginx

  handlers:
    - name: Test and restart nginx
      ansible.builtin.include_tasks: tasks/test_and_restart_nginx.yaml