2022-10-14 16:53:40 +02:00
|
|
|
---
|
|
|
|
title: Cloud-Init
|
2023-06-15 16:53:21 +02:00
|
|
|
visible: true
|
2022-10-14 16:53:40 +02:00
|
|
|
---
|
|
|
|
|
|
|
|
[toc]
|
2022-12-09 08:59:48 +01:00
|
|
|
|
2022-10-14 16:53:40 +02:00
|
|
|
## VM Preparation
|
2022-12-09 08:59:48 +01:00
|
|
|
|
|
|
|
The VM template needs a few cloud-init tools installed before we can use it with cloud-init configs
|
2022-10-14 16:53:40 +02:00
|
|
|
|
|
|
|
### Debian
|
2022-12-09 08:59:48 +01:00
|
|
|
|
2023-06-02 19:25:19 +02:00
|
|
|
[shroot]
|
|
|
|
|
2023-02-19 15:21:41 +01:00
|
|
|
```sh
|
|
|
|
apt install cloud-init cloud-initramfs-growroot
|
|
|
|
```
|
2022-10-14 16:53:40 +02:00
|
|
|
|
2023-06-02 19:25:19 +02:00
|
|
|
[/shroot]
|
|
|
|
|
2023-06-15 16:53:21 +02:00
|
|
|
## Cloud-init
|
2022-12-09 08:59:48 +01:00
|
|
|
|
|
|
|
Cloud-init has a config file in `/etc/cloud/cloud.cfg`
|
2023-06-15 16:53:21 +02:00
|
|
|
|
|
|
|
### Growing partitions
|
|
|
|
|
|
|
|
With growroot installed in the initramfs, cloud-init will expand partitions and filesystems to fit the root partition given.
|
|
|
|
|
|
|
|
### XCP-ng: Set Hostname
|
|
|
|
|
|
|
|
This cloud config snippet sets the machine hostname to the VM name.
|
|
|
|
|
|
|
|
```
|
|
|
|
#cloud-config
|
|
|
|
hostname: {name}
|
|
|
|
```
|
|
|
|
|
|
|
|
## Network config
|
|
|
|
|
|
|
|
The network config is a special config file with cloud-init that focuses on specifying network settings.
|
|
|
|
|
|
|
|
### Set Static IP
|
|
|
|
|
|
|
|
The snippet below sets a static ip address for the specified interface.
|
|
|
|
Its syntax mainly follows the `/etc/network/interfaces` syntax.
|
|
|
|
|
|
|
|
```
|
|
|
|
network:
|
|
|
|
version: 1
|
|
|
|
config:
|
|
|
|
- type: physical
|
|
|
|
name: [INTERFACE]
|
|
|
|
subnets:
|
|
|
|
- type: static
|
|
|
|
address: [ADDRESS]
|
|
|
|
gateway: [ADDRESS]
|
|
|
|
dns_nameservers: [ADDRESS]
|
|
|
|
```
|