Skip to content
/ ago Public

Go module for executing Ansible commands

License

Notifications You must be signed in to change notification settings

dlampsi/ago

Repository files navigation

ago

GoDoc Actions Status

Go module for execute Ansible commands. Supported comands at this moment: ansible, ansible-playbook.

Usage

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)
}

Custom execuror

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{},
}