Initial commit
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
#!/usr/bin/env just
|
||||
|
||||
opentofu_dir := "infra/"
|
||||
|
||||
up:
|
||||
just gen-ssh-pair
|
||||
tofu -chdir=infra init
|
||||
tofu -chdir=infra apply -auto-approve
|
||||
|
||||
just playbook
|
||||
just get-admin-conf
|
||||
|
||||
tofu-init:
|
||||
tofu -chdir={{ opentofu_dir }} init -upgrade
|
||||
|
||||
tofu-apply: tofu-init gen-ssh-pair
|
||||
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"
|
||||
|
||||
down: tofu-destroy
|
||||
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
|
||||
Reference in New Issue
Block a user