From 34ffb7fd14dad0f97ddee33ced7486a8823634e7 Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Fri, 10 Nov 2023 21:50:45 +0100 Subject: [PATCH] feat(Makefile): Add up target with installation state detection --- Makefile | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index df5ae89..76e9b3b 100644 --- a/Makefile +++ b/Makefile @@ -1,18 +1,35 @@ +up: + @echo "Checking for Homelab installation..." + @vagrant status | grep "not created" > /dev/null; \ + if [ "$$?" -gt 0 ]; then \ + echo "Installation found, bringing it up..."; \ + vagrant up; \ + else \ + echo "No Homelab installation found or missing components, creating..."; \ + $(MAKE) install_vb; \ + fi + install_vb: - vagrant up - cd ansible && ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -i ../inventory/lab.yml -i ../inventory/outsider.yml init.yml --extra-vars "enable_setup=true enable_wireguard=true enable_k3s=true" - make get_k3s_credentials + @echo "Creating components..." + @vagrant up + @echo "Installing k3s backbone configuration..." + @cd ansible && ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -i ../inventory/lab.yml -i ../inventory/outsider.yml init.yml --extra-vars "enable_setup=true enable_wireguard=true enable_k3s=true" + @make get_k3s_credentials k3s_reset: - cd ansible && ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -i ../inventory/lab.yml -i ../inventory/outsider.yml k3s-ansible/reset.yml - cd ansible && ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -i ../inventory/lab.yml -i ../inventory/outsider.yml init.yml --extra-vars "enable_setup=true enable_wireguard=true enable_k3s=true" - make get_k3s_credentials + @echo "Resetting k3s configuration..." + @cd ansible && ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -i ../inventory/lab.yml -i ../inventory/outsider.yml k3s-ansible/reset.yml + @cd ansible && ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -i ../inventory/lab.yml -i ../inventory/outsider.yml init.yml --extra-vars "enable_setup=true enable_wireguard=true enable_k3s=true" + @make get_k3s_credentials destroy: - vagrant destroy -f + @echo "Destroy Homelab installation..." + @vagrant destroy -f get_k3s_credentials: - vagrant ssh -c "sudo cat /home/creator/.kube/config" hb-wide-1 > ~/.kube/config-halia - sed -i 's/10.20.*:/192.168.56.101:/g' ~/.kube/config-halia - kube-merge - kubectl get nodes --context halia + @echo "Retrieving k3s credentials locally..." + @vagrant ssh -c "sudo cat /home/creator/.kube/config" hb-wide-1 > ~/.kube/config-halia + @sed -i 's/10.20.*:/192.168.56.101:/g' ~/.kube/config-halia + @kube-merge + @kubectl get nodes --context halia +