Skip to content

Losing whitespace/indentation in bootcmd scripts #4319

@chancez

Description

@chancez

I'm attempting to write a bootcmd that uses a bash heredoc to write some YAML to provide some config overrides to cloudinit before the network is initialized, but the problem is that lima strips whitespace when writing bootcmds to the bootcmd in the user-data:

lima/pkg/cidata/cidata.go

Lines 491 to 499 in e21b634

if f.Mode == limatype.ProvisionModeBoot {
lines := []string{}
for _, line := range strings.Split(*f.Script, "\n") {
if line == "" {
continue
}
lines = append(lines, strings.TrimSpace(line))
}
bootCmds = append(bootCmds, BootCmds{Lines: lines})

Here's the relevant portion of my lima.yaml:

provision:
- mode: boot
  script: |
    cat <<EOF > /etc/cloud/cloud.cfg.d/99-lima1-disable-route.cfg
    ethernets:
      lima1:
        dhcp4-overrides:
          use-routes: false
    EOF

And here's what gets rendered in user-data:

bootcmd:
- |
  # We need to embed the params.env as a here-doc because /mnt/lima-cidata is not yet mounted
  while read -r line; do [ -n "$line" ] && export "$line"; done <<'EOF'
  EOF
  cat <<EOF > /etc/cloud/cloud.cfg.d/99-lima1-disable-route.cfg
  ethernets:
  lima1:
  dhcp4-overrides:
  use-routes: false
  EOF

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions