aboutsummaryrefslogtreecommitdiffstats
path: root/roles/srht/tasks/main.yml
blob: 076557fdaf9a5e6e5d2b2c32929b30e6c984649d (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

# srht ~~ roles/srht/tasks/main.yml
# Srht git server

---

- name: ensure srht repository is enabled
  lineinfile:
    path: /etc/apk/repositories
    regexp: "^https://mirror.sr.ht"
    line: "https://mirror.sr.ht/alpine/v3.12/sr.ht"

- name: ensure signing key for sourcehut repository is installed
  shell: |
    wget -q -O /etc/apk/keys/alpine@sr.ht.rsa.pub https://mirror.sr.ht/alpine/alpine@sr.ht.rsa.pub
    apk update

- name: ensure sourcehut is installed
  package: name="{{ item }}" state=present
  loop: "{{ srht_services }}"

- name: generate srht service key
  shell: srht-keygen service | rev | cut -d " " -f 1 | rev
  register: srht_key_service

- name: generate srht network key
  shell: srht-keygen network | rev | cut -d " " -f 1 | rev
  register: srht_key_network

- name: generate srht webhook key
  shell: srht-keygen webhook | rev | cut -d " " -f 1 | rev
  register: srht_key_webhook

- name: generate srht nginx configuration
  template:
    src: "{{ item }}.srht.conf.j2"
    dest: "/etc/nginx/conf.d/{{ item }}.srht.conf"
    owner: "{{ user_root }}"
    group: "{{ group_root }}"
    mode: 0644
  loop:
    - "meta"
    - "hub"

- name: generate srht example configuration
  template:
    src: config.ini.j2
    dest: /etc/sr.ht/config.example.ini
    owner: "{{ user_root }}"
    group: "{{ group_root }}"
    mode: 0644

- name: debug hint for example configuration
  debug:
    msg:
      - srht configuration example at /etc/sr.ht/config.example.ini
      - copy and modify it to /etc/sr.ht/config.ini

- name: create database for srht services
  shell: psql -c 'create database "{{ item }}.sr.ht"'
  register: result
  failed_when: result.rc != 0 and "already exists" not in result.stderr
  ignore_errors: true
  loop:
    - "meta"
    - "git"
    - "hub"
  become: true
  become_user: postgres

- name: init database for srht services
  shell: "{{ item }}srht-initdb"
  loop:
    - "meta"
    - "git"
    - "hub"

- name: enable and restart srht services
  service:
    name: "{{ item }}"
    state: restarted
    enabled: true
  loop: "{{ srht_services }}"

- name: enable and restart srht api services
  service:
    name: "{{ item }}"
    state: restarted
    enabled: true
  loop:
    - "meta.sr.ht-api"
    - "git.sr.ht-api"
remember that computers suck.