1
0
mirror of https://github.com/coreos/ignition.git synced 2026-02-06 18:47:54 +01:00
Files
ignition/docs/examples.md

319 lines
8.3 KiB
Markdown
Raw Permalink Normal View History

---
nav_order: 4
---
2016-03-23 16:27:13 -07:00
# Example Configs
2020-09-14 15:26:14 +02:00
{: .no_toc }
2016-03-23 16:27:13 -07:00
These examples are written in version 3.0.0 of the config. Ignition v2.0.0+ understands all configs with version 3.0.0+.
2016-03-23 16:27:13 -07:00
2020-09-14 15:26:14 +02:00
1. TOC
{:toc}
2016-11-19 14:20:28 +01:00
## Services
2017-05-15 15:30:01 -07:00
### Start Services
2016-03-23 16:27:13 -07:00
This config will write a single service unit (shown below) with the contents of an example service. This unit will be enabled as a dependency of multi-user.target and therefore start on boot.
<!-- ignition -->
```json
2016-03-23 16:27:13 -07:00
{
"ignition": { "version": "3.0.0" },
2016-03-23 16:27:13 -07:00
"systemd": {
"units": [{
"name": "example.service",
"enabled": true,
2016-03-23 16:27:13 -07:00
"contents": "[Service]\nType=oneshot\nExecStart=/usr/bin/echo Hello World\n\n[Install]\nWantedBy=multi-user.target"
}]
}
}
```
`example.service`:
2016-03-23 16:27:13 -07:00
```ini
2016-03-23 16:27:13 -07:00
[Service]
Type=oneshot
ExecStart=/usr/bin/echo Hello World
[Install]
WantedBy=multi-user.target
```
2017-01-12 00:59:01 -08:00
2017-05-15 15:30:01 -07:00
### Modify Services
2016-11-19 14:20:28 +01:00
This config will add a [systemd unit drop-in](https://www.freedesktop.org/software/systemd/man/systemd.unit.html#Description) to modify the existing service `systemd-journald` and sets its environment variable `SYSTEMD_LOG_LEVEL` to `debug`.
2016-11-19 14:20:28 +01:00
<!-- ignition -->
```json
2016-11-19 14:20:28 +01:00
{
"ignition": { "version": "3.0.0" },
2016-11-19 14:20:28 +01:00
"systemd": {
"units": [{
"name": "systemd-journald.service",
2016-11-19 14:20:28 +01:00
"dropins": [{
"name": "debug.conf",
"contents": "[Service]\nEnvironment=SYSTEMD_LOG_LEVEL=debug"
}]
}]
}
}
```
`systemd-journald.service.d/debug.conf`:
2016-11-19 14:20:28 +01:00
```ini
2016-11-19 14:20:28 +01:00
[Service]
Environment=SYSTEMD_LOG_LEVEL=debug
```
2016-03-23 16:27:13 -07:00
## Create Files on the Root Filesystem
In many cases it is useful to write files to the root filesystem. This example writes a single file to `/etc/someconfig` on the root filesystem. The contents of the file ("example file") are specified inline in the config using the [data URL scheme][rfc2397].
2016-03-23 16:27:13 -07:00
<!-- ignition -->
```json
2016-03-23 16:27:13 -07:00
{
"ignition": { "version": "3.0.0" },
2016-03-23 16:27:13 -07:00
"storage": {
"files": [{
"path": "/etc/someconfig",
"mode": 420,
2016-03-23 16:27:13 -07:00
"contents": { "source": "data:,example%20file%0A" }
}]
}
}
```
Paths are specified relative to the root filesystem of the system Ignition is configuring. Symlinks are followed as if Ignition was running from the final system. See the [operator notes][operator-notes] for more information about how Ignition follows symlinks.
2016-03-23 16:27:13 -07:00
## Reformat the /var Filesystem
2016-03-23 16:27:13 -07:00
### Btrfs
This example Ignition configuration will locate the device with the "VAR" filesystem label and reformat it to btrfs, recreating the filesystem label. The `wipeFilesystem` option is set to ensure that Ignition ignores any existing filesystem. This configuration also writes a file to `/var/example-asset`, fetching its contents from `https://example.com/asset`. Ignition mounts filesystems it creates at the specified `path` before creating anything on the filesystems, ensuring `/var/example-asset` is created on the newly created filesystem. Note that Ignition will not automatically create mount units or `/etc/fstab` entries for the filesystems it creates. In this case we assume the OS already has a mount unit or `/etc/fstab` entry for the `/var` filesystem by label.
2016-03-23 16:27:13 -07:00
<!-- ignition -->
```json
2016-03-23 16:27:13 -07:00
{
"ignition": { "version": "3.0.0" },
2016-03-23 16:27:13 -07:00
"storage": {
"filesystems": [{
"device": "/dev/disk/by-label/VAR",
"path": "/var",
"format": "btrfs",
"wipeFilesystem": true,
"label": "VAR"
}],
2016-03-23 16:27:13 -07:00
"files": [{
"path": "/var/example-asset",
"mode": 420,
2016-03-23 16:27:13 -07:00
"contents": {
"source": "http://example.com/asset",
"verification": { "hash": "sha512-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" }
}
}]
}
}
```
2020-04-27 10:19:39 -04:00
The SHA512 sum of the file can be determined using `sha512sum`. SHA256 sums are also supported, and can be calculated using `sha256sum`.
2016-03-23 16:27:13 -07:00
## Create a RAID-enabled Data Volume
In many scenarios, it may be useful to have an external data volume. This config will set up a RAID0 ext4 volume, `data`, between two separate disks. It also writes a mount unit (shown below) which will automatically mount the volume to `/var/lib/data`.
<!-- ignition -->
```json
2016-03-23 16:27:13 -07:00
{
"ignition": { "version": "3.0.0" },
2016-03-23 16:27:13 -07:00
"storage": {
"disks": [
{
"device": "/dev/sdb",
"wipeTable": true,
"partitions": [{
"label": "raid.1.1",
"number": 1,
"sizeMiB": 1024,
"startMiB": 0
2016-03-23 16:27:13 -07:00
}]
},
{
"device": "/dev/sdc",
"wipeTable": true,
"partitions": [{
"label": "raid.1.2",
"number": 1,
"sizeMiB": 1024,
"startMiB": 0
2016-03-23 16:27:13 -07:00
}]
}
],
"raid": [{
"devices": [
"/dev/disk/by-partlabel/raid.1.1",
"/dev/disk/by-partlabel/raid.1.2"
],
"level": "stripe",
"name": "data"
}],
"filesystems": [{
"device": "/dev/md/data",
"path": "/var/lib/data",
"format": "ext4",
"label": "DATA"
2016-03-23 16:27:13 -07:00
}]
},
"systemd": {
"units": [{
"name": "var-lib-data.mount",
"enabled": true,
2016-03-23 16:27:13 -07:00
"contents": "[Mount]\nWhat=/dev/md/data\nWhere=/var/lib/data\nType=ext4\n\n[Install]\nWantedBy=local-fs.target"
}]
}
}
```
`var-lib-data.mount`:
2016-03-23 16:27:13 -07:00
```ini
2016-03-23 16:27:13 -07:00
[Mount]
What=/dev/md/data
2016-03-23 16:27:13 -07:00
Where=/var/lib/data
Type=ext4
[Install]
WantedBy=local-fs.target
```
2017-05-15 15:30:01 -07:00
## Replace the Config with a Remote Config
2016-03-23 16:27:13 -07:00
In some cloud environments, there is a limit on the size of the config which may be provided to a machine. To work around this, Ignition allows configs to be replaced with the contents of an alternate, remote config. The following demonstrates this, using a SHA512 sum to verify the contents of the config.
<!-- ignition -->
```json
2016-03-23 16:27:13 -07:00
{
"ignition": {
"version": "3.0.0",
2016-03-23 16:27:13 -07:00
"config": {
"replace": {
"source": "http://example.com/config.json",
"verification": { "hash": "sha512-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" }
}
}
}
}
```
2020-04-27 10:19:39 -04:00
The SHA512 sum of the config can be determined using `sha512sum`. SHA256 sums are also supported, and can be calculated using `sha256sum`.
2016-03-23 16:27:13 -07:00
2017-05-15 15:30:01 -07:00
## Set the Hostname
2016-07-05 17:37:41 -07:00
Setting the hostname of a system is as simple as writing `/etc/hostname`:
<!-- ignition -->
```json
2016-07-05 17:37:41 -07:00
{
"ignition": { "version": "3.0.0" },
2016-07-05 17:37:41 -07:00
"storage": {
"files": [{
"path": "/etc/hostname",
"mode": 420,
2019-05-14 11:01:54 +02:00
"overwrite": true,
2016-07-05 17:37:41 -07:00
"contents": { "source": "data:,core1" }
}]
}
}
```
2017-05-15 15:30:01 -07:00
## Add Users
Users can be added to an OS with the `passwd.users` key which takes a list of objects that specify a given user. If you wanted to configure a user "systemUser" and a user "jenkins" you would do that as follows:
<!-- ignition -->
```json
{
"ignition": { "version": "3.0.0" },
"passwd": {
"users": [
{
"name": "systemUser",
"passwordHash": "$superSecretPasswordHash.",
"sshAuthorizedKeys": [
"ssh-rsa veryLongRSAPublicKey"
]
},
{
"name": "jenkins",
"uid": 1000
}
]
}
}
```
To add more users, configure them within the `users` list structure (`[...]`).
## Create a LUKS Volume
This config will set up a key-file based LUKS2 volume, `data`, put a filesystem on the volume, and write a mount unit (shown below) to automatically mount the volume to `/var/lib/data`.
<!-- ignition -->
```json
{
2020-09-28 23:30:28 -05:00
"ignition": {"version": "3.2.0"},
"storage": {
"luks": [{
"name": "data",
"device": "/dev/sdb"
}],
"filesystems": [{
"path": "/var/lib/data",
"device": "/dev/disk/by-id/dm-name-data",
"format": "ext4",
"label": "DATA"
}]
},
"systemd": {
"units": [{
"name": "var-lib-data.mount",
"enabled": true,
"contents": "[Mount]\nWhat=/dev/disk/by-label/DATA\nWhere=/var/lib/data\nType=ext4\n\n[Install]\nWantedBy=local-fs.target"
}]
}
}
```
`var-lib-data.mount`:
```ini
[Mount]
What=/dev/disk/by-label/DATA
Where=/var/lib/data
Type=ext4
[Install]
WantedBy=local-fs.target
```
2021-05-05 23:28:27 -05:00
## Set Kernel Arguments
This config will ensure that the `example` and `foo bar` kernel arguments are set and the `somekarg` kernel argument is not set.
<!-- ignition -->
```json
{
2021-06-22 17:02:34 -04:00
"ignition": {"version": "3.3.0"},
2021-05-05 23:28:27 -05:00
"kernelArguments": {
"shouldExist": ["example", "foo bar"],
"shouldNotExist": ["somekarg"]
}
}
```
2016-03-23 16:27:13 -07:00
[rfc2397]: http://tools.ietf.org/html/rfc2397
[operator-notes]: operator-notes.md