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

ExtraVars not enclosed in quotes #50

Closed
abdullah-lt opened this issue Mar 26, 2021 · 2 comments
Closed

ExtraVars not enclosed in quotes #50

abdullah-lt opened this issue Mar 26, 2021 · 2 comments

Comments

@abdullah-lt
Copy link

abdullah-lt commented Mar 26, 2021

The ansible command that is being generated when adding extra vars argument is

ansible-playbook --extra-vars {"EC2IP":"127.0.0.1","ansible_password":"123456"} --inventory 10.10.10.120, --user root change-settings.yml

This is not working as extra-vars json should be enclosed in qoutes like

ansible-playbook --extra-vars '{"EC2IP":"127.0.0.1","ansible_password":"123456"}' --inventory 10.10.10.120, --user root change-settings.yml

@apenella
Copy link
Owner

hi! @abdullah-lt
it was already solved, which version of go-ansible are you using?
I recommend to use last version, though version 0.8.0 already had extravars quoted.

I have updated the example simple-ansibleplaybook as:

func main() {

	ansiblePlaybookConnectionOptions := &options.AnsibleConnectionOptions{
		Connection: "local",
	}

	ansiblePlaybookOptions := &playbook.AnsiblePlaybookOptions{
		Inventory: "127.0.0.1,",
	}

	ansiblePlaybookOptions.AddExtraVar("EC2IP", "127.0.0.1")
	ansiblePlaybookOptions.AddExtraVar("ansible_password", "12345678")

	playbook := &playbook.AnsiblePlaybookCmd{
		Playbooks:         []string{"site.yml", "site2.yml"},
		ConnectionOptions: ansiblePlaybookConnectionOptions,
		Options:           ansiblePlaybookOptions,
	}

	fmt.Println(">>", playbook.String())

	err := playbook.Run(context.TODO())
	if err != nil {
		panic(err)
	}
}

And that is the playbook.String() result.

$ go run simple-ansibleplaybook.go 
>> ansible-playbook  --extra-vars '{"EC2IP":"127.0.0.1","ansible_password":"12345678"}' --inventory 127.0.0.1,  --connection local --user aleix site.yml site2.yml

@abdullah-lt
Copy link
Author

Hi @apenella
I am using the latest version - v1.1.0. There was a different code issue and I was printing the command in a different way which removed the quotes from the ansible command. Thanks for your response and example.

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