Skip to content

Commit a316f7d

Browse files
Fix operator-framework#4530: not able to test ansible operator locally
Signed-off-by: rashmigottipati <[email protected]>
1 parent 2ddde63 commit a316f7d

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

internal/ansible/runner/runner.go

+14-3
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ const (
4848
// to the ansible-runner command. This will override the value for a particular CR.
4949
// Example usage "ansible.sdk.operatorframework.io/verbosity: 5"
5050
AnsibleVerbosityAnnotation = "ansible.sdk.operatorframework.io/verbosity"
51+
52+
ansibleRunnerBin = "ansible-runner"
5153
)
5254

5355
// Runner - a runnable that should take the parameters and name and namespace
@@ -128,6 +130,10 @@ func New(watch watches.Watch, runnerArgs string) (Runner, error) {
128130
return nil, err
129131
}
130132

133+
if _, err := exec.LookPath(ansibleRunnerBin); err != nil {
134+
return nil, err
135+
}
136+
131137
switch {
132138
case watch.Playbook != "":
133139
path = watch.Playbook
@@ -277,11 +283,16 @@ func (r *runner) Run(ident string, u *unstructured.Unstructured, kubeconfig stri
277283
// link the current run to the `latest` directory under artifacts
278284
currentRun := filepath.Join(inputDir.Path, "artifacts", ident)
279285
latestArtifacts := filepath.Join(inputDir.Path, "artifacts", "latest")
280-
if _, err = os.Lstat(latestArtifacts); err == nil {
281-
if err = os.Remove(latestArtifacts); err != nil {
282-
logger.Error(err, "Error removing the latest artifacts symlink")
286+
if _, err = os.Lstat(latestArtifacts); err != nil {
287+
if !errors.Is(err, os.ErrNotExist) {
288+
logger.Error(err, "Latest artifacts dir doesn't exist")
289+
return
283290
}
291+
} else if err = os.Remove(latestArtifacts); err != nil {
292+
logger.Error(err, "Error removing the latest artifacts symlink")
293+
return
284294
}
295+
285296
if err = os.Symlink(currentRun, latestArtifacts); err != nil {
286297
logger.Error(err, "Error symlinking latest artifacts")
287298
}

0 commit comments

Comments
 (0)