diff --git a/internal/exec/stages/files/units.go b/internal/exec/stages/files/units.go index b7f93c8032..e582087e4a 100644 --- a/internal/exec/stages/files/units.go +++ b/internal/exec/stages/files/units.go @@ -19,6 +19,7 @@ import ( "fmt" "path/filepath" "strings" + "sort" "github.com/coreos/ignition/v2/config/shared/errors" cutil "github.com/coreos/ignition/v2/config/util" @@ -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