Compare commits

69 Commits

Author SHA1 Message Date
629be846af Update Terraform hcloud to v1.50.0
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2025-02-26 02:07:50 +00:00
b15eaa7c7f Update golang Docker tag to v1.24
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2025-02-13 02:13:02 +00:00
312394af74 Update Terraform hcloud to v1.49.1
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2024-11-22 02:00:57 +00:00
2c6c74fe73 Update all dependencies
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2024-08-21 21:40:11 +00:00
0f995dadbd Update Terraform hcloud to v1.47.0
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2024-05-03 16:11:47 +00:00
862278c419 Update Terraform hcloud to v1.46.1
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2024-04-08 09:27:31 +00:00
4dbb2a1573 Update golang Docker tag to v1.22
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2024-02-10 10:36:12 +00:00
f3bd1f0ee8 Update Terraform hcloud to v1.45.0
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2024-01-11 17:24:55 +00:00
18bde2e1b9 Update Terraform hcloud to v1.44.1
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2023-10-05 08:37:38 +00:00
722793830b Update Terraform hcloud to v1.44.0
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2023-10-04 11:16:04 +00:00
b56c0edd1f Update Terraform hcloud to v1.43.0
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2023-09-20 11:15:00 +00:00
6c0d57b60e Update Terraform hcloud to v1.42.1
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2023-08-14 13:55:59 +00:00
d0ad44a8e8 Update all dependencies
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2023-08-08 21:49:25 +00:00
754368ffce Merge pull request 'Update Terraform hcloud to v1.41.0' (#17) from renovate/all into main
All checks were successful
continuous-integration/drone/push Build is passing
2023-06-22 11:31:37 +00:00
3796dcce50 Update Terraform hcloud to v1.38.2
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2023-04-15 11:35:54 +00:00
eb0db5f633 Update Terraform hcloud to v1.38.1
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2023-04-13 10:52:33 +00:00
383f2c76fb Update Terraform hcloud to v1.38.0
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2023-04-12 15:36:55 +00:00
a866be86f1 Update Terraform hcloud to v1.37.0
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2023-03-28 14:08:39 +00:00
1ecfc17231 Update golang Docker tag to v1.20
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2023-02-10 18:21:15 +00:00
a76d9813bd Update Terraform hcloud to v1.36.2
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2022-12-23 16:12:50 +00:00
faf93e7eb5 Update all dependencies to v2.7.0
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2022-11-11 09:09:26 +00:00
f1494b1817 Update Terraform hcloud to v1.36.0
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2022-11-09 16:16:50 +00:00
44ad0306a9 Merge pull request 'Update all dependencies' (#7) from renovate/all into main
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: https://git.front.kjuulh.io/kjuulh/serverctl/pulls/7
2022-10-27 19:58:38 +00:00
467993dee3 with updated drone
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
2022-10-27 21:58:23 +02:00
e6b3321c2a Update all dependencies
Some checks failed
continuous-integration/drone/pr Build is failing
continuous-integration/drone/push Build is failing
2022-10-27 06:31:33 +00:00
140067aa15 Merge pull request 'Configure Renovate' (#1) from renovate/configure into main
Some checks failed
continuous-integration/drone Build is failing
Reviewed-on: https://git.front.kjuulh.io/kjuulh/serverctl/pulls/1
2022-10-25 21:01:17 +00:00
8d4f4c9ab6 Add renovate.json 2022-10-25 20:59:55 +00:00
4d8a40fe8e Update 'infrastructure/create-resources/hcloud.tf'
All checks were successful
continuous-integration/drone/push Build is passing
2022-03-08 15:27:29 +01:00
e48e6f0c3d Update 'infrastructure/create-resources/hcloud.tf'
All checks were successful
continuous-integration/drone/push Build is passing
2022-03-08 15:23:11 +01:00
1f7b711048 Remove debug
Some checks failed
continuous-integration/drone/push Build is failing
2022-03-01 21:54:58 +01:00
e014270903 Kill servers
All checks were successful
continuous-integration/drone/push Build is passing
2022-02-24 22:00:24 +01:00
5c9f96be8e Add homeserver to infra
All checks were successful
continuous-integration/drone/push Build is passing
2022-02-24 21:36:07 +01:00
9eaca5ae11 with correct variables
All checks were successful
continuous-integration/drone/push Build is passing
2022-02-24 14:10:49 +01:00
1cb55b1fb3 fix template
Some checks failed
continuous-integration/drone/push Build is failing
2022-02-24 14:09:13 +01:00
ecc2e332da Trying with cluster
Some checks failed
continuous-integration/drone/push Build is failing
2022-02-24 14:07:27 +01:00
ede5600da5 Nulled hosts
All checks were successful
continuous-integration/drone/push Build is passing
2022-02-24 14:05:55 +01:00
b4ee531a81 Merged configs
Some checks failed
continuous-integration/drone/push Build is failing
2022-02-24 14:03:42 +01:00
1663a469c2 Add wireguard
All checks were successful
continuous-integration/drone/push Build is passing
2022-02-24 13:57:19 +01:00
5f301ce32a Take down servers
All checks were successful
continuous-integration/drone/push Build is passing
2022-02-19 22:11:50 +01:00
4356588131 Add node
All checks were successful
continuous-integration/drone/push Build is passing
2022-02-19 22:07:04 +01:00
1f286384c2 Add master
All checks were successful
continuous-integration/drone/push Build is passing
2022-02-19 22:03:37 +01:00
d74cdfa143 destroy all
All checks were successful
continuous-integration/drone/push Build is passing
2022-02-19 22:01:46 +01:00
baae7a8d7e Reduce amount of servers
All checks were successful
continuous-integration/drone/push Build is passing
2022-02-19 21:35:09 +01:00
4da3293569 Add nodes
All checks were successful
continuous-integration/drone/push Build is passing
2022-02-19 21:29:38 +01:00
4ee8043bb8 Add k3s to ansible
All checks were successful
continuous-integration/drone/push Build is passing
2022-02-19 21:22:14 +01:00
c50547c2fb set create before destory
All checks were successful
continuous-integration/drone/push Build is passing
2022-02-19 20:23:54 +01:00
44323ef46b Fix user
All checks were successful
continuous-integration/drone/push Build is passing
2022-02-19 20:21:14 +01:00
7d868cbd60 Add back host key checking
Some checks failed
continuous-integration/drone/push Build is failing
2022-02-19 20:18:35 +01:00
11efe45f77 removed hosts file
Some checks failed
continuous-integration/drone/push Build is failing
2022-02-19 20:14:36 +01:00
f2c81dc9ac Add ansible for k3s
Some checks failed
continuous-integration/drone/push Build is failing
2022-02-19 20:11:28 +01:00
ecc308735c Add pub key
All checks were successful
continuous-integration/drone/push Build is passing
2022-02-19 18:22:44 +01:00
e0c93087ea add hosts
Some checks failed
continuous-integration/drone/push Build is failing
2022-02-19 18:21:04 +01:00
e5726cf742 Remove ansible from terraform
All checks were successful
continuous-integration/drone/push Build is passing
2022-02-19 18:19:26 +01:00
170c5e0730 Add ansible to pipeline
Some checks failed
continuous-integration/drone/push Build is failing
2022-02-19 18:18:19 +01:00
81abb30846 Update path for ansible-playbook
All checks were successful
continuous-integration/drone/push Build is passing
2022-02-18 16:41:33 +01:00
97ab34737d removed debugging and added ansible to pipeline
Some checks failed
continuous-integration/drone/push Build is failing
2022-02-18 16:37:15 +01:00
23358515b8 removed excess strings
Some checks failed
continuous-integration/drone/push Build is failing
2022-02-18 16:35:28 +01:00
1870a78fde Fix env variable for secret
Some checks failed
continuous-integration/drone/push Build is failing
2022-02-18 16:33:30 +01:00
fad6e517e5 Add key id to secrets
Some checks failed
continuous-integration/drone/push Build is failing
2022-02-18 16:30:26 +01:00
9eba0f9042 fix name of unzip file
Some checks failed
continuous-integration/drone/push Build is failing
2022-02-18 16:28:10 +01:00
8441f85f88 fix path
Some checks failed
continuous-integration/drone/push Build is failing
2022-02-18 16:27:38 +01:00
42a6110e3c Add zip keys
Some checks failed
continuous-integration/drone/push Build is failing
2022-02-18 16:26:35 +01:00
e9671cbe81 Always run ansible
Some checks failed
continuous-integration/drone/push Build is failing
2022-02-18 15:50:37 +01:00
662ce1b1a5 Add setup-terraform
All checks were successful
continuous-integration/drone/push Build is passing
2022-02-17 22:15:08 +01:00
8cfa0fb4d9 Reduce amount of servers
All checks were successful
continuous-integration/drone/push Build is passing
2022-02-17 22:10:47 +01:00
2b85b7db66 Add secrets to gitignore
All checks were successful
continuous-integration/drone/push Build is passing
2022-02-17 22:10:27 +01:00
4544292114 WIP: var
All checks were successful
continuous-integration/drone/push Build is passing
2022-02-17 22:08:26 +01:00
6eaeb601bd Add apply
Some checks failed
continuous-integration/drone/push Build is failing
2022-02-17 22:06:59 +01:00
5e20237572 Add apply 2022-02-17 22:06:32 +01:00
37 changed files with 707 additions and 66 deletions

View File

@@ -1,23 +1,36 @@
type: docker
kind: pipeline
name: Serverctl
steps:
- name: terraform plan
image: alpine
environment:
HCLOUD_TOKEN:
from_secret: serverctl_hcloud_token
ACCESS_KEY:
from_secret: serverctl_access_key
SECRET_KEY:
from_secret: serverctl_secret_key
- name: test
image: harbor.front.kjuulh.io/docker-proxy/library/bash:latest
commands:
- apk --update add curl
- curl --silent --output terraform.zip "https://releases.hashicorp.com/terraform/1.1.6/terraform_1.1.6_linux_amd64.zip"
- unzip terraform.zip ; rm -f terraform.zip; chmod +x terraform
- mkdir -p ${HOME}/bin ; export PATH=${PATH}:${HOME}/bin; mv terraform ${HOME}/bin/
- terraform -v
- cd infrastructure/create-resources
- terraform init -backend-config="access_key=$ACCESS_KEY" -backend-config="secret_key=$SECRET_KEY"
- terraform validate
- terraform plan -vars="hcloud_token=$HCLOUD_TOKEN"
- echo 'Run tests'
#
# - name: terraform plan
# image: alpine
# environment:
# HCLOUD_TOKEN:
# from_secret: serverctl_hcloud_token
# ACCESS_KEY:
# from_secret: serverctl_access_key
# SECRET_KEY:
# from_secret: serverctl_secret_key
# SSH_ZIP_KEY:
# from_secret: serverctl_ssh_zip_key
# HCLOUD_SSH_KEY_ID:
# from_secret: serverctl_hcloud_ssh_key_id
# commands:
# - apk --update add curl zip ansible python3
# - cd infrastructure && ./unzip-ssh-keys.sh "$SSH_ZIP_KEY" && cd ..
# - curl --silent --output terraform.zip "https://releases.hashicorp.com/terraform/1.1.6/terraform_1.1.6_linux_amd64.zip"
# - unzip terraform.zip ; rm -f terraform.zip; chmod +x terraform
# - mkdir -p ${HOME}/bin ; export PATH=${PATH}:${HOME}/bin; mv terraform ${HOME}/bin/
# - terraform -v
# - cd infrastructure/create-resources
# - terraform init -backend-config="access_key=$ACCESS_KEY" -backend-config="secret_key=$SECRET_KEY"
# - terraform validate
# - terraform apply -auto-approve -var "hcloud_token=$HCLOUD_TOKEN" -var "pvt_key=../ssh_keys/id_ed25519" -var "pub_key=../ssh_keys/id_ed25519.pub" -var "hcloud_serverctl_ssh_key_id=$HCLOUD_SSH_KEY_ID"
# - cd ansible
# - ANSIBLE_HOST_KEY_CHECKING=False /usr/bin/ansible-playbook -u root --key-file '../../ssh_keys/id_ed25519' -e 'pub_key=../../ssh_keys/id_ed25519.pub' site.yml

View File

@@ -55,7 +55,7 @@ services:
# Logging
loki:
image: grafana/loki:2.4.2
image: grafana/loki:2.7.0
ports:
- 3100
networks:
@@ -66,7 +66,7 @@ services:
logging: *loki-logging
promtail:
image: grafana/promtail:2.4.2
image: grafana/promtail:2.7.0
volumes:
- ./services/logs/promtail/config.yaml:/mnt/config/promtail-config.yaml
- /var/lib/docker/containers:/host/containers

1
infrastructure/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
ssh_keys/

View File

@@ -3,3 +3,5 @@
.terraform.lock.hcl
terraform.tfstate
terraform.tfstate.backup
secrets.txt
.env

View File

@@ -0,0 +1,9 @@
---
extends: default
rules:
line-length:
max: 120
level: warning
truthy:
allowed-values: ['true', 'false', 'yes', 'no']

View File

@@ -0,0 +1,12 @@
[defaults]
nocows = True
roles_path = ./roles
inventory = ./inventory/hosts.cfg
remote_tmp = $HOME/.ansible/tmp
local_tmp = $HOME/.ansible/tmp
pipelining = True
become = True
host_key_checking = False
deprecation_warnings = True
callback_whitelist = profile_tasks

View File

@@ -0,0 +1,3 @@
---
collections:
- name: community.general

View File

@@ -0,0 +1,15 @@
---
k3s_version: v1.22.3+k3s1
ansible_user: root
systemd_dir: /etc/systemd/system
systemd_network_dir: /etc/systemd/network
master_ip: "{{ hostvars[groups['serverctl_master_hosts'][0]]['wireguard_ip'] | default(groups['serverctl_master_hosts'][0]) }}"
extra_server_args: "--flannel-iface=serverctl-wg0"
extra_agent_args: "--flannel-iface=serverctl-wg0"
ansible_become_method: su
ufw_enabled: true
wireguard_mask_bits: 24
wireguard_port: 51871

View File

@@ -0,0 +1,32 @@
[serverctl_master_hosts]
95.217.155.228 ansible_host=95.217.155.228 wireguard_ip=10.1.1.1
[serverctl_node_hosts]
65.21.50.146 ansible_host=65.21.50.146 wireguard_ip=10.1.1.10
95.216.162.16 ansible_host=95.216.162.16 wireguard_ip=10.1.1.11
[serverctl_home_servers]
192.168.1.150 ansible_host=192.168.1.150 wireguard_ip=10.1.1.8
#192.168.1.233 ansible_host=192.168.1.233 wireguard_ip=10.1.1.9
[serverctl_cluster:children]
serverctl_master_hosts
serverctl_node_hosts
[serverctl_super_cluster:children]
serverctl_cluster
serverctl_home_servers
[serverctl_home_servers:vars]
client_server=True
[serverctl_super_cluster:vars]
pipelining=true
ansible_ssh_user=root
ansible_ssh_port=22
[serverctl_cluster:vars]
client_server=False
pipelining=true
ansible_ssh_user=root
ansible_ssh_port=22

View File

@@ -0,0 +1,8 @@
- hosts: serverctl_master_hosts[0]
become: yes
tasks:
- name: Fetch kubeconfig
ansible.builtin.fetch:
src: ~/.kube/config
dest: temp/.kube/config

View File

@@ -0,0 +1,7 @@
---
- hosts: serverctl_super_cluster
gather_facts: yes
tasks:
- name: ping
command: "ping -c3 {{ hostvars[item].wireguard_ip}}"
with_items: "{{groups['all']}}"

View File

@@ -0,0 +1,10 @@
---
- name: Download k3s binary x64
get_url:
url: https://github.com/k3s-io/k3s/releases/download/{{ k3s_version }}/k3s
checksum: sha256:https://github.com/k3s-io/k3s/releases/download/{{ k3s_version }}/sha256sum-amd64.txt
dest: /usr/local/bin/k3s
owner: root
group: root
mode: 0755
when: ansible_facts.architecture == "x86_64"

View File

@@ -0,0 +1,67 @@
---
- name: update packages
apt:
update_cache: yes
cache_valid_time: 3600
become: yes
- name: install ufw
apt:
name: ufw
state: present
become: yes
when: ufw_enabled
- name: Allow SSH in UFW
ufw:
rule: allow
port: "{{ ansible_ssh_port }}"
proto: tcp
become: yes
when: ufw_enabled
- name: Allow wireguard port in UFW
ufw:
rule: allow
port: "{{ wireguard_port }}"
proto: udp
become: yes
when: ufw_enabled
- name: Set ufw logging
ufw:
logging: "on"
become: yes
when: ufw_enabled
- name: inter-node Wireguard UFW connectivity
ufw:
rule: allow
src: "{{ hostvars[item].wireguard_ip }}"
with_items: "{{ groups['all'] }}"
become: yes
when: ufw_enabled and item != inventory_hostname
- name: Reject everything and enable UFW
ufw:
state: enabled
policy: reject
log: yes
become: yes
when: ufw_enabled
- name: Allow 6443 in UFW /tcp
ufw:
rule: allow
port: "6443"
proto: tcp
become: yes
when: ufw_enabled
- name: Allow 6443 in UFW udp
ufw:
rule: allow
port: "6443"
proto: udp
become: yes
when: ufw_enabled

View File

@@ -0,0 +1,2 @@
---
k3s_server_location: /var/lib/rancher/k3s

View File

@@ -0,0 +1,79 @@
---
- name: Copy K3s service file
register: k3s_service
template:
src: "k3s.service.j2"
dest: "{{ systemd_dir }}/k3s.service"
owner: root
group: root
mode: 0644
- name: Enable and check K3s service
systemd:
name: k3s
daemon_reload: yes
state: restarted
enabled: yes
- name: Wait for node-token
wait_for:
path: "{{ k3s_server_location }}/server/node-token"
- name: Register node-token file access mode
stat:
path: "{{ k3s_server_location }}/server/node-token"
register: p
- name: Change file access node-token
file:
path: "{{ k3s_server_location }}/server/node-token"
mode: "g+rx,o+rx"
- name: Read node-token from master
slurp:
path: "{{ k3s_server_location }}/server/node-token"
register: node_token
- name: Store Master node-token
set_fact:
token: "{{ node_token.content | b64decode | regex_replace('\n', '') }}"
- name: Restore node-token file access
file:
path: "{{ k3s_server_location }}/server/node-token"
mode: "{{ p.stat.mode }}"
- name: Create directory .kube
file:
path: ~{{ ansible_user }}/.kube
state: directory
owner: "{{ ansible_user }}"
mode: "u=rwx,g=rx,o="
- name: Copy config file to user home directory
copy:
src: /etc/rancher/k3s/k3s.yaml
dest: ~{{ ansible_user }}/.kube/config
remote_src: yes
owner: "{{ ansible_user }}"
mode: "u=rw,g=,o="
- name: Replace https://localhost:6443 by https://master-ip:6443
command: >-
k3s kubectl config set-cluster default
--server=https://{{ master_ip }}:6443
--kubeconfig ~{{ ansible_user }}/.kube/config
changed_when: true
- name: Create kubectl symlink
file:
src: /usr/local/bin/k3s
dest: /usr/local/bin/kubectl
state: link
- name: Create crictl symlink
file:
src: /usr/local/bin/k3s
dest: /usr/local/bin/crictl
state: link

View File

@@ -0,0 +1,24 @@
[Unit]
Description=Lightweight Kubernetes
Documentation=https://k3s.io
After=network-online.target
[Service]
Type=notify
ExecStartPre=-/sbin/modprobe br_netfilter
ExecStartPre=-/sbin/modprobe overlay
ExecStart=/usr/local/bin/k3s server --data-dir {{ k3s_server_location }} {{ extra_server_args | default("") }} --advertise-address {{master_ip}}
KillMode=process
Delegate=yes
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=1048576
LimitNPROC=infinity
LimitCORE=infinity
TasksMax=infinity
TimeoutStartSec=0
Restart=always
RestartSec=5s
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1,15 @@
---
- name: Copy K3s service file
template:
src: "k3s.service.j2"
dest: "{{ systemd_dir }}/k3s-node.service"
owner: root
group: root
mode: 0755
- name: Enable and check K3s service
systemd:
name: k3s-node
daemon_reload: yes
state: restarted
enabled: yes

View File

@@ -0,0 +1,24 @@
[Unit]
Description=Lightweight Kubernetes
Documentation=https://k3s.io
After=network-online.target
[Service]
Type=notify
ExecStartPre=-/sbin/modprobe br_netfilter
ExecStartPre=-/sbin/modprobe overlay
ExecStart=/usr/local/bin/k3s agent --server https://{{ master_ip }}:6443 --token {{ hostvars[groups['serverctl_master_hosts'][0]]['token'] }} {{ extra_agent_args | default("") }} --node-ip {{inventory_hostname}}
KillMode=process
Delegate=yes
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=1048576
LimitNPROC=infinity
LimitCORE=infinity
TasksMax=infinity
TimeoutStartSec=0
Restart=always
RestartSec=5s
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1,18 @@
---
- name: Enable IPv4 forwarding
sysctl:
name: net.ipv4.ip_forward
value: "1"
state: present
reload: yes
- name: Enable IPv6 forwarding
sysctl:
name: net.ipv6.conf.all.forwarding
value: "1"
state: present
reload: yes
when: ansible_all_ipv6_addresses
- name: Wait for apt to unlock
shell: while sudo fuser /var/lib/dpkg/lock >/dev/null >2&1; do sleep 5; done;

View File

@@ -0,0 +1,7 @@
---
- name: systemd network restart
service:
name: systemd-networkd
state: restarted
enabled: yes
become: yes

View File

@@ -0,0 +1,89 @@
---
- name: install wireguard
apt:
name: wireguard
state: present
become: yes
when: ansible_distribution == 'Debian' or ansible_distribution == "Ubuntu"
- name: install wireguard
pacman:
name: wireguard-tools
state: present
become: yes
when: ansible_distribution == "Archlinux"
- name: generate wireguard keypair
shell: wg genkey | tee /etc/wireguard/serverctl-privatekey | wg pubkey | tee /etc/wireguard/serverctl-publickey
args:
creates: /etc/wireguard/serverctl-privatekey
become: yes
- name: register private key
shell: cat /etc/wireguard/serverctl-privatekey
register: wireguard_private_key
changed_when: false
become: yes
- name: register public key
shell: cat /etc/wireguard/serverctl-publickey
register: wireguard_public_key
changed_when: false
become: yes
- name: generate preshared keypair
shell: "wg genpsk > /etc/wireguard/serverctl-psk-{{item}}"
args:
creates: "/etc/wireguard/serverctl-psk-{{item}}"
when: inventory_hostname < item
with_items: "{{groups['serverctl_super_cluster']}}"
become: yes
- name: register preshared key
shell: "cat /etc/wireguard/serverctl-psk-{{item}}"
register: wireguard_preshared_key
changed_when: false
when: inventory_hostname < item
with_items: "{{groups['serverctl_super_cluster']}}"
become: yes
- name: message preshared keys
set_fact: "wireguard_preshared_keys={{wireguard_preshared_keys|default({}) | combine({item.item: item.stdout})}}"
when: item.skipped is not defined
with_items: "{{wireguard_preshared_key.results}}"
become: yes
#- name: print hostvars
# ansible.builtin.debug:
# msg: "{{hostvars[item]}}"
# with_items: "{{groups['serverctl_super_cluster']}}"
- name: Setup wg0 device
template:
src: 'systemd.netdev'
dest: '{{systemd_network_dir}}/99-serverctl-wg0.netdev'
owner: root
group: systemd-network
mode: 0640
become: yes
notify: systemd network restart
- name: Setup wg0 network
template:
src: 'systemd.network'
dest: "{{systemd_network_dir}}/99-serverctl-wg0.network"
owner: root
group: systemd-network
mode: 0640
become: yes
notify: systemd network restart
#- name: Start and enalbe wireguard on book
# systemd:
# name: wg-quick@wgserverctl0
# enabled: yes
# state: started
#- debug: msg="{{item.1}} - {{ (wireguard_base_ipv4|ipaddr(item.0 + 1)) }}"
# with_indexed_items: "{{groups.serverctl_mesh_nodes}}"

View File

@@ -0,0 +1,22 @@
[NetDev]
Name=serverctl-wg0
Kind=wireguard
Description=WireGuard tunnel serverctl-wg0
[WireGuard]
ListenPort={{ wireguard_port }}
PrivateKey={{ wireguard_private_key.stdout }}
{% for peer in groups['serverctl_super_cluster'] %}
{% if peer != inventory_hostname %}
[WireGuardPeer]
PublicKey={{ hostvars[peer].wireguard_public_key.stdout }}
PresharedKey={{ wireguard_preshared_keys[peer] if inventory_hostname < peer else hostvars[peer].wireguard_preshared_keys[inventory_hostname] }}
AllowedIPs={{ hostvars[peer].wireguard_ip }}/32
{% if not hostvars[peer].client_server %}
Endpoint={{ hostvars[peer].ansible_host }}:{{ wireguard_port }}
PersistentKeepalive=25
{% endif %}
{% endif %}
{% endfor %}

View File

@@ -0,0 +1,5 @@
[Match]
Name=serverctl-wg0
[Network]
Address={{ wireguard_ip }}/{{ wireguard_mask_bits }}

View File

@@ -0,0 +1,16 @@
- become: yes
hosts: all
name: server-install
tasks:
- name: Add the user 'kjuulh' and add it to 'sudo'
user:
name: kjuulh
group: sudo
- name:
authorized_key:
user: kjuulh
state: present
key: "{{ lookup('file', pub_key) }}"
- name: Wait for apt to unlock
become: yes
shell: while sudo fuser /var/lib/dpkg/lock >/dev/null >2&1; do sleep 5; done;

View File

@@ -0,0 +1,25 @@
---
- hosts: serverctl_cluster
gather_facts: yes
become: yes
roles:
- role: prereq
- role: download
- role: firewall
- hosts: serverctl_super_cluster
gather_facts: yes
become: yes
roles:
- role: wireguard/mesh
- hosts: serverctl_master_hosts
become: yes
roles:
- role: "./k3s/master"
- hosts: serverctl_node_hosts
become: yes
roles:
- role: "./k3s/node"

View File

@@ -0,0 +1,81 @@
variable "serverctl_master_count" {
default = 0
}
variable "serverctl_node_count" {
default = 0
}
resource "hcloud_placement_group" "serverctl_master" {
name = "serverctl_master_group"
type = "spread"
}
resource "hcloud_server" "serverctl_master" {
count = var.serverctl_master_count
name = "serverctl-master-${count.index}"
image = "debian-11"
server_type = "cx11"
ssh_keys = [
var.hcloud_serverctl_ssh_key_id
]
placement_group_id = hcloud_placement_group.serverctl_master.id
lifecycle {
create_before_destroy = true
}
provisioner "remote-exec" {
inline = ["sudo apt update", "sudo apt install python3 -y", "echo Done!"]
connection {
host = self.ipv4_address
type = "ssh"
user = "root"
private_key = file(var.pvt_key)
}
}
}
resource "hcloud_placement_group" "serverctl_node" {
name = "serverctl_node_group"
type = "spread"
}
resource "hcloud_server" "serverctl_node" {
count = var.serverctl_node_count
name = "serverctl-node-${count.index}"
image = "debian-11"
server_type = "cx11"
ssh_keys = [
var.hcloud_serverctl_ssh_key_id
]
placement_group_id = hcloud_placement_group.serverctl_node.id
lifecycle {
create_before_destroy = true
}
provisioner "remote-exec" {
inline = ["sudo apt update", "sudo apt install python3 -y", "echo Done!"]
connection {
host = self.ipv4_address
type = "ssh"
user = "root"
private_key = file(var.pvt_key)
}
}
}
resource "local_file" "hosts_cfg" {
content = templatefile("${path.module}/templates/hosts.tftpl",
{
serverctl_masters = hcloud_server.serverctl_master.*.ipv4_address
serverctl_nodes = hcloud_server.serverctl_node.*.ipv4_address
}
)
filename = "ansible/inventory/hosts.cfg"
}

View File

@@ -1,43 +0,0 @@
terraform {
required_providers {
hcloud = {
source = "hetznercloud/hcloud"
version = "1.32.2"
}
}
backend "s3" {
bucket = "serverctl-terraform"
key = "terraform.tfstate"
endpoint = "https://api.minio.front.kjuulh.io"
region = "main"
skip_credentials_validation = true
skip_metadata_api_check = true
skip_region_validation = true
force_path_style = true
}
}
variable "hcloud_token" {
sensitive = true
}
provider "hcloud" {
token = var.hcloud_token
}
resource "hcloud_placement_group" "serverctl_master" {
name = "serverctl_master_group"
type = "spread"
}
resource "hcloud_server" "serverctl_master" {
count = 2
name = "serverctl-master-${count.index}"
image = "debian-11"
server_type = "cx11"
placement_group_id = hcloud_placement_group.serverctl_master.id
}

View File

@@ -0,0 +1,35 @@
terraform {
required_providers {
hcloud = {
source = "hetznercloud/hcloud"
version = "1.50.0"
}
}
backend "s3" {
bucket = "serverctl-terraform"
key = "terraform.tfstate"
endpoint = "https://api.minio.front.kjuulh.io"
region = "main"
skip_credentials_validation = true
skip_metadata_api_check = true
skip_region_validation = true
force_path_style = true
}
}
variable "hcloud_token" {
sensitive = true
}
provider "hcloud" {
token = var.hcloud_token
}
variable "hcloud_serverctl_ssh_key_id" {}
variable "pvt_key" {}
variable "pub_key" {}

View File

@@ -0,0 +1,6 @@
#!/bin/bash
export $(grep -v "^#" .env | xargs)
terraform init -backend-config="access_key=$ACCESS_KEY" -backend-config="secret_key=$SECRET_KEY"

View File

@@ -0,0 +1,35 @@
[serverctl_master_hosts]
%{ for ip in serverctl_masters ~}
${ip} ansible_host=${ip} wireguard_ip=${cidrhost("10.1.1.0/24", index(serverctl_masters, ip) + 1)}
%{ endfor ~}
[serverctl_node_hosts]
%{ for ip in serverctl_nodes ~}
${ip} ansible_host=${ip} wireguard_ip=${cidrhost("10.1.1.0/24", index(serverctl_nodes, ip) + 10)}
%{ endfor ~}
[serverctl_home_servers]
192.168.1.150 ansible_host=192.168.1.150 wireguard_ip=10.1.1.8
#192.168.1.233 ansible_host=192.168.1.233 wireguard_ip=10.1.1.9
[serverctl_cluster:children]
serverctl_master_hosts
serverctl_node_hosts
[serverctl_super_cluster:children]
serverctl_cluster
serverctl_home_servers
[serverctl_home_servers:vars]
client_server=True
[serverctl_super_cluster:vars]
pipelining=true
ansible_ssh_user=root
ansible_ssh_port=22
[serverctl_cluster:vars]
client_server=False
pipelining=true
ansible_ssh_user=root
ansible_ssh_port=22

BIN
infrastructure/ssh_keys.zip Normal file

Binary file not shown.

View File

@@ -0,0 +1,7 @@
#!/bin/sh
ZIP_KEY=$1
unzip -P "$ZIP_KEY" ssh_keys.zip
echo "unzip done!"

12
infrastructure/zip-ssh-keys.sh Executable file
View File

@@ -0,0 +1,12 @@
#!/bin/bash
ZIP_KEY=$(openssl rand -hex 30)
mkdir -p ssh_keys/
cp -f ~/.ssh/id_ed25519* ssh_keys/
zip -r --password $ZIP_KEY ssh_keys.zip ssh_keys/
echo "zip done!"
echo "Zip key: $ZIP_KEY"

3
renovate.json Normal file
View File

@@ -0,0 +1,3 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json"
}

View File

@@ -1,4 +1,4 @@
FROM golang:1.17-bullseye
FROM golang:1.24-bullseye
RUN go install github.com/jackc/tern@latest

View File

@@ -1,4 +1,4 @@
FROM golang:1.17-bullseye
FROM golang:1.24-bullseye
RUN go install github.com/cosmtrek/air@latest
# Development don't need this

View File

@@ -1,6 +1,6 @@
module serverctl
go 1.17
go 1.19
require (
github.com/Microsoft/go-winio v0.4.17 // indirect