summaryrefslogtreecommitdiff
path: root/roles/radicle_node/tasks/main.yml
blob: 8e04a83d8ced4c7b03f0ae6c90639d11b3af04c7 (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
- name: "check radicle_node_version"
  shell: |
    [ "{{ radicle_node_version }}" = "1" ] || \
      (echo "Unexpected version {{ radicle_node_version }}" 1>&2; exit 1)

- name: "check that radicle_node_key is set"
  shell: |
    echo radicle_node_key Ansible variable is not set
    exit 1
  when: radicle_node_key is not defined

- name: "check that radicle_node_key_pub is set"
  shell: |
    echo radicle_node_key_pub Ansible variable is not set
    exit 1
  when: radicle_node_key_pub is not defined

- name: "install important additional packages for Radicle"
  apt:
    name:
      # For the Radicle installer
      - curl

      # Radicle is built on git.
      - git

      # Rsync for backups.
      - rsync

      # Web server for the web UI.
      - caddy

      # Radicle components.
      - radicle
      - radicle-ci-broker
      - radicle-native-ci

- name: "stop Radicle node if it's running"
  shell: |
    systemctl stop radicle-node || true

- name: "stop Radicle CI broker if it's running"
  shell: |
    systemctl stop radicle-ci-broker || true

- name: "configure git for _rad user"
  shell: |
    sudo -u _rad git config --global user.name "_rad"
    sudo -u _rad git config --global user.email "liw@liw.fi"

- name: "create directory for Radicle for the _rad user"
  file:
    state: directory
    path: /home/_rad/.radicle
    owner: _rad
    group: _rad
    mode: 0755

- name: "create directory for web pages"
  file:
    state: directory
    path: /srv/http
    owner: _rad
    group: _rad
    mode: 0755

- name: "create directory for Radicle backup"
  when: radicle_node_backup is defined
  file:
    state: directory
    path: radicle-backup
    owner: root
    group: root
    mode: 0755

- name: "restore from backup (step 1 or 2)"
  when: radicle_node_backup is defined
  synchronize:
    src: "{{ radicle_node_backup }}/."
    dest: radicle-backup/.
    group: no
    owner: no

- name: "restore from backup (step 2 or 2)"
  when: radicle_node_backup is defined
  shell: |
    find radicle-backup -name control.sock -delete
    rsync -a --del radicle-backup/home/_rad/.radicle/. /home/_rad/.radicle/.
    rsync -a --del radicle-backup/srv/http/. /srv/http/.
    chown -R _rad:_rad /home/_rad/.radicle/. /srv/http/.

- name: "create directory for Radicle keys"
  file:
    state: directory
    path: /home/_rad/.radicle/keys
    owner: _rad
    group: _rad
    mode: 0755

- name: "install Radicle private key"
  copy:
    content: "{{ radicle_node_key }}"
    dest: /home/_rad/.radicle/keys/radicle
    owner: _rad
    group: _rad
    mode: 0600

- name: "install Radicle public key"
  copy:
    content: "{{ radicle_node_key_pub }}"
    dest: /home/_rad/.radicle/keys/radicle.pub
    owner: _rad
    group: _rad
    mode: 0644

- name: "install systemd unit for Radicle node"
  template:
    src: radicle-node.service.j2
    dest: /lib/systemd/system/radicle-node.service

- name: "init Radicle node config"
  shell: |
    if [ ! -e /home/_rad/.radicle/config.json ]; then
        sudo -u _rad -i rad config init --alias "{{ radicle_node_domain_name }}"
    fi

- name: "(re)start systemd unit for Radicle node"
  systemd:
    name: radicle-node
    state: restarted
    masked: no
    enabled: yes
    daemon_reload: yes

- name: "install script to add update Radicle config file"
  when: radicle_node_connections is defined
  copy:
    src: rad-config-update
    dest: /home/_rad/rad-config-update
    owner: _rad
    group: _rad
    mode: 0755

- name: "connect to other Radicle nodes"
  when: radicle_node_connections is defined
  with_items: "{{ radicle_node_connections }}"
  shell: |
    sudo -u _rad -i ./rad-config-update \
        "{{ radicle_node_domain_name }}" \
        "{{ radicle_node_domain_name }}:8776" \
        "{{ radicle_node_policy }}" \
        "{{ radicle_node_scope }}" \
        "{{ item.nid }}@{{ item.host }}:{{ item.port }}"

- name: "install script to add update Radicle repository pinning"
  when: radicle_node_repositories is defined
  copy:
    src: rad-config-pin
    dest: /home/_rad/rad-config-pin
    owner: _rad
    group: _rad
    mode: 0755

- name: "seed Radicle repositories"
  when: radicle_node_repositories is defined
  with_items: "{{ radicle_node_repositories }}"
  shell: |
    sudo -u _rad rad seed "{{ item.rid }}"
    sudo -u _rad -i ./rad-config-pin "{{ item.rid }}"

- name: "install Caddy configuation file"
  template:
    src: Caddyfile.j2
    dest: /etc/caddy/Caddyfile

- name: "create directory for CI logs"
  file:
    state: directory
    path: /srv/http
    owner: _rad
    group: _rad

- name: "restart Caddy"
  systemd:
    name: caddy
    state: restarted
    masked: no
    enabled: yes
    daemon_reload: yes

- name: "install systemd unit for Radicle HTTPD"
  template:
    src: radicle-httpd.service.j2
    dest: /lib/systemd/system/radicle-httpd.service

- name: "enable systemd unit for Radicle HTTPD"
  systemd:
    name: radicle-httpd
    state: restarted
    masked: no
    enabled: yes
    daemon_reload: yes

- name: "install Radicle CI broker config"
  copy:
    content: |
      {{ radicle_node_ci_broker_config }}
    dest: /home/_rad/ci-broker.yaml
    owner: _rad
    group: _rad
    mode: 0644

- name: "create state directory for Radicle native CI"
  file:
    state: directory
    path: /home/_rad/native-ci.state
    owner: _rad
    group: _rad
    mode: 0755

- name: "install Radicle native CI config"
  copy:
    content: |
      state: /srv/http
      log: /home/_rad/native-ci.log
    dest: /home/_rad/native-ci.yaml
    owner: _rad
    group: _rad
    mode: 0644

- name: "install systemd unit for Radicle CI broker"
  template:
    src: radicle-ci-broker.service.j2
    dest: /lib/systemd/system/radicle-ci-broker.service

- name: "enable systemd unit for Radicle CI broker"
  systemd:
    name: radicle-ci-broker
    state: restarted
    masked: no
    enabled: yes
    daemon_reload: yes