This ansible playbook can be used to automize the deployment of Hetzner servers with Debian Stretch. It uses the
installimage script that is provided by Hetzner inside of their rescue system.
What does it do?
Primary it calls the
installimage script which you can find in a running rescue system of Hetzner. Usually you have to configure the script manually in an editor. This playbook answers all questions as parameters for a fully automated installation. It also reboots the server after the installation.
In its current state the playbook makes a lot of assumptions about your desired configuration.
- The inventory hostname is used as the new hostname.
- grub is installed as bootloader.
- sda and sdb are configured as a level 1 software raid.
- All partitions are ext4.
- 1GB for /boot (Yes that is a lot...)
- 50GB for /
- A swap partition half as big as your RAM.
- The rest of the disks is configured as a LVM group with the name
To force the
installimage script to create a volume group without any volumes the playbook creates a dummy volume and removes it after the installation is complete. Of course this is a bad way to do this but it works for now.
"But this playbook should be more flexible!?"
Yes, you are right! In the current state it works for my personal use cases. If my requirements change in the future I will update the playbook accordingly. If you use this playbook and update it to make it more configurable then please open a pull request! :)
How to use this playbook
I assume that you already have a working ansible installation. For this example we use the following configuration.
[defaults] inventory = hosts
server.example.com [all:vars] deployment_key = ~/.ssh/core_deployment public_root_key = ~/.ssh/root_key.pub
- Generate two pairs of SSH keys (
ssh-keygen -t ed25519). For example
- Make sure you specified the correct paths to the keys in your hosts file or in some of the many ways that ansible allows to handle host variables.
- Login to your Hetzner robot webinterface.
- Go to your server, select the Rescue tab and upload the
core_deployment.pubpublic key file in Hetzners key management.
- Then you enable the rescue system and select the uploaded key for SSH access.
- Reboot the server. It will boot into Hetzners rescue system.
- Run the playbook. You need to specify the inventory hostname as an extra variable:
ansible-playbook deploy_debian_hetzner.yml -e 'target_host=server.example.com'THIS WILL DELETE ALL DATA FROM YOUR SERVER WITHOUT ANY QUESTION
- This will install Debian Stretch and wait for the server to be rebooted. In my tests it took about three minutes.
- Login to your server with the
I do not work for Hetzner and this software is in no official way connected to Hetzner.