Skip to content

Commit 2b80e7f

Browse files
authored
Merge pull request #2678 from afbjorklund/ansible-path
Validate that the playbook path actually exists
2 parents 5db1b15 + e383ce0 commit 2b80e7f

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

pkg/limayaml/validate.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,18 @@ func Validate(y *LimaYAML, warn bool) error {
208208
return fmt.Errorf("field `provision[%d].mode` must one of %q, %q, %q, %q, or %q",
209209
i, ProvisionModeSystem, ProvisionModeUser, ProvisionModeBoot, ProvisionModeDependency, ProvisionModeAnsible)
210210
}
211+
if p.Playbook != "" {
212+
if p.Mode != ProvisionModeAnsible {
213+
return fmt.Errorf("field `provision[%d].mode must be %q if playbook is set", i, ProvisionModeAnsible)
214+
}
215+
if p.Script != "" {
216+
return fmt.Errorf("field `provision[%d].script must be empty if playbook is set", i)
217+
}
218+
playbook := p.Playbook
219+
if _, err := os.Stat(playbook); err != nil {
220+
return fmt.Errorf("field `provision[%d].playbook` refers to an inaccessible path: %q: %w", i, playbook, err)
221+
}
222+
}
211223
if strings.Contains(p.Script, "LIMA_CIDATA") {
212224
logrus.Warn("provisioning scripts should not reference the LIMA_CIDATA variables")
213225
}

0 commit comments

Comments
 (0)