Skip to content

Commit a51f022

Browse files
committed
index
1 parent 46dcfb2 commit a51f022

File tree

18 files changed

+859
-80
lines changed

18 files changed

+859
-80
lines changed

COPYING

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 125 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,128 @@
11
# Homelab
22

3-
(quasi) Gitops e IAC
3+
[![documentation](https://img.shields.io/website?label=document&logo=gitbook&logoColor=white&style=flat-square&url=https%3A%2F%2Fhomelab.ildoc.it)](https://homelab.ildoc.it)
4+
[![license](https://img.shields.io/github/license/ildoc/homelab?style=flat-square&logo=gnu&logoColor=white)](https://www.gnu.org/licenses/gpl-3.0.html)
45

5-
[homelab.ildoc.it](https://homelab.ildoc.it)
6+
Questo progetto mira a utilizzare [Infrastructure as Code](https://en.wikipedia.org/wiki/Infrastructure_as_code) e [GitOps](https://www.weave.works/technologies/gitops) per automatizzare il più possibile l'installazione e la configurazione del software che gira sul mio Homelab.
7+
8+
Nel 2020 sono partito da un docker-compose e oggi sono messo così... è un work in progress continuo 😅
9+
10+
> **Che cos'è un homelab?**
11+
>
12+
> Un Homelab è un laboratorio casalingo dove si può fare self-hosting, sperimentare nuove tecnologie, fare pratica per certificazioni e così via.
13+
>
14+
> Per maggiori informazioni fare riferimento alla introduzione di [r/homelab](https://www.reddit.com/r/homelab/wiki/introduction) e alla community Discord [Home Operations](https://discord.gg/home-operations) (ex [k8s-at-home](https://k8s-at-home.com)).
15+
>
16+
> Un ottimo articolo è anche [What is a Homelab and Why Should You Have One?](https://linuxhandbook.com/homelab/)
17+
18+
19+
## Overview generale
20+
21+
Tutto l'Homelab gestito (principalmente) con playbook Ansible, ArgoCD e pipeline Gitlab.
22+
23+
**NOTA:** questo repository GitHub è un mirror del repository originale che si trova sulla mia istanza privata di GitLab
24+
25+
## Tech stack
26+
27+
<table>
28+
<tr>
29+
<th>Logo</th>
30+
<th>Nome</th>
31+
<th>Descrzione</th>
32+
</tr>
33+
<tr>
34+
<td><img width="32" src="https://simpleicons.org/icons/ansible.svg"></td>
35+
<td><a href="https://www.ansible.com">Ansible</a></td>
36+
<td>Automazione di deploy e configurazioni</td>
37+
</tr>
38+
<tr>
39+
<td><img width="32" src="https://avatars.githubusercontent.com/u/30269780"></td>
40+
<td><a href="https://argoproj.github.io/cd">ArgoCD</a></td>
41+
<td>Tool GitOps per deployare su Kubernetes</td>
42+
</tr>
43+
<tr>
44+
<td><img width="32" src="https://github.com/jetstack/cert-manager/raw/master/logo/logo.png"></td>
45+
<td><a href="https://cert-manager.io">cert-manager</a></td>
46+
<td>Cloud native certificate management</td>
47+
</tr>
48+
<tr>
49+
<td><img width="32" src="https://avatars.githubusercontent.com/u/21054566?s=200&v=4"></td>
50+
<td><a href="https://cilium.io">Cilium</a></td>
51+
<td>eBPF-based Networking, Observability e Security (CNI, Network Policy, ecc.)</td>
52+
</tr>
53+
<tr>
54+
<td><img width="32" src="https://avatars.githubusercontent.com/u/314135?s=200&v=4"></td>
55+
<td><a href="https://www.cloudflare.com">Cloudflare</a></td>
56+
<td>Issuer dei certificati e Tunnel</td>
57+
</tr>
58+
<tr>
59+
<td><img width="32" src="https://www.docker.com/wp-content/uploads/2022/03/Moby-logo.png"></td>
60+
<td><a href="https://www.docker.com">Docker</a></td>
61+
<td>Orchestrazione di container con docker compose</td>
62+
</tr>
63+
<tr>
64+
<td><img width="32" src="https://images.ctfassets.net/xz1dnu24egyd/1IRkfXmxo8VP2RAE5jiS1Q/ea2086675d87911b0ce2d34c354b3711/gitlab-logo-500.png"></td>
65+
<td><a href="https://gitlab.com">GitLab</a></td>
66+
<td>Self-hosted Git</td>
67+
</tr>
68+
<tr>
69+
<td><img width="32" src="https://avatars.githubusercontent.com/u/13991055?s=200&v=4"></td>
70+
<td><a href="https://www.hashicorp.com/en/products/vault">HashiCorp Vault</a></td>
71+
<td>Secrets management</td>
72+
</tr>
73+
<tr>
74+
<td><img width="32" src="https://helm.sh/img/helm.svg"></td>
75+
<td><a href="https://helm.sh">Helm</a></td>
76+
<td>Package manager per Kubernetes</td>
77+
</tr>
78+
<tr>
79+
<td><img width="32" src="https://kube-vip.io/images/kube-vip.png"></td>
80+
<td><a href="https://kube-vip.io">kube-vip</a></td>
81+
<td>Virtual IP e load balancer</td>
82+
</tr>
83+
<tr>
84+
<td><img width="32" src="https://avatars.githubusercontent.com/u/13629408"></td>
85+
<td><a href="https://kubernetes.io">Kubernetes</a></td>
86+
<td>Container-orchestration system</td>
87+
</tr>
88+
<tr>
89+
<td><img width="32" src="https://avatars.githubusercontent.com/u/1412239?s=200&v=4"></td>
90+
<td><a href="https://www.nginx.com">NGINX</a></td>
91+
<td>Reverse Proxy</td>
92+
</tr>
93+
<tr>
94+
<td><img width="32" src="https://wp-cdn.pi-hole.net/wp-content/uploads/2016/12/Vortex-R.png"></td>
95+
<td><a href="https://pi-hole.net/">Pi-hole</a></td>
96+
<td>Ad blocker, DNS e DHCP</td>
97+
</tr>
98+
<tr>
99+
<td><img width="32" src="https://avatars.githubusercontent.com/u/13991055?s=200&v=4"></td>
100+
<td><a href="https://www.proxmox.com">Proxmox</a></td>
101+
<td>Virtualizzazione di VM e LXC</td>
102+
</tr>
103+
<tr>
104+
<td><img width="32" src="https://docs.renovatebot.com/assets/images/logo.png"></td>
105+
<td><a href="https://docs.renovatebot.com/">Renovate</a></td>
106+
<td>Update automatico delle dipendenze</td>
107+
</tr>
108+
<tr>
109+
<td><img width="32" src="https://avatars.githubusercontent.com/u/14280338?s=200&v=4"></td>
110+
<td><a href="https://doc.traefik.io/traefik/">Traefik</a></td>
111+
<td>Kubernetes Ingress Controller</td>
112+
</tr>
113+
<tr>
114+
<td><img width="32" src="https://avatars.githubusercontent.com/u/53482242?s=200&v=4"></td>
115+
<td><a href="https://www.truenas.com/">TrueNAS</a></td>
116+
<td>NFS share, Backup</td>
117+
</tr>
118+
<tr>
119+
<td><img width="32" src="https://upload.wikimedia.org/wikipedia/commons/1/16/Ubuntu_and_Ubuntu_Server_Icon.png"></td>
120+
<td><a href="https://ubuntu.com/server">Ubuntu Server</a></td>
121+
<td>Os di base per i nodi Kubernetes</td>
122+
</tr>
123+
<tr>
124+
<td><img width="32" src="https://avatars.githubusercontent.com/u/13991055?s=200&v=4"></td>
125+
<td><a href="https://www.wireguard.com">Wireguard</a></td>
126+
<td>VPN tunnel</td>
127+
</tr>
128+
</table>

ansible/roles/gitlab/tasks/certbot.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
- name: Creare cartella certbot
1+
- name: Create certbot folder
22
ansible.builtin.file:
33
path: ~/certbot
44
state: directory
@@ -41,9 +41,9 @@
4141
dest: "~/gitlab/renew-cert.sh"
4242
mode: '0755'
4343

44-
- name: Schedula lo script di rinnovo del certificato
44+
- name: Schedule certificate renew script
4545
ansible.builtin.cron:
46-
name: "Rinnovo certificato {{ gitlab.domain }}"
46+
name: "Renew cert {{ gitlab.domain }}"
4747
minute: "0"
4848
hour: "*/12"
4949
job: "/home/{{ ansible_user }}/gitlab/renew-cert.sh"

ansible/roles/gitlab/tasks/main.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
- name: Install docker
22
ansible.builtin.include_tasks: "{{ tasks_dir }}/docker/install.yaml"
3+
34
- name: Setup GitLab
45
ansible.builtin.include_tasks: setup_gitlab.yaml
56

ansible/roles/gitlab/tasks/nginx.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
- name: Creare cartella nginx
1+
- name: Create nginx folder
22
ansible.builtin.file:
33
path: ~/nginx
44
state: directory
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,81 @@
1-
- name: Creare cartella data
1+
- name: Create data folder
22
ansible.builtin.file:
33
path: ~/gitlab/data
44
state: directory
55
mode: '0755'
66
recurse: true
77

8-
- name: Creare cartella config
8+
- name: Create config folder
99
ansible.builtin.file:
1010
path: ~/gitlab/config
1111
state: directory
1212
mode: '0755'
1313
recurse: true
1414

15-
- name: Creare cartella logs
15+
- name: Create logs folder
1616
ansible.builtin.file:
1717
path: ~/gitlab/logs
1818
state: directory
1919
mode: '0755'
2020
recurse: true
2121

22-
- name: Creare cartella runnerconfig
22+
- name: Create runnerconfig folder
2323
ansible.builtin.file:
2424
path: ~/runner
2525
state: directory
2626
mode: '0755'
2727

28-
- name: Copia entrypoint con permessi eseguibili
28+
- name: Copy entrypoint.sh
2929
ansible.builtin.copy:
3030
src: "{{ gitlab_files_path }}/entrypoint.sh"
3131
dest: ~/gitlab/entrypoint.sh
3232
mode: '0755'
3333

34-
- name: Valorizza variabili
34+
- name: Set variables
3535
ansible.builtin.set_fact:
3636
remote_path: ~/docker-compose.yml
3737
local_path: "{{ gitlab_files_path }}/docker-compose.yml"
3838
project_path: .
3939

40-
- name: Includi update docker docker-compose
40+
- name: Include update docker-compose
4141
ansible.builtin.include_tasks: "{{ tasks_dir }}/docker/update-compose.yaml"
4242
vars:
4343
update_compose_remote_path: "{{ remote_path }}"
4444
update_compose_local_path: "{{ local_path }}"
4545
update_compose_project_path: "{{ project_path }}"
4646

47-
- name: Leggi il gitlab.rb remoto
47+
- name: Get remote gitlab.rb
4848
ansible.builtin.stat:
4949
path: ~/gitlab/config/gitlab.rb
5050
register: remote_gitlab_rb
5151

52-
- name: Leggi il contenuto del file remoto
52+
- name: Read remote file content
5353
ansible.builtin.slurp:
5454
src: ~/gitlab/config/gitlab.rb
5555
register: remote_gitlab_rb_content
5656
when: remote_gitlab_rb.stat.exists
5757

58-
- name: Rendi template come stringa
58+
- name: Render templates as string
5959
ansible.builtin.set_fact:
6060
gitlab_rb_template_rendered: "{{ lookup('template', gitlab_templates_path + 'gitlab.rb.j2') }}"
6161

62-
- name: Confronta contenuti testuali
62+
- name: Check text differences
6363
ansible.builtin.set_fact:
6464
gitlab_rb_different: >
6565
{{ (remote_gitlab_rb_content.content | b64decode).strip() != gitlab_rb_template_rendered.strip() }}
6666
67-
- name: Sono diversi?
67+
- name: Are they different?
6868
ansible.builtin.debug:
6969
msg: "{{ gitlab_rb_different }}"
7070

71-
- name: Esegui azioni Docker se il file è stato copiato o è diverso
71+
- name: Actions to do if files are different
7272
when: gitlab_rb_different
7373
block:
74-
- name: Copia gitlab.rb
74+
- name: Copy gitlab.rb
7575
ansible.builtin.template:
7676
src: gitlab.rb.j2
7777
dest: ~/gitlab/config/gitlab.rb
7878
mode: '0644'
7979

80-
- name: Esegui il reconfigure di GitLab
80+
- name: Reconfigure GitLab
8181
ansible.builtin.command: docker exec -t gitlab gitlab-ctl reconfigure

ansible/roles/gitlab/templates/gitlab.rb.j2

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@ external_url 'https://{{ gitlab.domain }}'
77

88
registry_external_url 'https://registry.{{ gitlab.domain }}'
99

10-
# Disabilita nginx interno del registry se usi nginx esterno (es: con docker)
1110
registry['enable'] = true
1211
registry['registry_http_addr'] = "0.0.0.0:5000"
1312

14-
# Usa il certificato Let's Encrypt già usato da nginx
1513
registry_nginx['enable'] = false
1614

1715
nginx['worker_processes'] = 2
Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,61 @@
11
#!/bin/bash
22
set -euo pipefail
33

4-
# CONFIGURAZIONE
4+
# CONFIGURATIONS
55
POLICY_NAME="ansible-policy"
66
ROLE_NAME="ansible-role"
7-
SECRET_PATH="ansible" # sarà montato come kv-v2
7+
SECRET_PATH="ansible"
88
VAULT_ADDR="${VAULT_ADDR:-http://127.0.0.1:8200}"
99
VAULT_TOKEN="${VAULT_TOKEN:?VAULT_TOKEN mancante}"
1010

11+
# Install dependencies
1112
apk add jq
1213

13-
echo "🟡 Inizializzazione Vault..."
14+
echo "[+] Init Vault..."
1415

15-
# Check se il secret engine è già abilitato
16+
# Check if secret engine is already enabled
1617
if vault secrets list -format=json | jq -e ".[\"$SECRET_PATH/\"]"; then
17-
echo " Secret engine '$SECRET_PATH/' già abilitato."
18+
echo "[+] Secret engine '$SECRET_PATH/' already enabled."
1819
else
19-
echo "➕ Abilitazione secret engine '$SECRET_PATH/' (kv-v2)..."
20+
echo "[+] Enabling secret engine '$SECRET_PATH/' (kv-v2)..."
2021
vault secrets enable -path="$SECRET_PATH" -version=2 kv
2122
fi
2223

23-
# Check se l'auth method approle è già abilitato
24+
# Check if Approle auth method is already enabled
2425
if vault auth list -format=json | jq -e '."approle/"'; then
25-
echo " Auth method AppRole già abilitato."
26+
echo "[+] Auth method AppRole already enabled."
2627
else
27-
echo "➕ Abilitazione auth method AppRole..."
28+
echo "[+] Enabling auth method AppRole..."
2829
vault auth enable approle
2930
fi
3031

31-
# Crea o aggiorna la policy
32-
echo "📜 Scrittura policy '$POLICY_NAME'..."
32+
# Create or update policy
33+
echo "[+] Writing policy '$POLICY_NAME'..."
3334
cat <<EOF | vault policy write "$POLICY_NAME" -
3435
path "$SECRET_PATH/data/*" {
3536
capabilities = ["create", "read", "update", "delete", "list"]
3637
}
3738
EOF
3839

39-
# Check se il ruolo esiste già
40+
# Check if role is already created
4041
if vault read -format=json "auth/approle/role/$ROLE_NAME" > /dev/null 2>&1; then
41-
echo "✅ Ruolo AppRole '$ROLE_NAME' già esistente."
42+
echo "[+] Role AppRole '$ROLE_NAME' already existing."
4243
else
43-
echo "➕ Creazione ruolo AppRole '$ROLE_NAME'..."
44+
echo "[+] Creating role AppRole '$ROLE_NAME'..."
4445
vault write "auth/approle/role/$ROLE_NAME" \
4546
token_policies="$POLICY_NAME" \
4647
token_ttl="3600" \
4748
token_max_ttl="7200"
4849
fi
4950

50-
# Recupera role_id (fisso per il ruolo)
51+
# Get role_id (fixed for the role)
5152
ROLE_ID=$(vault read -field=role_id "auth/approle/role/$ROLE_NAME/role-id")
5253

53-
# Crea un nuovo secret_id (questo è sempre one-time-use)
54+
# Create new secret_id (this is always one-time-use)
5455
SECRET_ID=$(vault write -f -field=secret_id "auth/approle/role/$ROLE_NAME/secret-id")
5556

5657
# Output
5758
echo ""
58-
echo " AppRole configurato con successo:"
59+
echo "[+] AppRole successfully configured:"
5960
echo "export VAULT_ROLE_ID=\"$ROLE_ID\""
6061
echo "export VAULT_SECRET_ID=\"$SECRET_ID\""

ansible/roles/vault/files/vault-config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
{
22
"ui": true,
33
"disable_mlock": true,
4-
"api_addr":"https://127.0.0.1:8200",
4+
"api_addr":"http://127.0.0.1:8200",
55

66
"storage": {
77
"file": {
88
"path": "/vault/file"
99
}
1010
},
11+
1112
"listener": {
1213
"tcp": {
1314
"address": "0.0.0.0:8200",

0 commit comments

Comments
 (0)