Skip to content

Commit b16fd85

Browse files
authored
Add Vars map to manifest.Manifest (#21)
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

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ ipxe: true
100100
# which netbootd automatically points to be itself.
101101
# This should map to a "mount" below.
102102
bootFilename: install.ipxe
103+
# Arbitrary mapping of key/value pairs that can be substituted
104+
# in mount content templates below using {{ .Manifest.Vars.xxx }}
105+
vars:
106+
gfxpayload: 800x600x16,800x600
107+
auto: true
103108

104109
# Mounts define virtual per-host (per-manifest) paths that are acessible
105110
# over both TFTP and HTTP but only from the IP address of in this manifest.
@@ -133,7 +138,7 @@ mounts:
133138
set base {{ .HttpBaseUrl }}/netboot
134139
135140
{{ $hostnameParts := splitList "." .Manifest.Hostname }}
136-
kernel ${base}/linux gfxpayload=800x600x16,800x600 initrd=initrd.gz auto=true url={{ .HttpBaseUrl.String }}/preseed.txt netcfg/get_ipaddress={{ .Manifest.IPv4.IP }} netcfg/get_netmask={{ .Manifest.IPv4.Netmask }} netcfg/get_gateway={{ first .Manifest.Router }} netcfg/get_nameservers="{{ .Manifest.DNS | join " " }}" netcfg/disable_autoconfig=true hostname={{ first $hostnameParts }} domain={{ rest $hostnameParts | join "." }} DEBCONF_DEBUG=developer
141+
kernel ${base}/linux gfxpayload={{ .Manifest.Vars.gfxpayload }} initrd=initrd.gz auto={{ .Manifest.Vars.auto }} url={{ .HttpBaseUrl.String }}/preseed.txt netcfg/get_ipaddress={{ .Manifest.IPv4.IP }} netcfg/get_netmask={{ .Manifest.IPv4.Netmask }} netcfg/get_gateway={{ first .Manifest.Router }} netcfg/get_nameservers="{{ .Manifest.DNS | join " " }}" netcfg/disable_autoconfig=true hostname={{ first $hostnameParts }} domain={{ rest $hostnameParts | join "." }} DEBCONF_DEBUG=developer
137142
initrd ${base}/initrd.gz
138143
boot
139144
```

manifest/schema.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type Manifest struct {
2727
BootFilename string `yaml:"bootFilename"`
2828
Mounts []Mount
2929
Suspended bool
30+
Vars map[string]interface{}
3031
}
3132

3233
// Mount represents a path exposed via TFTP and HTTP.

0 commit comments

Comments
 (0)