bbl / go-ansible

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

About

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


Languages

Language:Go 99.5%Language:Makefile 0.5%