diff --git a/internal/exec/stages/files/units.go b/internal/exec/stages/files/units.go index b7f93c8032..60aeedf8be 100644 --- a/internal/exec/stages/files/units.go +++ b/internal/exec/stages/files/units.go @@ -18,6 +18,7 @@ import ( "context" "fmt" "path/filepath" + "sort" "strings" "github.com/coreos/ignition/v2/config/shared/errors" @@ -151,7 +152,16 @@ func (s *stage) createSystemdPresetFile(presets map[string]*Preset) error { return err } hasInstanceUnit := false - for _, value := range presets { + + // sort the units before writing to the systemd presets file + unitNames := make([]string, 0, len(presets)) + for unit := range presets { + unitNames = append(unitNames, unit) + } + sort.Strings(unitNames) + + for i := range unitNames { + value := presets[unitNames[i]] unitString := value.unit if value.instantiatable { hasInstanceUnit = true