Compare commits

..

2 Commits

Author SHA1 Message Date
JamesAllenby c00faad987 refactor: use ansible native incus connection 2026-06-23 21:17:21 +01:00
JamesAllenby f58488e5fd refactor: justfile targets 2026-06-23 20:33:00 +01:00
6 changed files with 35 additions and 106 deletions
+6 -40
View File
@@ -2,59 +2,25 @@
opentofu_dir := "infra/"
up:
just gen-ssh-pair
tofu -chdir=infra init
tofu -chdir=infra apply -auto-approve
just playbook
just get-admin-conf
up: tofu-apply ansible-run-playbook
down: tofu-destroy
tofu-init:
tofu -chdir={{ opentofu_dir }} init -upgrade
tofu-apply: tofu-init gen-ssh-pair
tofu-apply: tofu-init
tofu -chdir={{ opentofu_dir }} apply -auto-approve
tofu-destroy: tofu-init
tofu -chdir={{ opentofu_dir }} apply -auto-approve -destroy
build-inventory:
#!/usr/bin/env bash
master_ips=$(tofu -chdir=infra output -json master_addresses)
worker_ips=$(tofu -chdir=infra output -json worker_addresses)
ansible-run-playbook:
ansible-playbook -i ansible/inventory/incus.yaml -c community.general.incus ansible/playbook.yaml
# Build the inventory file cleanly using bash loops over the JSON arrays
{
echo "[masters]"
for i in $(seq 0 $(jq 'length - 1' <<< "${master_ips}")); do
ip=$(jq -r ".[$i]" <<< "${master_ips}")
echo "master-${i} ansible_host=${ip} ansible_user=root ansible_ssh_private_key_file=ansible/.ssh/key ansible_python_interpreter=auto_silent"
done
echo ""
echo "[workers]"
for i in $(seq 0 $(jq 'length - 1' <<< "${worker_ips}")); do
ip=$(jq -r ".[$i]" <<< "${worker_ips}")
echo "worker-${i} ansible_host=${ip} ansible_user=root ansible_ssh_private_key_file=ansible/.ssh/key ansible_python_interpreter=auto_silent"
done
} > ansible/hosts.ini
playbook: build-inventory
ansible-playbook --inventory ansible/hosts.ini ansible/playbook.yaml --ssh-extra-args "-o StrictHostKeyChecking=no"
# ansible-playbook --inventory ansible/hosts.ini ansible/setup-playbook.yaml --ssh-extra-args "-o StrictHostKeyChecking=no"
# ansible-playbook --inventory ansible/hosts.ini ansible/master-playbook.yaml --ssh-extra-args "-o StrictHostKeyChecking=no"
# ansible-playbook --inventory ansible/hosts.ini ansible/worker-playbook.yaml --ssh-extra-args "-o StrictHostKeyChecking=no"
down: tofu-destroy
clean:
rm ansible/hosts.ini || true
rm -r ansible/.ssh/ || true
rm admin.conf || true
gen-ssh-pair:
#!/usr/bin/env bash
mkdir -p ansible/.ssh
[ ! -f ansible/.ssh/key ] && ssh-keygen -f ansible/.ssh/key -P '' || true
get-admin-conf:
incus exec master-0 -- cat /etc/kubernetes/admin.conf > k8s-admin.conf
-5
View File
@@ -1,5 +0,0 @@
[masters]
master-0 ansible_host=10.150.0.2 ansible_user=root ansible_ssh_private_key_file=ansible/.ssh/key ansible_python_interpreter=auto_silent
master-1 ansible_host=10.150.0.4 ansible_user=root ansible_ssh_private_key_file=ansible/.ssh/key ansible_python_interpreter=auto_silent
[workers]
+5
View File
@@ -0,0 +1,5 @@
---
plugin: community.general.incus
strict: true
remotes:
- local:deskpi-cluster
+2 -35
View File
@@ -1,36 +1,3 @@
---
- name: Initialise empty disk with BTRFS
hosts: all
vars:
target_disk: /dev/disk/by-id/ata-QEMU_HARDDISK_incus_ext
tasks:
- name: Ensure btrfs-progs, parted and blkid is installed
ansible.builtin.package:
name: "{{ item }}"
state: present
loop:
- btrfs-progs
- parted
- blkid
- name: Ensure external disk has single partition on GPT
community.general.parted:
device: "{{ target_disk }}"
name: ext
number: 1
label: gpt
state: present
- name: Ensure BTRFS is formatted on external disk
community.general.filesystem:
dev: "{{ target_disk }}-part1"
fstype: btrfs
- name: Mount external disk to /mnt
ansible.posix.mount:
src: "{{ target_disk }}-part1"
path: /mnt
fstype: btrfs
state: mounted
# - name: Create BTRFS filesystem on external disk
# community.general.filesystem:
# fstype: btrfs
# dev: "{{ target_disk }}"
- name: Provision with Incus
ansible.builtin.import_playbook: playbooks/common.yaml
+22
View File
@@ -0,0 +1,22 @@
---
- name: Bootstrap - Stage 1
hosts: all
gather_facts: false
tasks:
- name: Install Python 3
ansible.builtin.raw: |
if ! command -v python3 >/dev/null 2>&1; then
apk add --no-cache python3
fi
register: apk_result
changed_when: "'OK' in apk_result.stdout or 'Installing' in apk_result.stdout"
- name: Bootstrap - Stage 2
hosts: all
tasks:
- name: Install Python 3 Libraries
ansible.builtin.package:
name: "{{ item }}"
loop:
- py3-yaml
- py3-kubernetes
-26
View File
@@ -83,17 +83,6 @@ resource "incus_instance" "master" {
type = "agent"
}
file {
source_path = "bootstrap.sh"
target_path = "/bootstrap.sh"
}
file {
source_path = "../ansible/.ssh/key.pub"
target_path = "/root/.ssh/authorized_keys"
create_directories = true
}
device {
name = "eth0"
type = "nic"
@@ -113,8 +102,6 @@ resource "incus_instance" "master" {
"source" = incus_storage_volume.master[count.index].name
}
}
exec = { "00-init" = { command = ["/bootstrap.sh"] } }
}
resource "incus_storage_volume" "master" {
@@ -147,17 +134,6 @@ resource "incus_instance" "worker" {
type = "agent"
}
file {
source_path = "bootstrap.sh"
target_path = "/bootstrap.sh"
}
file {
source_path = "../ansible/.ssh/key.pub"
target_path = "/root/.ssh/authorized_keys"
create_directories = true
}
device {
name = "eth0"
type = "nic"
@@ -167,8 +143,6 @@ resource "incus_instance" "worker" {
"ipv4.address" = cidrhost(local.network_cidr, 3 + (2 * count.index))
}
}
exec = { "00-init" = { command = ["/bootstrap.sh"] } }
}
# -------