Skip to content

Latest commit

 

History

History
217 lines (141 loc) · 4.64 KB

ansible.adoc

File metadata and controls

217 lines (141 loc) · 4.64 KB

Hetzner Ansible

Introduction

This document describes the Ansible playbooks implemented.

Scope

Describe the steps to install the hetzner client and provision hetzner cloud VMs.

Requirements

Read the README.adoc and README-cloud.adoc documents.

Playbooks

Although there are several playbooks available, for creating and deleting hetzner VMs 2 of them should be used. Other playbooks are used as dependencies for these main playbooks

Create Passstore VM

The playbook for creating a passwordstore based VM is hetzner_vm_create_passwordstore.yml which is located at ansible/playbook/hetzner/.

To create a new VM execute the following command

Create passwordstore VM on Hetzner
ansible-playbook ansible/playbook/hetzner/hetzner_vm_create_passwordstore.yml -e vm_name=snowdrop-vm -e k8s_type=masters -e k8s_version=123 -e salt_text=$(gpg --gen-random --armor 1 20) -e vm_image=fedora-37 -e server_type=cx21

The parameters are the following.

Table 1. Script options
Parameter Description

k8s_type

string

Type of k8s node

Choices:

  • master

  • node

k8s_version

string

Kubernetes version

Choices:

  • 124: Kubernetes 1.24

  • 123: Kubernetes 1.23

  • 121: Kubernetes 1.21

  • 119: Kubernetes 1.19

Warning

The kubernetes version must be mapped at Ansible Inventory level, on the hosts.yaml file located at the ansible/inventory subfolder.

salt_text

string

required

Salt to be used on the generation of the host user password.

Usually the following script is used: $(gpg --gen-random --armor 1 20).

server_type

string

The flavor of the servier in terms of CPU and RAM.

vm_image

string

vm_name

string

required

Name to be given to the VM.

Note

More information on the k8s_type

Click to see the sample yaml file contents
link:../ansible/inventory/hosts.yml[role=include]
Note

More information on the k8s_version

Click to see the sample yaml file contents
link:../ansible/inventory/hosts.yml[role=include]

Delete Passstore VM

The playbook for deleting a passwordstore based VM is hetzner_vm_delete_passwordstore.yml which is located at ansible/playbook/hetzner/.

To delete a new VM execute the following command.

Delete a passwordstore VM on Hetzner
ansible-playbook ansible/playbook/hetzner/hetzner_vm_delete_passwordstore.yml -e vm_name=snowdrop-vm

Configuration Playbooks

Init the hetzner context

Initializes the Hetzner context.

$ ansible-playbook hetzner/ansible/hetzner-init-context.yml

This playbook has the following variables.

Variable Required Prompt Meaning

hetzner_context_name

x

x

context name

hetzner_token

x

x

The token to register with Hetzner.

Each of the Ansible prompts can be replaced by defining it’s value as an extra variable of the playbook.

$ ansible-playbook hetzner/ansible/hetzner-init-context.yml -e hetzner_context_name=mycontext -e hetzner_token=mytoken

Other Playbooks

Several playbooks have been created to interact with Hetzner which are described in this section.

The playbooks with _passwordstore suffix have been developed with storing information on a pass database.

hetzner_ssh_key_create

Prior to creating a new VM, the SSH key generated by the Ansible Inventory must be added to the Hetzner SSH Key repository. This SSH will then be used in the server creation.

This is accomplished using the [hetzner-create-ssh-key](ansible/hetzner-create-ssh-key.yml) playbook which will create an SSH Key with the name of the

Table 2. hetzner_ssh_key_create playbook options

vm_name

string

required

Name of the VM to be created at hetzner.

Example 1. hetzner_ssh_key_create playbook sample
$ ansible-playbook hetzner/ansible/hetzner-create-ssh-key.yml -e vm_name=${VM_NAME}