Skip to content

Latest commit

 

History

History
56 lines (43 loc) · 1.12 KB

Readme.md

File metadata and controls

56 lines (43 loc) · 1.12 KB

go-ansible

Go-ansible is a lightweight Golang package to run Ansible commands from Go.

Installation

Use go-get:

go get -u github.com/bbl/go-ansible

Usage

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

Contributing

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.

License

MIT