apenella / go-ansible

Go-ansible is a Go package that enables the execution of ansible-playbook or ansible commands directly from Golang applications. It supports a wide range of options for each command, enabling smooth integration of Ansible functionality into your projects.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

If it is possible to add a list variable as extra-vars

xiangpingjiang opened this issue · comments

commented
ansible-playbook arcade.yml --extra-vars '{"pacman":"mrs","ghosts":["inky","pinky","clyde","sue"]}'

in the example of go-ansible:

ansiblePlaybookOptions.AddExtraVar("app_name", app_name)

The value of the extra-vars must be string?
If it is possible to add a list variable as extra-vars?
Thank you very much

hi @xiangpingjiang
As you could see on the link below AddExtraVar method accepts an interface{} as value, then it can be an slice, int, bool,.. or even another map.
https://github.com/apenella/go-ansible/blob/master/pkg/playbook/ansiblePlaybook.go#L414

Following your ansble-playbook command, you need to define the ghosts values on a slice and then pass it as value.

ghosts_values := []string{"inky","pinky","clyde","sue"}
playbook.AddExtraVar("ghosts", ghosts_values)

Do you have anyother question?

Thanks!

commented

Hi @apenella
thanks for your reply
i have resolved this problem.