forked from k-space/kube
mv to ansible/
This commit is contained in:
76
ansible/bind-primary.yml
Normal file
76
ansible/bind-primary.yml
Normal file
@@ -0,0 +1,76 @@
|
||||
- name: Setup primary nameserver
|
||||
hosts: ns1.k-space.ee
|
||||
tasks:
|
||||
- name: Make sure bind9 is installed
|
||||
ansible.builtin.apt:
|
||||
name: bind9
|
||||
state: present
|
||||
|
||||
- name: Configure Bind
|
||||
register: bind
|
||||
copy:
|
||||
dest: /etc/bind/named.conf
|
||||
content: |
|
||||
# This file is managed by Ansible
|
||||
# https://git.k-space.ee/k-space/kube/src/branch/master/ansible-bind-primary.yml
|
||||
# Do NOT modify manually
|
||||
|
||||
include "/etc/bind/named.conf.local";
|
||||
include "/etc/bind/readwrite.key";
|
||||
include "/etc/bind/readonly.key";
|
||||
|
||||
options {
|
||||
directory "/var/cache/bind";
|
||||
version "";
|
||||
listen-on { any; };
|
||||
listen-on-v6 { any; };
|
||||
pid-file "/var/run/named/named.pid";
|
||||
notify explicit; also-notify { 172.20.53.1; 172.20.53.2; 172.20.53.3; };
|
||||
allow-recursion { none; };
|
||||
recursion no;
|
||||
check-names master ignore;
|
||||
dnssec-validation no;
|
||||
auth-nxdomain no;
|
||||
};
|
||||
|
||||
# https://kb.isc.org/docs/aa-00723
|
||||
|
||||
acl allowed {
|
||||
172.20.3.0/24;
|
||||
172.20.4.0/24;
|
||||
};
|
||||
|
||||
acl rejected { !allowed; any; };
|
||||
|
||||
zone "." {
|
||||
type hint;
|
||||
file "/var/lib/bind/db.root";
|
||||
};
|
||||
|
||||
zone "k-space.ee" {
|
||||
type master;
|
||||
file "/var/lib/bind/db.k-space.ee";
|
||||
allow-update { !rejected; key readwrite; };
|
||||
allow-transfer { !rejected; key readonly; key readwrite; };
|
||||
};
|
||||
|
||||
zone "k6.ee" {
|
||||
type master;
|
||||
file "/var/lib/bind/db.k6.ee";
|
||||
allow-update { !rejected; key readwrite; };
|
||||
allow-transfer { !rejected; key readonly; key readwrite; };
|
||||
};
|
||||
|
||||
zone "kspace.ee" {
|
||||
type master;
|
||||
file "/var/lib/bind/db.kspace.ee";
|
||||
allow-update { !rejected; key readwrite; };
|
||||
allow-transfer { !rejected; key readonly; key readwrite; };
|
||||
};
|
||||
- name: Check Bind config
|
||||
ansible.builtin.shell: "named-checkconf"
|
||||
- name: Reload Bind config
|
||||
service:
|
||||
name: bind9
|
||||
state: reloaded
|
||||
when: bind.changed
|
63
ansible/doors.yml
Normal file
63
ansible/doors.yml
Normal file
@@ -0,0 +1,63 @@
|
||||
# ansible doors -m shell -a "ctr image pull harbor.k-space.ee/k-space/mjpg-streamer:latest"
|
||||
# journalctl -u mjpg_streamer@video0.service -f
|
||||
- name: Setup doors
|
||||
hosts: doors
|
||||
tasks:
|
||||
- name: Make sure containerd is installed
|
||||
ansible.builtin.apt:
|
||||
name: containerd
|
||||
state: present
|
||||
|
||||
- name: Copy systemd service for Doorboy controller
|
||||
copy:
|
||||
dest: /etc/systemd/system/godoor.service
|
||||
content: |
|
||||
[Unit]
|
||||
Description=Doorboy service
|
||||
Documentation=https://git.k-space.ee/k-space/godoor
|
||||
After=network.target
|
||||
[Service]
|
||||
Environment=IMAGE=harbor.k-space.ee/k-space/godoor:latest
|
||||
ExecStartPre=-ctr task kill --signal=9 %N
|
||||
ExecStartPre=-ctr task rm %N
|
||||
ExecStartPre=-ctr c rm %N
|
||||
ExecStartPre=-ctr image pull $IMAGE
|
||||
ExecStart=ctr run --rm --pid-file=/run/%N.pid --privileged --read-only --env-file=/etc/godoor --env=KDOORPI_API_ALLOWED=https://doorboy-proxy.k-space.ee/allowed --env=KDOORPI_API_LONGPOLL=https://doorboy-proxy.k-space.ee/longpoll --env=KDOORPI_API_SWIPE=https://doorboy-proxy.k-space.ee/swipe --env=KDOORPI_DOOR=%H --net-host --net-host --cwd /app $IMAGE %N /godoor
|
||||
ExecStopPost=ctr task rm %N
|
||||
ExecStopPost=ctr c rm %N
|
||||
Restart=always
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
- name: Enable Doorboy controller
|
||||
ansible.builtin.systemd:
|
||||
state: restarted
|
||||
daemon_reload: yes
|
||||
name: godoor.service
|
||||
|
||||
- name: Copy systemd service for mjpg-streamer
|
||||
copy:
|
||||
dest: /etc/systemd/system/mjpg_streamer@.service
|
||||
content: |
|
||||
[Unit]
|
||||
Description=A server for streaming Motion-JPEG from a video capture device
|
||||
After=network.target
|
||||
ConditionPathExists=/dev/%I
|
||||
[Service]
|
||||
Environment=IMAGE=harbor.k-space.ee/k-space/mjpg-streamer:latest
|
||||
StandardOutput=tty
|
||||
Type=forking
|
||||
ExecStartPre=-ctr task kill --signal=9 %p_%i
|
||||
ExecStartPre=-ctr task rm %p_%i
|
||||
ExecStartPre=-ctr c rm %p_%i
|
||||
ExecStartPre=-ctr image pull $IMAGE
|
||||
ExecStart=ctr run --tty -d --rm --pid-file=/run/%i.pid --privileged --read-only --net-host $IMAGE %p_%i /usr/local/bin/mjpg_streamer -i 'input_uvc.so -d /dev/%I -r 1280x720 -f 10' -o 'output_http.so -w /usr/share/mjpg_streamer/www'
|
||||
ExecStopPost=ctr task rm %p_%i
|
||||
ExecStopPost=ctr c rm %p_%i
|
||||
PIDFile=/run/%i.pid
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
- name: Enable mjpg-streamer
|
||||
ansible.builtin.systemd:
|
||||
state: restarted
|
||||
daemon_reload: yes
|
||||
name: mjpg_streamer@video0.service
|
91
ansible/inventory.yml
Normal file
91
ansible/inventory.yml
Normal file
@@ -0,0 +1,91 @@
|
||||
all:
|
||||
vars:
|
||||
admins:
|
||||
- lauri
|
||||
- eaas
|
||||
extra_admins: []
|
||||
children:
|
||||
nasgroup:
|
||||
hosts:
|
||||
nas.k-space.ee:
|
||||
ansible_host: 172.23.0.7
|
||||
offsite:
|
||||
ansible_host: 78.28.64.17
|
||||
ansible_port: 10648
|
||||
vars:
|
||||
offsite_dataset: offsite/backup_zrepl
|
||||
misc:
|
||||
children:
|
||||
nasgroup:
|
||||
hosts:
|
||||
ns1.k-space.ee:
|
||||
ansible_host: 172.20.0.2
|
||||
proxmox:
|
||||
vars:
|
||||
extra_admins:
|
||||
- rasmus
|
||||
hosts:
|
||||
pve1:
|
||||
ansible_host: 172.21.20.1
|
||||
pve2:
|
||||
ansible_host: 172.21.20.2
|
||||
pve8:
|
||||
ansible_host: 172.21.20.8
|
||||
pve9:
|
||||
ansible_host: 172.21.20.9
|
||||
kubernetes:
|
||||
children:
|
||||
masters:
|
||||
hosts:
|
||||
master1.kube.k-space.ee:
|
||||
ansible_host: 172.21.3.51
|
||||
master2.kube.k-space.ee:
|
||||
ansible_host: 172.21.3.52
|
||||
master3.kube.k-space.ee:
|
||||
ansible_host: 172.21.3.53
|
||||
kubelets:
|
||||
children:
|
||||
mon:
|
||||
hosts:
|
||||
mon1.kube.k-space.ee:
|
||||
ansible_host: 172.21.3.61
|
||||
mon2.kube.k-space.ee:
|
||||
ansible_host: 172.21.3.62
|
||||
mon3.kube.k-space.ee:
|
||||
ansible_host: 172.21.3.63
|
||||
storage:
|
||||
hosts:
|
||||
storage1.kube.k-space.ee:
|
||||
ansible_host: 172.21.3.71
|
||||
storage2.kube.k-space.ee:
|
||||
ansible_host: 172.21.3.72
|
||||
storage3.kube.k-space.ee:
|
||||
ansible_host: 172.21.3.73
|
||||
storage4.kube.k-space.ee:
|
||||
ansible_host: 172.21.3.74
|
||||
workers:
|
||||
hosts:
|
||||
worker1.kube.k-space.ee:
|
||||
ansible_host: 172.20.3.81
|
||||
worker2.kube.k-space.ee:
|
||||
ansible_host: 172.20.3.82
|
||||
worker3.kube.k-space.ee:
|
||||
ansible_host: 172.20.3.83
|
||||
worker4.kube.k-space.ee:
|
||||
ansible_host: 172.20.3.84
|
||||
worker9.kube.k-space.ee:
|
||||
# Raspberry Pi 400
|
||||
ansible_host: 172.20.3.89
|
||||
doors:
|
||||
vars:
|
||||
extra_admins:
|
||||
- arti
|
||||
hosts:
|
||||
grounddoor:
|
||||
ansible_host: 100.102.3.1
|
||||
frontdoor:
|
||||
ansible_host: 100.102.3.2
|
||||
backdoor:
|
||||
ansible_host: 100.102.3.3
|
||||
workshopdoor:
|
||||
ansible_host: 100.102.3.4
|
162
ansible/kubernetes.yml
Normal file
162
ansible/kubernetes.yml
Normal file
@@ -0,0 +1,162 @@
|
||||
---
|
||||
- name: Reconfigure Kubernetes worker nodes
|
||||
hosts:
|
||||
- storage
|
||||
- workers
|
||||
tasks:
|
||||
- name: Configure grub defaults
|
||||
copy:
|
||||
dest: "/etc/default/grub"
|
||||
content: |
|
||||
GRUB_DEFAULT=0
|
||||
GRUB_TIMEOUT_STYLE=countdown
|
||||
GRUB_TIMEOUT=5
|
||||
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
|
||||
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash memhp_default_state=online"
|
||||
GRUB_CMDLINE_LINUX="memhp_default_state=online rootflags=pquota"
|
||||
register: grub_defaults
|
||||
|
||||
- name: Load grub defaults
|
||||
ansible.builtin.shell: update-grub
|
||||
when: grub_defaults.changed
|
||||
|
||||
- name: Reconfigure Kubernetes nodes
|
||||
hosts: kubernetes
|
||||
vars:
|
||||
KUBERNETES_VERSION: v1.28.12
|
||||
tasks:
|
||||
- name: Remove APT packages
|
||||
ansible.builtin.apt:
|
||||
name: "{{ item }}"
|
||||
state: absent
|
||||
loop:
|
||||
- kubelet
|
||||
- kubeadm
|
||||
- kubectl
|
||||
|
||||
- name: Download kubectl, kubeadm, kubelet
|
||||
ansible.builtin.get_url:
|
||||
url: "https://cdn.dl.k8s.io/release/{{ KUBERNETES_VERSION }}/bin/linux/{{ 'arm64' if ansible_architecture == 'aarch64' else 'amd64' }}/{{ item }}"
|
||||
dest: "/usr/bin/{{ item }}-{{ KUBERNETES_VERSION }}"
|
||||
mode: '0755'
|
||||
loop:
|
||||
- kubelet
|
||||
- kubectl
|
||||
- kubeadm
|
||||
|
||||
- name: Create symlinks for kubectl, kubeadm, kubelet
|
||||
ansible.builtin.file:
|
||||
src: "/usr/bin/{{ item }}-{{ KUBERNETES_VERSION }}"
|
||||
dest: "/usr/bin/{{ item }}"
|
||||
state: link
|
||||
loop:
|
||||
- kubelet
|
||||
- kubectl
|
||||
- kubeadm
|
||||
register: kubelet
|
||||
|
||||
- name: Restart Kubelet
|
||||
service:
|
||||
name: kubelet
|
||||
enabled: true
|
||||
state: restarted
|
||||
when: kubelet.changed
|
||||
|
||||
- name: Create /etc/systemd/system/kubelet.service
|
||||
ansible.builtin.copy:
|
||||
content: |
|
||||
[Unit]
|
||||
Description=kubelet: The Kubernetes Node Agent
|
||||
Documentation=https://kubernetes.io/docs/home/
|
||||
Wants=network-online.target
|
||||
After=network-online.target
|
||||
[Service]
|
||||
ExecStart=/usr/local/bin/kubelet
|
||||
Restart=always
|
||||
StartLimitInterval=0
|
||||
RestartSec=10
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
dest: /etc/systemd/system/kubelet.service
|
||||
|
||||
- name: Reconfigure shutdownGracePeriod
|
||||
ansible.builtin.lineinfile:
|
||||
path: /var/lib/kubelet/config.yaml
|
||||
regexp: '^shutdownGracePeriod:'
|
||||
line: 'shutdownGracePeriod: 5m'
|
||||
|
||||
- name: Reconfigure shutdownGracePeriodCriticalPods
|
||||
ansible.builtin.lineinfile:
|
||||
path: /var/lib/kubelet/config.yaml
|
||||
regexp: '^shutdownGracePeriodCriticalPods:'
|
||||
line: 'shutdownGracePeriodCriticalPods: 5m'
|
||||
|
||||
- name: Work around unattended-upgrades
|
||||
ansible.builtin.lineinfile:
|
||||
path: /lib/systemd/logind.conf.d/unattended-upgrades-logind-maxdelay.conf
|
||||
regexp: '^InhibitDelayMaxSec='
|
||||
line: 'InhibitDelayMaxSec=5m0s'
|
||||
|
||||
- name: Disable unneccesary services
|
||||
ignore_errors: true
|
||||
loop:
|
||||
- gdm3
|
||||
- snapd
|
||||
- bluetooth
|
||||
- multipathd
|
||||
service:
|
||||
name: "{{item}}"
|
||||
state: stopped
|
||||
enabled: no
|
||||
|
||||
- name: Reset /etc/containers/registries.conf
|
||||
ansible.builtin.copy:
|
||||
content: "unqualified-search-registries = [\"docker.io\"]\n"
|
||||
dest: /etc/containers/registries.conf
|
||||
register: registries
|
||||
|
||||
- name: Restart CRI-O
|
||||
service:
|
||||
name: cri-o
|
||||
state: restarted
|
||||
when: registries.changed
|
||||
|
||||
- name: Reset /etc/modules
|
||||
ansible.builtin.copy:
|
||||
content: |
|
||||
overlay
|
||||
br_netfilter
|
||||
dest: /etc/modules
|
||||
register: kernel_modules
|
||||
- name: Load kernel modules
|
||||
ansible.builtin.shell: "cat /etc/modules | xargs -L 1 -t modprobe"
|
||||
when: kernel_modules.changed
|
||||
|
||||
- name: Reset /etc/sysctl.d/99-k8s.conf
|
||||
ansible.builtin.copy:
|
||||
content: |
|
||||
net.ipv4.conf.all.accept_redirects = 0
|
||||
net.bridge.bridge-nf-call-iptables = 1
|
||||
net.ipv4.ip_forward = 1
|
||||
net.bridge.bridge-nf-call-ip6tables = 1
|
||||
vm.max_map_count = 524288
|
||||
fs.inotify.max_user_instances = 1280
|
||||
fs.inotify.max_user_watches = 655360
|
||||
dest: /etc/sysctl.d/99-k8s.conf
|
||||
register: sysctl
|
||||
|
||||
- name: Reload sysctl config
|
||||
ansible.builtin.shell: "sysctl --system"
|
||||
when: sysctl.changed
|
||||
|
||||
- name: Reconfigure Kubernetes master nodes
|
||||
hosts: masters
|
||||
vars:
|
||||
KUBERNETES_VERSION: v1.28.12
|
||||
IP: "{{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] }}"
|
||||
tasks:
|
||||
- name: Configure kube-apiserver manifest on masters
|
||||
ansible.builtin.template:
|
||||
src: kube-apiserver.j2
|
||||
dest: /etc/kubernetes/manifests/kube-apiserver.yaml
|
||||
mode: 600
|
178
ansible/ssh_config
Normal file
178
ansible/ssh_config
Normal file
@@ -0,0 +1,178 @@
|
||||
# Use `ansible-playbook ansible/update-ssh-config.yml` to update this file
|
||||
# Use `ssh -F ssh_config ...` to connect to target machine or
|
||||
# Add `Include ~/path/to/this/kube/ssh_config` in your ~/.ssh/config
|
||||
Host backdoor 100.102.3.3
|
||||
User root
|
||||
Hostname 100.102.3.3
|
||||
GlobalKnownHostsFile known_hosts
|
||||
UserKnownHostsFile /dev/null
|
||||
ControlMaster auto
|
||||
ControlPersist 8h
|
||||
Host frontdoor 100.102.3.2
|
||||
User root
|
||||
Hostname 100.102.3.2
|
||||
GlobalKnownHostsFile known_hosts
|
||||
UserKnownHostsFile /dev/null
|
||||
ControlMaster auto
|
||||
ControlPersist 8h
|
||||
Host grounddoor 100.102.3.1
|
||||
User root
|
||||
Hostname 100.102.3.1
|
||||
GlobalKnownHostsFile known_hosts
|
||||
UserKnownHostsFile /dev/null
|
||||
ControlMaster auto
|
||||
ControlPersist 8h
|
||||
Host master1.kube.k-space.ee 172.21.3.51
|
||||
User root
|
||||
Hostname 172.21.3.51
|
||||
GlobalKnownHostsFile known_hosts
|
||||
UserKnownHostsFile /dev/null
|
||||
ControlMaster auto
|
||||
ControlPersist 8h
|
||||
Host master2.kube.k-space.ee 172.21.3.52
|
||||
User root
|
||||
Hostname 172.21.3.52
|
||||
GlobalKnownHostsFile known_hosts
|
||||
UserKnownHostsFile /dev/null
|
||||
ControlMaster auto
|
||||
ControlPersist 8h
|
||||
Host master3.kube.k-space.ee 172.21.3.53
|
||||
User root
|
||||
Hostname 172.21.3.53
|
||||
GlobalKnownHostsFile known_hosts
|
||||
UserKnownHostsFile /dev/null
|
||||
ControlMaster auto
|
||||
ControlPersist 8h
|
||||
Host mon1.kube.k-space.ee 172.21.3.61
|
||||
User root
|
||||
Hostname 172.21.3.61
|
||||
GlobalKnownHostsFile known_hosts
|
||||
UserKnownHostsFile /dev/null
|
||||
ControlMaster auto
|
||||
ControlPersist 8h
|
||||
Host mon2.kube.k-space.ee 172.21.3.62
|
||||
User root
|
||||
Hostname 172.21.3.62
|
||||
GlobalKnownHostsFile known_hosts
|
||||
UserKnownHostsFile /dev/null
|
||||
ControlMaster auto
|
||||
ControlPersist 8h
|
||||
Host mon3.kube.k-space.ee 172.21.3.63
|
||||
User root
|
||||
Hostname 172.21.3.63
|
||||
GlobalKnownHostsFile known_hosts
|
||||
UserKnownHostsFile /dev/null
|
||||
ControlMaster auto
|
||||
ControlPersist 8h
|
||||
Host nas.k-space.ee 172.23.0.7
|
||||
User root
|
||||
Hostname 172.23.0.7
|
||||
GlobalKnownHostsFile known_hosts
|
||||
UserKnownHostsFile /dev/null
|
||||
ControlMaster auto
|
||||
ControlPersist 8h
|
||||
Host ns1.k-space.ee 172.20.0.2
|
||||
User root
|
||||
Hostname 172.20.0.2
|
||||
GlobalKnownHostsFile known_hosts
|
||||
UserKnownHostsFile /dev/null
|
||||
ControlMaster auto
|
||||
ControlPersist 8h
|
||||
Host pve1 172.21.20.1
|
||||
User root
|
||||
Hostname 172.21.20.1
|
||||
GlobalKnownHostsFile known_hosts
|
||||
UserKnownHostsFile /dev/null
|
||||
ControlMaster auto
|
||||
ControlPersist 8h
|
||||
Host pve2 172.21.20.2
|
||||
User root
|
||||
Hostname 172.21.20.2
|
||||
GlobalKnownHostsFile known_hosts
|
||||
UserKnownHostsFile /dev/null
|
||||
ControlMaster auto
|
||||
ControlPersist 8h
|
||||
Host pve8 172.21.20.8
|
||||
User root
|
||||
Hostname 172.21.20.8
|
||||
GlobalKnownHostsFile known_hosts
|
||||
UserKnownHostsFile /dev/null
|
||||
ControlMaster auto
|
||||
ControlPersist 8h
|
||||
Host pve9 172.21.20.9
|
||||
User root
|
||||
Hostname 172.21.20.9
|
||||
GlobalKnownHostsFile known_hosts
|
||||
UserKnownHostsFile /dev/null
|
||||
ControlMaster auto
|
||||
ControlPersist 8h
|
||||
Host storage1.kube.k-space.ee 172.21.3.71
|
||||
User root
|
||||
Hostname 172.21.3.71
|
||||
GlobalKnownHostsFile known_hosts
|
||||
UserKnownHostsFile /dev/null
|
||||
ControlMaster auto
|
||||
ControlPersist 8h
|
||||
Host storage2.kube.k-space.ee 172.21.3.72
|
||||
User root
|
||||
Hostname 172.21.3.72
|
||||
GlobalKnownHostsFile known_hosts
|
||||
UserKnownHostsFile /dev/null
|
||||
ControlMaster auto
|
||||
ControlPersist 8h
|
||||
Host storage3.kube.k-space.ee 172.21.3.73
|
||||
User root
|
||||
Hostname 172.21.3.73
|
||||
GlobalKnownHostsFile known_hosts
|
||||
UserKnownHostsFile /dev/null
|
||||
ControlMaster auto
|
||||
ControlPersist 8h
|
||||
Host storage4.kube.k-space.ee 172.21.3.74
|
||||
User root
|
||||
Hostname 172.21.3.74
|
||||
GlobalKnownHostsFile known_hosts
|
||||
UserKnownHostsFile /dev/null
|
||||
ControlMaster auto
|
||||
ControlPersist 8h
|
||||
Host worker1.kube.k-space.ee 172.20.3.81
|
||||
User root
|
||||
Hostname 172.20.3.81
|
||||
GlobalKnownHostsFile known_hosts
|
||||
UserKnownHostsFile /dev/null
|
||||
ControlMaster auto
|
||||
ControlPersist 8h
|
||||
Host worker2.kube.k-space.ee 172.20.3.82
|
||||
User root
|
||||
Hostname 172.20.3.82
|
||||
GlobalKnownHostsFile known_hosts
|
||||
UserKnownHostsFile /dev/null
|
||||
ControlMaster auto
|
||||
ControlPersist 8h
|
||||
Host worker3.kube.k-space.ee 172.20.3.83
|
||||
User root
|
||||
Hostname 172.20.3.83
|
||||
GlobalKnownHostsFile known_hosts
|
||||
UserKnownHostsFile /dev/null
|
||||
ControlMaster auto
|
||||
ControlPersist 8h
|
||||
Host worker4.kube.k-space.ee 172.20.3.84
|
||||
User root
|
||||
Hostname 172.20.3.84
|
||||
GlobalKnownHostsFile known_hosts
|
||||
UserKnownHostsFile /dev/null
|
||||
ControlMaster auto
|
||||
ControlPersist 8h
|
||||
Host worker9.kube.k-space.ee 172.20.3.89
|
||||
User root
|
||||
Hostname 172.20.3.89
|
||||
GlobalKnownHostsFile known_hosts
|
||||
UserKnownHostsFile /dev/null
|
||||
ControlMaster auto
|
||||
ControlPersist 8h
|
||||
Host workshopdoor 100.102.3.4
|
||||
User root
|
||||
Hostname 100.102.3.4
|
||||
GlobalKnownHostsFile known_hosts
|
||||
UserKnownHostsFile /dev/null
|
||||
ControlMaster auto
|
||||
ControlPersist 8h
|
70
ansible/update-ssh-config.yaml
Normal file
70
ansible/update-ssh-config.yaml
Normal file
@@ -0,0 +1,70 @@
|
||||
---
|
||||
- name: Collect servers SSH public keys to known_hosts
|
||||
hosts: localhost
|
||||
connection: local
|
||||
vars:
|
||||
targets: "{{ hostvars[groups['all']] }}"
|
||||
tasks:
|
||||
- name: Generate known_hosts
|
||||
ansible.builtin.copy:
|
||||
dest: known_hosts
|
||||
content: |
|
||||
# Use `ansible-playbook ansible/update-ssh-config.yml` to update this file
|
||||
{% for host in groups['all'] | sort %}
|
||||
{{ lookup('ansible.builtin.pipe', 'ssh-keyscan -t ecdsa %s ' % (
|
||||
hostvars[host].get('ansible_host', host))) }} # {{ host }}
|
||||
{% endfor %}
|
||||
- name: Generate ssh_config
|
||||
ansible.builtin.copy:
|
||||
dest: ssh_config
|
||||
content: |
|
||||
# Use `ansible-playbook ansible/update-ssh-config.yml` to update this file
|
||||
# Use `ssh -F ssh_config ...` to connect to target machine or
|
||||
# Add `Include ~/path/to/this/kube/ssh_config` in your ~/.ssh/config
|
||||
{% for host in groups['all'] | sort %}
|
||||
Host {{ [host, hostvars[host].get('ansible_host', host)] | unique | join(' ') }}
|
||||
User root
|
||||
Hostname {{ hostvars[host].get('ansible_host', host) }}
|
||||
GlobalKnownHostsFile known_hosts
|
||||
UserKnownHostsFile /dev/null
|
||||
ControlMaster auto
|
||||
ControlPersist 8h
|
||||
{% endfor %}
|
||||
|
||||
- name: Pull authorized keys from Gitea
|
||||
hosts: localhost
|
||||
connection: local
|
||||
vars:
|
||||
targets: "{{ hostvars[groups['all']] }}"
|
||||
tasks:
|
||||
- name: Download https://git.k-space.ee/user.keys
|
||||
loop:
|
||||
- arti
|
||||
- eaas
|
||||
- lauri
|
||||
- rasmus
|
||||
ansible.builtin.get_url:
|
||||
url: https://git.k-space.ee/{{ item }}.keys
|
||||
dest: "./{{ item }}.keys"
|
||||
|
||||
- name: Push authorized keys to targets
|
||||
hosts:
|
||||
- misc
|
||||
- kubernetes
|
||||
- doors
|
||||
tasks:
|
||||
- name: Generate /root/.ssh/authorized_keys
|
||||
ansible.builtin.copy:
|
||||
dest: "/root/.ssh/authorized_keys"
|
||||
owner: root
|
||||
group: root
|
||||
mode: '0644'
|
||||
content: |
|
||||
# Use `ansible-playbook ansible/update-ssh-config.yml` from https://git.k-space.ee/k-space/kube/ to update this file
|
||||
{% for user in admins + extra_admins | unique | sort %}
|
||||
{% for line in lookup("ansible.builtin.file", user + ".keys").split("\n") %}
|
||||
{% if line.startswith("sk-") %}
|
||||
{{ line }} # {{ user }}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endfor %}
|
47
ansible/zrepl/zrepl.yml
Normal file
47
ansible/zrepl/zrepl.yml
Normal file
@@ -0,0 +1,47 @@
|
||||
- name: zrepl
|
||||
hosts: nasgroup
|
||||
tasks:
|
||||
- name: 'apt: zrepl gpg'
|
||||
ansible.builtin.get_url:
|
||||
url: 'https://zrepl.cschwarz.com/apt/apt-key.asc'
|
||||
dest: /usr/share/keyrings/zrepl.asc
|
||||
- name: 'apt: zrepl repo'
|
||||
apt_repository:
|
||||
repo: 'deb [arch=amd64 signed-by=/usr/share/keyrings/zrepl.asc] https://zrepl.cschwarz.com/apt/debian bookworm main'
|
||||
- name: 'apt: ensure packages'
|
||||
apt:
|
||||
state: latest
|
||||
pkg: zrepl
|
||||
|
||||
- name: 'zrepl: ensure config'
|
||||
ansible.builtin.template:
|
||||
src: "zrepl_{{ansible_hostname}}.yml.j2"
|
||||
dest: /etc/zrepl/zrepl.yml
|
||||
mode: 600
|
||||
register: zreplconf
|
||||
- name: 'zrepl: restart service after config change'
|
||||
when: zreplconf.changed
|
||||
service:
|
||||
state: restarted
|
||||
enabled: true
|
||||
name: zrepl
|
||||
- name: 'zrepl: ensure service'
|
||||
when: not zreplconf.changed
|
||||
service:
|
||||
state: started
|
||||
enabled: true
|
||||
name: zrepl
|
||||
|
||||
# avoid accidental conflicts of changes on recv (would err 'will not overwrite without force')
|
||||
- name: 'zfs: ensure recv mountpoint=off'
|
||||
hosts: offsite
|
||||
tasks:
|
||||
- name: 'zfs: get mountpoint'
|
||||
shell: zfs get mountpoint -H -o value {{offsite_dataset}}
|
||||
register: result
|
||||
changed_when: false
|
||||
- when: result.stdout != "none"
|
||||
name: 'zfs: ensure mountpoint=off'
|
||||
changed_when: true
|
||||
shell: zfs set mountpoint=none {{offsite_dataset}}
|
||||
register: result
|
47
ansible/zrepl/zrepl_nas.yml.j2
Normal file
47
ansible/zrepl/zrepl_nas.yml.j2
Normal file
@@ -0,0 +1,47 @@
|
||||
global:
|
||||
logging:
|
||||
- type: syslog
|
||||
format: logfmt
|
||||
level: warn
|
||||
monitoring:
|
||||
- type: prometheus
|
||||
listen: ':9811'
|
||||
|
||||
jobs:
|
||||
- name: k6zrepl
|
||||
type: snap
|
||||
# "<" aka recursive, https://zrepl.github.io/configuration/filter_syntax.html
|
||||
filesystems:
|
||||
'nas<': true
|
||||
snapshotting:
|
||||
type: periodic
|
||||
prefix: zrepl_
|
||||
interval: 1h
|
||||
pruning:
|
||||
keep:
|
||||
# Keep non-zrepl snapshots
|
||||
- type: regex
|
||||
negate: true
|
||||
regex: '^zrepl_'
|
||||
|
||||
- type: last_n
|
||||
regex: "^zrepl_.*"
|
||||
count: 4
|
||||
- type: grid
|
||||
regex: "^zrepl_.*"
|
||||
grid: 4x1h | 6x4h | 3x1d | 2x7d
|
||||
|
||||
- name: k6zrepl_offsite_src
|
||||
type: source
|
||||
send:
|
||||
encrypted: true # zfs native already-encrypted, filesystems not encrypted will log to error-level
|
||||
serve:
|
||||
type: tcp
|
||||
listen: "{{ansible_host}}:35566" # NAT-ed to 193.40.103.250
|
||||
clients: {
|
||||
"78.28.64.17": "offsite.k-space.ee",
|
||||
}
|
||||
filesystems:
|
||||
'nas<': true
|
||||
snapshotting: # handled by above job, separated for secuwurity (isolation of domains)
|
||||
type: manual
|
38
ansible/zrepl/zrepl_offsite.yml.j2
Normal file
38
ansible/zrepl/zrepl_offsite.yml.j2
Normal file
@@ -0,0 +1,38 @@
|
||||
global:
|
||||
logging:
|
||||
- type: syslog
|
||||
format: logfmt
|
||||
level: warn
|
||||
|
||||
jobs:
|
||||
- name: k6zrepl_offsite_dest
|
||||
type: pull
|
||||
recv:
|
||||
placeholder:
|
||||
encryption: off # https://zrepl.github.io/configuration/sendrecvoptions.html#placeholders
|
||||
# bandwidth_limit:
|
||||
# max: 9 MiB # 75.5 Mbps
|
||||
connect:
|
||||
type: tcp
|
||||
address: '193.40.103.250:35566' # firewall whitelisted to offsite
|
||||
root_fs: {{offsite_dataset}}
|
||||
interval: 10m # start interval, does nothing when no snapshots to recv
|
||||
replication:
|
||||
concurrency:
|
||||
steps: 2
|
||||
pruning:
|
||||
keep_sender: # offsite does not dictate nas snapshot policy
|
||||
- type: regex
|
||||
regex: '.*'
|
||||
keep_receiver:
|
||||
# Keep non-zrepl snapshots
|
||||
- negate: true
|
||||
type: regex
|
||||
regex: "^zrepl_"
|
||||
|
||||
- type: last_n
|
||||
regex: "^zrepl_"
|
||||
count: 4
|
||||
- type: grid
|
||||
regex: "^zrepl_"
|
||||
grid: 4x1h | 6x4h | 3x1d | 2x7d
|
Reference in New Issue
Block a user