Skip to content

Using cloud config to configure you KVM server

Martin Bagge / brother edited this page Apr 27, 2024 · 5 revisions

When using the KVM platform you can provide a custom cloud-config file to configure and provision your server automatically.

Simple Example

#cloud-config
bootcmd:
  - echo 'Hello World!'

This cloud-config file can be passed to the API using the cloudconfig argument:

> POST /server/create HTTP/1.1
> Host: api.glesys.com
> Authorization: Basic ...
> Accept: application/json
> Content-Type: application/json

| {
|       "cloudconfig": "#cloud-config\nbootcmd:\n  - echo 'Hello World!'",
|       // ...
| }

This will create a server and run the command echo 'Hello World!' on first boot.

NOTE: No users will be created for the server in the example above. You can provide users in your cloud-config or use the templating feature below.

Templated Example

In addition to simple cloud-config files you can use Mustache templates if you prefix your cloud-config with ## template: glesys.

## template: glesys
#cloud-config
{{> users }}
bootcmd:
  - echo 'Hello {{params.name}}!'

The cloud-config above tells the GleSYS API to run it through a Mustache template compiler which gives you access to a partial named {{> users }} (see more below) and any parameters passed to cloudconfigparams:

> POST /server/create HTTP/1.1
> Host: api.glesys.com
> Authorization: Basic ...
> Accept: application/json
> Content-Type: application/json

| {
|       "cloudconfig": "## template: glesys\n#cloud-config\n{{> users }}\nbootcmd:\n  - echo 'Hello {{params.name}}!'",
|       "cloudconfigparams": {
|           "name": "Martin"
|       },
|       "users": [
|           { "username": "mbagge", "sshkeys": ["ssh-ed25519 ..."] }
|       ]
|       // ...
| }

This will create a server run the command echo 'Hello Martin!' on first boot as well as create a user named mbagge.

You can preview the compiled cloud-config file using the server/previewcloudconfig endpoint.

A note on users

If you don't pass a custom cloud-config we will provide one for you. This cloud-config includes the {{> users }} partial as it acts as a shortcut to create any users provided in the users argument. You can choose to provide a password or/and any number of SSH keys for any given user.

If you don't want to use the {{> users }} partial you can still access the provided users via the {{ users }} variable in your template.

Read more