Skip to content

Commit 9841b1d

Browse files
committed
resturcure the setup.yaml and hosts safer this way and add CSP for grafana
1 parent 21c2f27 commit 9841b1d

10 files changed

Lines changed: 93 additions & 30 deletions

File tree

‎.github/copilot/README.md‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ This project provisions Freifunk Südholstein gateways and related services. The
1717

1818
- README.md: deployment, usage, and vault guidance
1919
- setup.yml: main playbook with gateway, service, and monitoring roles
20-
- hosts.yml: inventory for gateways, services, and monitoring hosts
20+
- hosts.yml: inventory for gateways, split service groups, and monitoring hosts
2121
- group_vars/versions.yml: shared software versions
2222
- group_vars/secrets.yml: shared encrypted vars
2323
- host_vars/: host-specific secret and config values
@@ -26,15 +26,18 @@ This project provisions Freifunk Südholstein gateways and related services. The
2626
## Host groups
2727

2828
- gateways: complete production router deployment
29-
- services: lightweight service-only hosts
29+
- services_map: map service host roles
30+
- services_web: web service host roles
3031
- monitoring: Prometheus/Grafana stack
3132

3233
## Typical workflow
3334

3435
```bash
3536
ansible-playbook --vault-id=fastd_key@prompt setup.yml
3637
ansible-playbook --vault-id=fastd_key@prompt setup.yml --limit gateways
37-
ansible-playbook --vault-id=fastd_key@prompt setup.yml --limit services
38+
ansible-playbook --vault-id=fastd_key@prompt setup.yml --limit "services_map:services_web"
39+
ansible-playbook --vault-id=fastd_key@prompt setup.yml --limit services_map
40+
ansible-playbook --vault-id=fastd_key@prompt setup.yml --limit services_web
3841
ansible-playbook --vault-id=fastd_key@prompt setup.yml --check
3942
ansible-lint
4043
```

‎README.md‎

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Ansible
22
[![Ansible Lint](https://github.com/ffsh/ansible/actions/workflows/ansible-lint.yml/badge.svg?branch=main)](https://github.com/ffsh/ansible/actions/workflows/ansible-lint.yml)
33

4-
This repository holds the Ansible playbook to deploy a ffsh gateway in the standard configuration and to provision batman-only service hosts.
4+
This repository holds the Ansible playbook to deploy a ffsh gateway in the standard configuration and to provision dedicated service hosts.
55
It is based on https://docs.freifunk-suedholstein.de/de/1.5/gateway.html but changes were made where it was plausible.
66

77
## requirements
@@ -48,7 +48,10 @@ That way Ansible will be able to automatically detect the right ssh key and conn
4848
## hosts
4949
If you want to deploy to a new gateway you need to add it to the `hosts.yml` file in the repo, just compare it to brunsbach and add your own details.
5050

51-
If you want to add a batman-only service host, add it to the `services` group in `hosts.yml`. These hosts only receive the `batman` and `batctl` roles.
51+
If you want to add a service host, place it in the dedicated service group in `hosts.yml`:
52+
53+
- `services_map` for the map stack (`batman`, `batctl`, `grafana_public`, `meshviewer`)
54+
- `services_web` for the web stack (`batman`, `batctl`, `website`, `firmware_release`, `firmware_selector`)
5255

5356
The standalone DNS host belongs to the `dns` group. The DNS play only installs
5457
node_exporter and bind_exporter; it does not manage the existing BIND service,
@@ -129,10 +132,22 @@ Run playbook on all gateways listed in `hosts`:
129132
ansible-playbook --vault-id=fastd_key@prompt setup.yml --limit gateways
130133
```
131134

132-
Run the batman-only service hosts (web-server map-server):
135+
Run both service hosts:
136+
137+
```bash
138+
ansible-playbook --vault-id=fastd_key@prompt setup.yml --limit "services_map:services_web"
139+
```
140+
141+
Run only the map service host:
142+
143+
```bash
144+
ansible-playbook --vault-id=fastd_key@prompt setup.yml --limit services_map
145+
```
146+
147+
Run only the web service host:
133148

134149
```bash
135-
ansible-playbook --vault-id=fastd_key@prompt setup.yml --limit services
150+
ansible-playbook --vault-id=fastd_key@prompt setup.yml --limit services_web
136151
```
137152

138153
Run the monitoring host:

‎hosts.yml‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,16 @@ gateways:
4545
vars:
4646
ansible_user: root
4747

48-
services:
48+
services_map:
4949
hosts:
5050
map-ffsh:
5151
ansible_ssh_host: 116.203.148.80
5252
blackbox_http_url: https://map.freifunk-suedholstein.de/
53+
vars:
54+
ansible_user: root
55+
56+
services_web:
57+
hosts:
5358
web-ffsh:
5459
ansible_ssh_host: 116.203.27.68
5560
blackbox_http_url: https://freifunk-suedholstein.de/

‎roles/firmware_release/tasks/main.yml‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
- name: Skip firmware release helper on non-target hosts
2-
ansible.builtin.meta: end_role
3-
when: inventory_hostname != firmware_release_target_host
4-
51
- name: Install firmware release helper dependencies
62
ansible.builtin.apt:
73
name:

‎roles/firmware_selector/tasks/main.yml‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
- name: Skip firmware selector on non-target hosts
2-
ansible.builtin.meta: end_role
3-
when: inventory_hostname != firmware_selector_target_host
4-
51
- name: Install firmware selector dependency
62
ansible.builtin.apt:
73
name: git

‎roles/grafana_public/tasks/main.yml‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
---
2-
- name: Skip public Grafana on non-map hosts
3-
ansible.builtin.meta: end_role
4-
when: inventory_hostname != "map-ffsh"
5-
61
- name: Install prerequisites for Grafana repository
72
ansible.builtin.apt:
83
name: gnupg

‎roles/grafana_public/templates/grafana.conf.j2‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ server {
2222
ssl_prefer_server_ciphers off;
2323

2424
add_header Strict-Transport-Security "max-age=31536000" always;
25+
add_header Content-Security-Policy "frame-ancestors https://freifunk-suedholstein.de https://*.freifunk-suedholstein.de" always;
2526

2627
location / {
2728
proxy_pass http://127.0.0.1:3000;

‎roles/meshviewer/tasks/main.yml‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
---
2-
- name: Skip meshviewer on non-target hosts
3-
ansible.builtin.meta: end_role
4-
when: inventory_hostname != meshviewer_target_host
5-
61
- name: Install meshviewer dependencies
72
ansible.builtin.apt:
83
name:

‎setup.yml‎

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,67 @@
6666
tags:
6767
- always
6868

69-
- name: Services Deployment
70-
hosts: services
69+
- name: Services Deployment (map)
70+
hosts: services_map
71+
serial: "{{ deploy_serial | default(1) }}"
72+
vars_files:
73+
- group_vars/versions.yml
74+
vars:
75+
users:
76+
- username: root
77+
pre_tasks:
78+
- name: Load shared deployment secrets
79+
ansible.builtin.include_vars:
80+
file: group_vars/secrets.yml
81+
name: vault_secrets
82+
tags:
83+
- always
84+
85+
- name: Abort if target OS is not Ubuntu 24.04
86+
ansible.builtin.assert:
87+
that:
88+
- ansible_facts["distribution"] == "Ubuntu"
89+
- ansible_facts["distribution_version"] == "24.04"
90+
fail_msg: >-
91+
Unsupported target OS: {{ ansible_facts["distribution"] }} {{
92+
ansible_facts["distribution_version"] }}. This playbook supports
93+
Ubuntu 24.04 only.
94+
success_msg: "Target OS check passed: Ubuntu 24.04"
95+
tags:
96+
- always
97+
98+
- name: Update apt cache
99+
ansible.builtin.apt:
100+
update_cache: true
101+
roles:
102+
- {role: batman, tags: "batman-adv"}
103+
- {role: batctl, tags: "batctl"}
104+
- {role: grafana_public, tags: "grafana-public"}
105+
- {role: meshviewer, tags: "meshviewer"}
106+
107+
post_tasks:
108+
- name: Check if reboot is required
109+
ansible.builtin.stat:
110+
path: /var/run/reboot-required
111+
register: system_reboot_required
112+
changed_when: false
113+
tags:
114+
- always
115+
116+
- name: Reboot if required
117+
ansible.builtin.reboot:
118+
msg: Reboot triggered by Ansible because /var/run/reboot-required exists.
119+
reboot_timeout: 900
120+
connect_timeout: 10
121+
post_reboot_delay: 15
122+
when:
123+
- system_reboot_required.stat.exists
124+
- not ansible_check_mode
125+
tags:
126+
- always
127+
128+
- name: Services Deployment (web)
129+
hosts: services_web
71130
serial: "{{ deploy_serial | default(1) }}"
72131
vars_files:
73132
- group_vars/versions.yml
@@ -104,8 +163,6 @@
104163
- {role: firmware_release, tags: "firmware-release"}
105164
- {role: firmware_selector, tags: "firmware-selector"}
106165
- {role: website, tags: "website"}
107-
- {role: grafana_public, tags: "grafana-public"}
108-
- {role: meshviewer, tags: "meshviewer"}
109166

110167
post_tasks:
111168
- name: Check if reboot is required

0 commit comments

Comments
 (0)