Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

respect ignore_errors when extracting error messages from event data #329

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions internal/ansible/ansible.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,13 +430,17 @@ func extractFailureReason(ctx context.Context, eventsDir string) (string, error)
if err != nil {
return "", err
}
msgs = append(msgs, m)
if m != "" {
msgs = append(msgs, m)
}
case eventTypeRunnerUnreachable:
m, err := runnerEventMessage(evt, "Unreachable")
if err != nil {
return "", err
}
msgs = append(msgs, m)
if m != "" {
msgs = append(msgs, m)
}
default:
}
}
Expand Down Expand Up @@ -483,6 +487,9 @@ func runnerEventMessage(evt jobEvent, reason string) (string, error) {
if err := reunmarshal(evt.EventData, &evtData); err != nil {
return "", fmt.Errorf("unmarshaling job event %s as runner event: %w", evt.UUID, err)
}
if evtData.IgnoreErrors {
return "", nil
}

return fmt.Sprintf("%s on play %q, task %q, host %q: %s",
reason,
Expand Down
18 changes: 18 additions & 0 deletions internal/ansible/ansible_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,20 @@ func TestExtractFailureReason(t *testing.T) {
}
`

runnerFailedIgnoreErrorsEvt := `
{
"uuid": "7097758b-1109-4fd9-af59-f545633794dd",
"event": "runner_on_failed",
"event_data": {
"play": "test",
"task": "file",
"host": "testhost",
"res": {"msg": "fake error"},
"ignore_errors": true
}
}
`

runnerUnreachableEvt := `
{
"uuid": "ded6289b-e557-48c1-88e1-88eb630aec21",
Expand All @@ -289,6 +303,10 @@ func TestExtractFailureReason(t *testing.T) {
events: []string{playbookStartEvt, runnerFailedEvt},
expectedReason: `Failed on play "test", task "file", host "testhost": fake error`,
},
"FailedEventWithIgnoreErrors": {
events: []string{playbookStartEvt, runnerFailedIgnoreErrorsEvt},
expectedReason: "",
},
"UnreachableEvent": {
events: []string{playbookStartEvt, runnerUnreachableEvt},
expectedReason: `Unreachable on play "test", task "Gathering Facts", host "testhost": Failed to connect to the host via ssh`,
Expand Down
9 changes: 5 additions & 4 deletions internal/ansible/jobEvent.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ type jobEvent struct {
}

type runnerEventData struct {
Play string `json:"play"`
Task string `json:"task"`
Host string `json:"host"`
Result runnerResult `json:"res"`
Play string `json:"play"`
Task string `json:"task"`
Host string `json:"host"`
Result runnerResult `json:"res"`
IgnoreErrors bool `json:"ignore_errors"`
}

type runnerResult struct {
Expand Down
Loading