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

warning messages are included on json data when is used json stdout_callback #27

Closed
apenella opened this issue Feb 10, 2021 · 1 comment · Fixed by #28
Closed

warning messages are included on json data when is used json stdout_callback #27

apenella opened this issue Feb 10, 2021 · 1 comment · Fixed by #28
Labels
bug Something isn't working v0.7.1

Comments

@apenella
Copy link
Owner

Which ansible version are you using?
ansible 2.10.5
config file = ??/.ansible.cfg
configured module search path = ['??/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = ??/.local/lib/python3.8/site-packages/ansible
executable location = ??/.local/bin/ansible
python version = 3.8.5 (default, Jul 28 2020, 12:59:40) [GCC 9.3.0]

Which go version are you using?
go version go1.15.6 linux/amd64

Which go-ansbile version are you using?
0.7.0

What did you see?
When is run a playbook using the json stdout_callbak, and there is a warning message on the output (with warning messages I mean those messages that start with [WARNING]), that message is included on json data and then the parsing done by JSONParse fails.

exit status 4                                                                                  
panic: Unmarshall error                     
        invalid character '[' after top-level value

On the other hand, some warning messages returned by ansible-playbook in one line on terminal are seen as multiple line messages by go-ansible

Thats an example:

  • Shell output:
$ ANSIBLE_STDOUT_CALLBACK=json ansible-playbook  --inventory 127.0.0.1,  --user apenella site.yml
[WARNING]: Unhandled error in Python interpreter discovery for host 127.0.0.1: Failed to connect to the host via ssh: ssh: connect to host 127.0.0.1 port 22: Connection refused
...
  • go-ansible output:
-- #[WARNING]: Unhandled error in Python interpreter discovery for host 127.0.0.1:#
-- #Failed to connect to the host via ssh: ssh: connect to host 127.0.0.1 port 22:#
-- #Connection refused#

How to reproduce the issue?
To reproduce the issue I used simple-ansibleplaybook-json example.
I forced a connection error updating ansiblePlaybookConnectionOptions definition as is shown below:

	ansiblePlaybookConnectionOptions := &ansibler.AnsiblePlaybookConnectionOptions{
	//	Connection: "local",
		User:       "apenella",
	}

You could see the scanned text by go-ansible updating ansiblePlaybookJSONResults as is shown below:

	for scanner.Scan() {
		line := scanner.Text()
		if !skipLine(line) {
                        // println for debuggin purpose
                        fmt.Println("-- #" + line + "#")
			fmt.Fprintf(w, "%s", line)
		}
	}

The issue is related to #23

@apenella apenella added the bug Something isn't working label Feb 10, 2021
@apenella
Copy link
Owner Author

On DefaultExecutor is created a multireader for stdout and stderr, then the stdout and stderr output is written on same writer and that causes an invalid json outcome when there is a warning message during playbook execution.

Here there is where is defined the multireader:
https://github.com/apenella/go-ansible/blob/master/execute/defaultExecute.go#L85

I am going to separete stdout and stderr to avoid this kind of errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working v0.7.1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant