Skip to content

Commit

Permalink
Change StdoutLines and StderrLines type to []interface{}
Browse files Browse the repository at this point in the history
  • Loading branch information
apenella committed Apr 9, 2024
1 parent 78f6fa4 commit 1b7af13
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 9 deletions.
4 changes: 3 additions & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Release notes

## v2.0.0-rc.3
## v2.0.0-rc.4

Version 2.0.0 of *go-ansible* introduces several disruptive changes. Read the upgrade guide carefully before proceeding with the upgrade.

Expand All @@ -22,6 +22,7 @@ Version 2.0.0 of *go-ansible* introduces several disruptive changes. Read the up
- The constants `AnsibleForceColorEnv` and `AnsibleHostKeyCheckingEnv` have been removed from the `github.com/apenella/go-ansible/pkg/options` package.
- The functions `AnsibleForceColor`, `AnsibleAvoidHostKeyChecking` and `AnsibleSetEnv` have been removed from the `github.com/apenella/go-ansible/pkg/options` package. Use the `ExecutorWithAnsibleConfigurationSettings` decorator instead defined in the `github.com/apenella/go-ansible/v2/pkg/execute/configuration` package.
- The methods `WithWrite` and `WithShowduration` have been removed from the `ExecutorTimeMeasurement` decorator. Instead, a new method named `Duration` has been introduced for obtaining the duration of the execution.
- In the `AnsiblePlaybookJSONResultsPlayTaskHostsItem` struct, the attributes `StdoutLines` and `StderrLines` have chnage their type from `[]string` to `[]interface{}`.

### Fixed

Expand Down Expand Up @@ -52,6 +53,7 @@ Version 2.0.0 of *go-ansible* introduces several disruptive changes. Read the up

### Changed

- In the `AnsiblePlaybookJSONResultsPlayTaskHostsItem` struct, the attributes `StdoutLines` and `StderrLines` have chnage their type from `[]string` to `[]interface{}`.
- The `AnsibleAdhocCmd` struct has been updated to implement the `Commander` interface.
- The `AnsibleInventoryCmd` struct has been updated to implement the `Commander` interface.
- The `AnsiblePlaybookCmd` struct has been updated to implement the `Commander` interface.
Expand Down
4 changes: 2 additions & 2 deletions pkg/execute/result/json/ansiblePlaybookJSONResults.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ type AnsiblePlaybookJSONResultsPlayTaskHostsItem struct {
Msg interface{} `json:"msg"`
AnsibleFacts map[string]interface{} `json:"ansible_facts"`
Stdout interface{} `json:"stdout"`
StdoutLines []string `json:"stdout_lines"`
StdoutLines []interface{} `json:"stdout_lines"`
Stderr interface{} `json:"stderr"`
StderrLines []string `json:"stderr_lines"`
StderrLines []interface{} `json:"stderr_lines"`
Cmd interface{} `json:"cmd"`
Failed bool `json:"failed"`
FailedWhenResult bool `json:"failed_when_result"`
Expand Down
147 changes: 141 additions & 6 deletions pkg/execute/result/json/ansiblePlaybookJSONResults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -773,9 +773,9 @@ func TestParseJSONResultsStream(t *testing.T) {
Action: "command",
Changed: true,
Stdout: "",
StdoutLines: []string{},
StdoutLines: []interface{}{},
Stderr: "",
StderrLines: []string{},
StderrLines: []interface{}{},
Cmd: "/usr/bin/true",
Failed: false,
FailedWhenResult: false,
Expand Down Expand Up @@ -821,9 +821,9 @@ func TestParseJSONResultsStream(t *testing.T) {
Changed: true,
Msg: "non-zero return code",
Stdout: "",
StdoutLines: []string{},
StdoutLines: []interface{}{},
Stderr: "",
StderrLines: []string{},
StderrLines: []interface{}{},
Cmd: "exit -1",
Failed: true,
FailedWhenResult: false,
Expand All @@ -848,9 +848,9 @@ func TestParseJSONResultsStream(t *testing.T) {
Changed: true,
Msg: "non-zero return code",
Stdout: "",
StdoutLines: []string{},
StdoutLines: []interface{}{},
Stderr: "/usr/bin/ls: cannot access '/tmp/foobar.baz': No such file or directory",
StderrLines: []string{"/usr/bin/ls: cannot access '/tmp/foobar.baz': No such file or directory"},
StderrLines: []interface{}{"/usr/bin/ls: cannot access '/tmp/foobar.baz': No such file or directory"},
Cmd: []interface{}{"/usr/bin/ls", "/tmp/foobar.baz"},
Failed: true,
FailedWhenResult: true,
Expand All @@ -875,6 +875,141 @@ func TestParseJSONResultsStream(t *testing.T) {
},
},
},

{
desc: "Testing json parse using and slice of slices in the stdout_lines",
inputResult: `{
"custom_stats": {},
"global_custom_stats": {},
"plays": [
{
"play": {
"duration": {
"end": "2024-04-01T03:08:28.359220Z",
"start": "2024-04-01T03:08:25.115857Z"
},
"id": "ff523e0a-84a7-e3d6-229a-000000000006",
"name": "Slice of slices test"
},
"tasks": [
{
"hosts": {
"192.168.0.1": {
"_ansible_no_log": false,
"action": "ios_command",
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python3"
},
"changed": false,
"invocation": {
"module_args": {
"commands": [
"show version | incl Version"
],
"interval": 1,
"match": "all",
"provider": null,
"retries": 10,
"wait_for": null
}
},
"stdout": [
"One line\nAnother line\nEven another line\nLast line"
],
"stdout_lines": [
[
"One line",
"Another line",
"Even another line",
"Last line"
]
]
}
},
"task": {
"duration": {
"end": "2024-04-01T03:08:27.896416Z",
"start": "2024-04-01T03:08:25.148062Z"
},
"id": "ff523e0a-84a7-e3d6-229a-000000000008",
"name": "run show version on the routers"
}
}
]
}
],
"stats": {
"192.168.0.1": {
"changed": 0,
"failures": 0,
"ignored": 0,
"ok": 2,
"rescued": 0,
"skipped": 0,
"unreachable": 0
}
}
}`,
res: &AnsiblePlaybookJSONResults{

CustomStats: map[string]interface{}{},
GlobalCustomStats: map[string]interface{}{},
Plays: []AnsiblePlaybookJSONResultsPlay{
{
Play: &AnsiblePlaybookJSONResultsPlaysPlay{
Name: "Slice of slices test",
Id: "ff523e0a-84a7-e3d6-229a-000000000006",
Duration: &AnsiblePlaybookJSONResultsPlayDuration{
End: "2024-04-01T03:08:28.359220Z",
Start: "2024-04-01T03:08:25.115857Z",
},
},
Tasks: []AnsiblePlaybookJSONResultsPlayTask{
{
Hosts: map[string]*AnsiblePlaybookJSONResultsPlayTaskHostsItem{
"192.168.0.1": {
// "_ansible_no_log": false, "_ansible_verbose_always": true,
Action: "ios_command",
AnsibleFacts: map[string]interface{}{
"discovered_interpreter_python": "/usr/bin/python3",
},
Changed: false,
Stdout: []interface{}{"One line\nAnother line\nEven another line\nLast line"},
StdoutLines: []interface{}{
[]interface{}{
"One line",
"Another line",
"Even another line",
"Last line",
},
},
},
},
Task: &AnsiblePlaybookJSONResultsPlayTaskItem{
Id: "ff523e0a-84a7-e3d6-229a-000000000008",
Name: "run show version on the routers",
Duration: &AnsiblePlaybookJSONResultsPlayTaskItemDuration{
End: "2024-04-01T03:08:27.896416Z",
Start: "2024-04-01T03:08:25.148062Z",
},
},
},
},
},
},
Stats: map[string]*AnsiblePlaybookJSONResultsStats{
"192.168.0.1": {
Changed: 0,
Failures: 0,
Ignored: 0,
Ok: 2,
Rescued: 0,
Skipped: 0,
Unreachable: 0,
},
},
},
},
}

for _, test := range tests {
Expand Down

0 comments on commit 1b7af13

Please sign in to comment.