Go module for execute Ansible commands. Supported comands at this moment: ansible
, ansible-playbook
.
import "github.com/dlampsi/ago"
Playbook run example:
// Create playbook entry point
p := ago.Playbook{
Name: "testdata/debug.yml",
}
// Playbook options
p.Options = &ago.PlaybookOptions{
Inventory: "testdata/inventory",
ExtraVars: map[string]interface{}{
"var1": "val1",
"var2": false,
"var3": []string{"one", "two"},
},
}
// Optionaly you can provide any ANSIBLE_ env variables
os.Setenv("ANSIBLE_FORCE_COLOR", "true")
// Execute
if err := p.Run(); err != nil {
panic(err)
}
Ansible ad-hook run example (executes pwd
command on localhost
):
a := &ago.Ansible{
HostPattern: "localhost",
Options: &AnsibleOptions{
ModuleArgs: "pwd",
},
}
if err := a.Run(); err != nil {
panic(err)
}
By default using DefaultExecutor
but you can provide your own executor via Executor
interface:
type myCustomExecutor struct {
}
func (e *myCustomExecutor) Exec(name string, args []string) error {
}
p := ago.Playbook{
Name: "testdata/debug.yml",
Exec: &myCustomExecutor{},
}