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

adhoc command StdoutCallback as json raise err. #62

Closed
wahello opened this issue Jul 5, 2021 · 3 comments
Closed

adhoc command StdoutCallback as json raise err. #62

wahello opened this issue Jul 5, 2021 · 3 comments

Comments

@wahello
Copy link

wahello commented Jul 5, 2021

I have some code as following:


func CheckAssetsConnectivityManual(ctx context.Context, adminUser, password, hosts string) {

	buff := new(bytes.Buffer)

	ansibleConnectionOptions := &options.AnsibleConnectionOptions{
		User: adminUser,
	}

	ansibleAdhocOptions := &adhoc.AnsibleAdhocOptions{
		Inventory:  hosts,
		ModuleName: "ping",
		//ModuleName: "setup",
	}

	// install sshpass
	ansibleAdhocOptions.AddExtraVar("ansible_password", password)

	executor := execute.NewDefaultExecute(
		execute.WithWrite(io.Writer(buff)),
	)

	adhoc := &adhoc.AnsibleAdhocCmd{
		Pattern:           "all",
		Options:           ansibleAdhocOptions,
		ConnectionOptions: ansibleConnectionOptions,
		Exec:              executor,
		StdoutCallback:    "json",
	}

	err := adhoc.Run(ctx)
	if err != nil {
		log.Println(err.Error())
	}
	log.Println(" ------ ===== buff: ", string(buff.Bytes()))
	res, err := results.JSONParse(buff.Bytes())
	if err != nil {
		log.Println(err.Error())
	}
	log.Println(" ---- res : ", res.String())

}


res, err := results.JSONParse(buff.Bytes())

panic.

@apenella
Copy link
Owner

apenella commented Jul 6, 2021

hi @wahello!
I updated simple-ansibleadhoc to use json stdout callback, and it finishes properly. (simple-ansibleadhoc has been updated on my local host)

❯ go run simple-ansibleadhoc.go 
ansible all  --inventory 127.0.0.1, --module-name ping  --connection local
[127.0.0.1] (ping)

Host: 127.0.0.1
 Changed: 0 Failures: 0 Ignored: 0 Ok: 1 Rescued: 0 Skipped: 0 Unreachable: 0

Can you share the panic's output?

Thanks!

@apenella
Copy link
Owner

hi @wahello!
There is any update about you issue?

Thanks!

@apenella
Copy link
Owner

@wahello since there is any update about your issue, I am going to close it.
In case you need anything else, just open a new issue!
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants