hetznertool - create VMs in the Hetzner Cloud for QvarnLabs Ab ============================================================================= `hetznertool` is a little utility to make it easier to manage VMs in the Hetzner Cloud. It's inspired by the OpenStack Heat tooling we've used before. The utility can: * list all servers in all hcloud contexts * create servers in a context based on a YAML specification file * also, update DNS (`CONTEXT-PROJECT.h.qvarnlabs.eu`) * also, write Ansible inventory files * delete all servers in a named context Requirements ============================================================================= * Python 3 * `hcloud` from * Download, unpack tarball from above URL. * Move `bin/hcloud` into a location on the PATH. * Create one or more contexts by going adding projects, ssh keys, and access tokens via the Hetzner Cloud console. (See below.) * Get `hetznertool` with git clone from `ssh://git@git.qvarnlabs.net/hetznertool` Preparation: Hetzner project creation ----------------------------------------------------------------------------- Log into https://console.hetzner.cloud/projects Create projects as needed, add ssh keys to them, and create access tokens for each. Use the access tokens to create "contexts" for `hcloud` (run `hcloud context create FOO`, it will ask for the access token). Use the ssh token at once when creating it: it cannot be recovered later (but a new one can be created at will). Not that it's not necessary to store the access token elsewhere, but do guard the `.config/hcloud/cli.toml` file, which is where `hcloud` stores the access tokens. `hcloud` does not seem to have a way to store that in `pass` or similar. Avoid sharing `cli.toml` with anyone. This only needs to be done once per project. Use ============================================================================= All `hetznertool` invocations should be done in the directory to where you cloned it. Config ----------------------------------------------------------------------------- Create `~/.config/hetznertool/hetznertool.yaml`: ssh-key: liw-openpgp ansible-inventory-dir: /home/liw/qvarnlabs/code/qvarn-prov/ansible (edit values as suits you). List ----------------------------------------------------------------------------- List all servers: ./hetznercloud list Create ----------------------------------------------------------------------------- Create a server specification file (`qvarn.servers`): defaults: type: cx11 image: debian-9 hosts: - name: haproxy type: cx51 - name: qvarn1 - name: qvarn2 - name: qvarn3 - name: qvarn4 - name: postgres type: cx51 - name: qvisvqe Values from `defaults` are used if a dict in the list in `hosts` doesn't specify a value. Create servers (may take a minute per server): ./hetznertool create mydev qvarn.server (where `mydev` is the name of a context). This will write inventory files and update DNS, creating names like `mydev-haproxy.h.qvarnlabs.eu`. Delete ----------------------------------------------------------------------------- Delete sll servers in a context: ./hetznertool delete mydev This will also rewrite zone and inventory files to update them to any remaining servers. To run Ansible ----------------------------------------------------------------------------- ansible-playbook -i hosts.mydev playbook.yml Problems? ============================================================================= Ask in the company Matrix room.