Commit b16fd85
authored
Add new `Vars` map to `manifest.Manifest` which can store arbitrary
key/value pairs to aide in programmatically creating manifests from a
template. For example, given the following manifest template
`manifest.yml.template`:
```
---
id: rocky9.5
ipv4: REPLACE_ME
leaseDuration: 1h
mac:
- REPLACE_ME
dns:
- REPLACE_ME
router:
- REPLACE_ME
ntp:
- REPLACE_ME
ipxe: true
bootFilename: install.ipxe
vars:
rootpw: "REPLACE_ME"
nwidgerpw: "REPLACE_ME"
sshkey: "REPLACE_ME"
mounts:
- path: /repo
pathIsPrefix: true
proxy: https://dl.rockylinux.org/vault/rocky/9.5
appendSuffix: true
- path: /ks
content: |
text
%addon com_redhat_kdump --enable --reserve-mb='auto'
%end
keyboard --xlayouts='us'
lang en_US.UTF-8
network --bootproto=dhcp --device=link
%packages
@^server-product-environment
%end
firstboot --disable
skipx
ignoredisk --only-use=sda
autopart
clearpart --all --initlabel
timezone America/New_York --utc
rootpw --iscrypted --allow-ssh {{ .Manifest.Vars.rootpw }}
user --groups=wheel --name=nwidger --password={{ .Manifest.Vars.nwidgerpw }} --iscrypted --gecos="nwidger"
sshkey --username=nwidger "{{ .Manifest.Vars.sshkey }}"
%post --interpreter=/bin/bash --erroronfail
curl --fail-with-body '{{ .ApiBaseUrl }}/api/self/suspend-boot'
%end
reboot --eject
- path: /install.ipxe
content: |
#!ipxe
set base-repo {{ .HttpBaseUrl }}/repo
set base-ks {{ .HttpBaseUrl }}/ks
kernel ${base-repo}/BaseOS/x86_64/os/images/pxeboot/vmlinuz initrd=initrd.img inst.stage2=${base-repo}/BaseOS/x86_64/os inst.ks=${base-ks} inst.repo=${base-repo}/BaseOS/x86_64/os
initrd ${base-repo}/BaseOS/x86_64/os/images/pxeboot/initrd.img
boot
```
we can generate an actual manifest from the template using a tool like
`yq` (https://mikefarah.gitbook.io/yq/):
```
cp manifest.yml.template manifest.yml
yq -i 'ipv4 = "192.168.2.2/24"' manifest.yml
yq -i 'mac[0] = "12:23:34:45:56:67"' manifest.yml
yq -i 'dns[0] = "192.168.2.1"' manifest.yml
yq -i 'router[0] = "192.168.2.1"' manifest.yml
yq -i 'ntp[0] = "192.168.2.1"' manifest.yml
yq -i 'vars.rootpw = "<password>"' manifest.yml
yq -i 'vars.nwidgerpw = "<password>"' manifest.yml
yq -i 'vars.sshkey = "<ssh-key>"' manifest.yml
```
and can then use `{{ .Vars.Xxx }}` within templates, such as the `/ks`
kickstarter mount, to customize what is returned. Without `Vars`,
we'd need to do something like add placeholders such as `<ROOTPW>` in
the Kickstarter file and then run `sed` over `manifest.yml` to
substitute the values, which seems less clean.
1 parent 3d8d2ae commit b16fd85
2 files changed
+7
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
103 | 108 | | |
104 | 109 | | |
105 | 110 | | |
| |||
133 | 138 | | |
134 | 139 | | |
135 | 140 | | |
136 | | - | |
| 141 | + | |
137 | 142 | | |
138 | 143 | | |
139 | 144 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
| |||
0 commit comments