Go-ansible is a lightweight Golang package to run Ansible commands from Go.
Use go-get
:
go get -u github.com/bbl/go-ansible
package main
import (
"fmt"
"github.com/bbl/go-ansible"
)
func main() {
// Download dependencies from requirements
err := ansible.Galaxy().
Requirements("/path/to/requirements.yaml").
RolesPath("/path/to/roles_dir").
Install()
if err != nil {
panic(err)
}
// Run a playbook with extra vars
vars := map[string]string{
"test_key": "test_value",
}
pb := ansible.Playbook().
Inventory("/path/to/inventory.ini").
Path("/path/to/playbook.yaml").
ExtraVars(vars).
ExtraVars(map[string]string{"key": "value"})
err := pb.Run()
if err != nil {
panic(err)
}
}
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.