summaryrefslogtreecommitdiffstats
path: root/roles/cgit/tasks/main.yml
blob: 17a5675b36703e7d49f048345db948c9ab1e9664 (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 packages"
  become: true
  ansible.builtin.package:
    name:
      - cgit
      - lighttpd
      - openssh
    state: present

- name: "Create git group"
  become: true
  ansible.builtin.group:
    name: "{{ cgit_ssh_user }}"
    system: true

- name: "Create git user"
  become: true
  ansible.builtin.user:
    name: "{{ cgit_ssh_user }}"
    group: "{{ cgit_ssh_user }}"
    shell: "/usr/bin/git-shell"
    home: "{{ cgit_repos_dir }}"
    create_home: true
    system: true

- name: "Create repos directory"
  become: true
  ansible.builtin.file:
    path: "{{ cgit_repos_dir }}"
    state: directory
    owner: "{{ cgit_ssh_user }}"
    group: "{{ cgit_ssh_user }}"
    mode: "0755"

- name: "Deploy cgitrc"
  become: true
  ansible.builtin.template:
    src: "cgitrc.j2"
    dest: "/etc/cgitrc"
    owner: "root"
    group: "root"
    mode: "0644"

- name: "Deploy lighttpd config"
  become: true
  ansible.builtin.template:
    src: "cgit.lighttpd.conf.j2"
    dest: "/etc/lighttpd/lighttpd.conf"
    owner: "root"
    group: "root"
    mode: "0644"
  notify: "Restart lighttpd"

- name: "Deploy caddy vhost on proxy"
  when: hostvars[cgit_proxy_host]['proxy_type'] == "caddy"
  delegate_to: "{{ cgit_proxy_host }}"
  block:
    - name: "Ensure caddy sites directory exists"
      become: true
      ansible.builtin.file:
        path: "/etc/caddy/sites"
        state: directory
        owner: "root"
        group: "caddy"
        mode: "0750"

    - name: "Deploy caddy vhost"
      become: true
      ansible.builtin.template:
        src: "cgit.caddy.j2"
        dest: "/etc/caddy/sites/{{ cgit_hostname }}.caddy"
        owner: "root"
        group: "caddy"
        mode: "0640"
      notify: "Restart caddy"

- name: "Deploy nginx vhost on proxy"
  when: hostvars[cgit_proxy_host]['proxy_type'] == "nginx"
  delegate_to: "{{ cgit_proxy_host }}"
  block:
    - name: "Ensure nginx vhosts directory exists"
      become: true
      ansible.builtin.file:
        path: "/etc/nginx/vhosts.d"
        state: directory
        owner: "root"
        group: "root"
        mode: "0755"

    - name: "Deploy nginx vhost"
      become: true
      ansible.builtin.template:
        src: "cgit.nginx.conf.j2"
        dest: "/etc/nginx/vhosts.d/{{ cgit_hostname }}.conf"
        owner: "root"
        group: "root"
        mode: "0644"
      notify: "Restart nginx"

- name: "Enable and start services"
  become: true
  ansible.builtin.service:
    name: "{{ item }}"
    enabled: true
    state: started
  loop:
    - lighttpd
    - sshd