56 lines
2.0 KiB
Makefile
56 lines
2.0 KiB
Makefile
#!/usr/bin/env just
|
|
|
|
opentofu_dir := "infra/"
|
|
|
|
up: tofu-apply
|
|
down: tofu-destroy
|
|
|
|
tofu-init:
|
|
tofu -chdir={{ opentofu_dir }} init -upgrade
|
|
|
|
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)
|
|
|
|
# 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"
|
|
|
|
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
|