diff --git a/Makefile b/Makefile index 24374ae..8351c4e 100644 --- a/Makefile +++ b/Makefile @@ -5,8 +5,10 @@ TOKEN = $(shell ansible-vault decrypt --vault-password-file \ ~/.config/ansible/hcloud.secret --output - \ group_vars/all/vars.yaml | cut -d' ' -f2) +SNAPNAME = $(shell cat group_vars/all/all.yaml | yq .snapshot) + SNAPSHOT = $(shell hcloud image list -t snapshot -o yaml | \ - yq '. | map(select(.description == "FreeBSD-14.1-RELEASE-hcloud-init")) | .[].id') + yq '. | map(select(.description == "$(SNAPNAME)")) | .[].id') OPTIONS = -i inventory -t active CREATE_COMMAND = ansible-playbook create.yaml $(OPTIONS) @@ -17,6 +19,9 @@ DEBUG_COMMAND = ansible-playbook debug.yaml $(OPTIONS) ENV = HCLOUD_TOKEN="$(TOKEN)" SNAPSHOT="$(SNAPSHOT)" ANSIBLE_VERBOSITY=$(verbose) +test: + @echo SNAPSHOT="$(SNAPSHOT)" + all: create deploy debug: diff --git a/README.md b/README.md index 71dcabb..6726237 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ## Ansible roles and playbook to maintain bsdnix.de -### Basics +### Prepare hetzner cloud In order to be able to deploy freebsd vps' on Hetzner cloud you need to do: @@ -16,14 +16,14 @@ In order to be able to deploy freebsd vps' on Hetzner cloud you need to do: - shutdown the vps - create a snapshot, name it visely, I name mine like: `FreeBSD-14.1-RELEASE-hcloud-init` - delete the builder vps +- update the snapshot name in `group_vars/all/all.yaml` Then you can deploy new freebsd vps' using this snapshot. They'll come up, configure themselves to be reachable. -The `deploy.yaml` playbook will then use the hetzner cloud dynamic -inventory to discover your vps. So, you have to call `make deploy` -twice: once to deploy a new vps and second time to configure -it. Subsequent calls only configure of course. +The `create.yaml` playbook will create a new vps if it doesn't exist +yet and the `deploy.yaml` playbook will then use the hetzner cloud +dynamic inventory to discover your vps. ### Setup ansible @@ -61,3 +61,24 @@ To make the output more verbose, add `verbose=N` to the target, e.g.: `make depoy verbose=2` where N is the verbosity level (0-4) If you want to execute only a subset of a playbook, remove the `active` tag from it. + +### Updating + +(not yet completely determined!) + +- create a new release snapshot as outlined above +- add a new vps to the local inventory (`inventory/vps.yaml`) +- run `make` +- remove the old vps + +or: just call `freebsd-update** - however, if you ever need to rebuild +the vps, then it will come up with the - then - old release. So, +better rebuild from scratch to update. + +### Deleting + +**CAUTION** the `cleanup.yaml` playbook removes **ALL** running vps +instances! Better use the `hcloud` cli to do this. The cleanup +playbook just exists to make development of the deployment easier so +that I don't need to pay for an non-ready instance running while I'm +not working on it. diff --git a/group_vars/all/all.yaml b/group_vars/all/all.yaml index 32b479c..853f5ce 100644 --- a/group_vars/all/all.yaml +++ b/group_vars/all/all.yaml @@ -11,6 +11,9 @@ packages: # used by bastille to build a base release: 14.1-RELEASE +# snapshot to install in new vps +snapshot: FreeBSD-14.1-RELEASE-hcloud-init + location: fsn1 # must already exist in group project