1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318
|
---
nav_order: 4
---
# Example Configs
{: .no_toc }
These examples are written in version 3.0.0 of the config. Ignition v2.0.0+ understands all configs with version 3.0.0+.
1. TOC
{:toc}
## Services
### Start Services
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
{
"ignition": { "version": "3.0.0" },
"systemd": {
"units": [{
"name": "example.service",
"enabled": true,
"contents": "[Service]\nType=oneshot\nExecStart=/usr/bin/echo Hello World\n\n[Install]\nWantedBy=multi-user.target"
}]
}
}
```
`example.service`:
```ini
[Service]
Type=oneshot
ExecStart=/usr/bin/echo Hello World
[Install]
WantedBy=multi-user.target
```
### Modify Services
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`.
<!-- ignition -->
```json
{
"ignition": { "version": "3.0.0" },
"systemd": {
"units": [{
"name": "systemd-journald.service",
"dropins": [{
"name": "debug.conf",
"contents": "[Service]\nEnvironment=SYSTEMD_LOG_LEVEL=debug"
}]
}]
}
}
```
`systemd-journald.service.d/debug.conf`:
```ini
[Service]
Environment=SYSTEMD_LOG_LEVEL=debug
```
## 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].
<!-- ignition -->
```json
{
"ignition": { "version": "3.0.0" },
"storage": {
"files": [{
"path": "/etc/someconfig",
"mode": 420,
"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.
## Reformat the /var Filesystem
### 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.
<!-- ignition -->
```json
{
"ignition": { "version": "3.0.0" },
"storage": {
"filesystems": [{
"device": "/dev/disk/by-label/VAR",
"path": "/var",
"format": "btrfs",
"wipeFilesystem": true,
"label": "VAR"
}],
"files": [{
"path": "/var/example-asset",
"mode": 420,
"contents": {
"source": "http://example.com/asset",
"verification": { "hash": "sha512-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" }
}
}]
}
}
```
The SHA512 sum of the file can be determined using `sha512sum`. SHA256 sums are also supported, and can be calculated using `sha256sum`.
## 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
{
"ignition": { "version": "3.0.0" },
"storage": {
"disks": [
{
"device": "/dev/sdb",
"wipeTable": true,
"partitions": [{
"label": "raid.1.1",
"number": 1,
"sizeMiB": 1024,
"startMiB": 0
}]
},
{
"device": "/dev/sdc",
"wipeTable": true,
"partitions": [{
"label": "raid.1.2",
"number": 1,
"sizeMiB": 1024,
"startMiB": 0
}]
}
],
"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"
}]
},
"systemd": {
"units": [{
"name": "var-lib-data.mount",
"enabled": true,
"contents": "[Mount]\nWhat=/dev/md/data\nWhere=/var/lib/data\nType=ext4\n\n[Install]\nWantedBy=local-fs.target"
}]
}
}
```
`var-lib-data.mount`:
```ini
[Mount]
What=/dev/md/data
Where=/var/lib/data
Type=ext4
[Install]
WantedBy=local-fs.target
```
## Replace the Config with a Remote Config
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
{
"ignition": {
"version": "3.0.0",
"config": {
"replace": {
"source": "http://example.com/config.json",
"verification": { "hash": "sha512-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" }
}
}
}
}
```
The SHA512 sum of the config can be determined using `sha512sum`. SHA256 sums are also supported, and can be calculated using `sha256sum`.
## Set the Hostname
Setting the hostname of a system is as simple as writing `/etc/hostname`:
<!-- ignition -->
```json
{
"ignition": { "version": "3.0.0" },
"storage": {
"files": [{
"path": "/etc/hostname",
"mode": 420,
"overwrite": true,
"contents": { "source": "data:,core1" }
}]
}
}
```
## 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
{
"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
```
## 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
{
"ignition": {"version": "3.3.0"},
"kernelArguments": {
"shouldExist": ["example", "foo bar"],
"shouldNotExist": ["somekarg"]
}
}
```
[rfc2397]: http://tools.ietf.org/html/rfc2397
[operator-notes]: operator-notes.md
|