gansible

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 15, 2026 License: MIT Imports: 10 Imported by: 0

README

gansible

Source of truth: This project is hosted on GitHub. The GitLab repository at gitlab.com/m0rthis/gansible is a read-only mirror.

go get github.com/m0rthis/gansible

A lightweight Go helper package for building custom Ansible modules that communicate using JSON over stdin/stdout.

Features

  • Structured result format compatible with Ansible expectations
  • Helper functions for clean exit (ExitJson, FailJson)
  • OS family normalization and validation utilities
  • Simple integration into any Go-based Ansible module

Usage

Result Handling
response := gansible.Result{
    Changed: true,
    Msg:     "Task completed",
    Data:    someOutput,
}
gansible.ExitJson(response)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ValidOS = []OS{Windows, Linux}
View Source
var Verbosity int

Functions

func ExitJson

func ExitJson(res Result)

func FailJson

func FailJson(res Result)

func V

func V(msg string, args ...any)

func VV

func VV(msg string, args ...any)

func VVV

func VVV(msg string, args ...any)

func VVVV

func VVVV(msg string, args ...any)

func VVVVV

func VVVVV(msg string, args ...any)

Types

type LoadOptions

type LoadOptions struct {
	UseRawInput bool
}

func LoadOptionsDefault

func LoadOptionsDefault() LoadOptions

func LoadOptionsFromEnv

func LoadOptionsFromEnv() LoadOptions

type OS

type OS string
const (
	Windows OS = "windows"
	Linux   OS = "linux"
)

func GetOS

func GetOS() (OS, error)

type Result

type Result struct {
	Changed       bool           `json:"changed"`
	Failed        bool           `json:"failed"`
	Msg           string         `json:"msg,omitempty"`
	Data          any            `json:"data,omitempty"`
	ModuleName    string         `json:"module_name,omitempty"`
	ModuleVersion string         `json:"module_version,omitempty"`
	ModuleStdout  string         `json:"module_stdout,omitempty"`
	ModuleStderr  string         `json:"module_stderr,omitempty"`
	Warnings      []string       `json:"warnings,omitempty"`
	RC            int            `json:"rc,omitempty"`
	AnsibleFacts  map[string]any `json:"ansible_facts,omitempty"`
}

func InitModule

func InitModule[T any](opts LoadOptions) (T, Result)

func LoadArgs

func LoadArgs[T any](opts LoadOptions) (T, Result)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL