henchman

package
v0.0.0-...-13c53c6 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2017 License: BSD-2-Clause Imports: 26 Imported by: 2

Documentation

Index

Constants

View Source
const (
	HENCHMAN_PREFIX = "henchman_"
	MODULES_TARGET  = "modules.tar"
	IGNORED_EXTS    = "zip,tar,tar.gz"
	REMOTE_DIR      = "${HOME}/.henchman/"
)
View Source
const (
	ECHO          = 53
	TTY_OP_ISPEED = 128
	TTY_OP_OSPEED = 129
)
View Source
const DEFAULT_CONFIGURATION = `` /* 205-byte string literal not displayed */

Variables

View Source
var (
	DebugFlag bool
	OsNames   = []string{"darwin", "linux"}
)
View Source
var ModuleSearchPath = []string{
	"modules",
}

Functions

func ClientKeyAuth

func ClientKeyAuth(keyFile string) (ssh.AuthMethod, error)

func CreateDir

func CreateDir(dir string) error

Removes old dir and creates new one

func Debug

func Debug(fields map[string]interface{}, msg string)

wrapper for debug

func ErrKeyword

func ErrKeyword(val interface{}) error

func ErrNotValidVariable

func ErrNotValidVariable(val interface{}) error

func ErrWrongType

func ErrWrongType(field interface{}, val interface{}, _type string) error

func Error

func Error(fields map[string]interface{}, msg string)

wrapper for Error

func Fatal

func Fatal(fields map[string]interface{}, msg string)

wrapper for Fatal

func GetInventoryGroups

func GetInventoryGroups(planBuf []byte) ([]string, error)

*

  • gets the groups under hosts section from plan file

func HenchErr

func HenchErr(err error, fields map[string]interface{}, extMsg string) error

func Info

func Info(fields map[string]interface{}, msg string)

wrapper for Info

func InitConfiguration

func InitConfiguration(filename string) error

FIXME: If a custom configuration is given, it should be merged with DEFAULT configuration

func InitLog

func InitLog() error

func MergeMap

func MergeMap(src map[string]interface{}, dst map[string]interface{}, override bool)

MergeMap(...) merges two map[string]interface{}. Source values will override dest values if override is true

func PasswordAuth

func PasswordAuth(pass string) (ssh.AuthMethod, error)

func Printf

func Printf(msg string, a ...interface{})

wrapper for Printf and Println with a lock

func PrintfAndFill

func PrintfAndFill(size int, fill string, msg string, a ...interface{})

Does a printf and fills the extra white space Just specify the max size to fill to and the string to fill with

func Println

func Println(msg string)

func SprintfAndFill

func SprintfAndFill(size int, fill string, msg string, a ...interface{}) string

Does a Sprintf and fills the extra white space

func Warn

func Warn(fields map[string]interface{}, msg string)

Types

type Configuration

type Configuration struct {
	Log       string
	ExecOrder map[string][]string
}
var Config Configuration

Global config object for henchman to use

type HenchmanError

type HenchmanError struct {
	Err    error
	Fields map[string]interface{}
	// contains filtered or unexported fields
}

func (*HenchmanError) Error

func (henchError *HenchmanError) Error() string

type HostGroup

type HostGroup struct {
	Hosts []string `yaml:"hosts"`
	Vars  VarsMap  `yaml:"vars"`
}

type Inventory

type Inventory struct {
	//GroupHosts map[string][]*Machine
	Groups     map[string]HostGroup `yaml:"groups"`
	HostVars   map[string]VarsMap   `yaml:"host_vars"`
	GlobalVars VarsMap              `yaml:"global_vars"`
}

type Inventory map[string][]*Machine

func (Inventory) Count

func (inv Inventory) Count() int

func (*Inventory) GetInventoryForGroups

func (inv *Inventory) GetInventoryForGroups(groups []string) Inventory

*

  • Returns a filtered inventory depending on which groups are specified
  • Keeps the groups specified in the filtered inventory

func (*Inventory) GetMachines

func (inv *Inventory) GetMachines(tc TransportConfig) ([]*Machine, error)

func (*Inventory) SetGlobalVarsFromInventoryGroups

func (inv *Inventory) SetGlobalVarsFromInventoryGroups(groups map[string]HostGroup)

*

  • Sets all_hosts, and groups with attached hosts lists
  • These can be accessed in vars.inv.whatevs

type InventoryConfig

type InventoryConfig map[string]string

type InventoryInterface

type InventoryInterface interface {
	Load(ic InventoryConfig) (Inventory, error)
}

type LocalTransport

type LocalTransport struct{}

Transport for the current machine on which henchman is being run on

func NewLocal

func NewLocal(config *TransportConfig) (*LocalTransport, error)

func (*LocalTransport) Exec

func (local *LocalTransport) Exec(cmdStr string, stdin []byte, sudoEnabled bool) (*bytes.Buffer, error)

func (*LocalTransport) Initialize

func (local *LocalTransport) Initialize(config *TransportConfig) error

func (*LocalTransport) Put

func (local *LocalTransport) Put(source, destination string, _ string) error

type Machine

type Machine struct {
	Hostname  string
	Vars      VarsMap
	Transport TransportInterface
}

type Module

type Module struct {
	Name   string
	Params map[string]string
}

FIXME: Have custom error types when parsing modules

func NewModule

func NewModule(args ...interface{}) (Module, error)

func (Module) ExecOrder

func (module Module) ExecOrder() ([]string, error)

ExecOrder() returns the execution order of specific modules

func (Module) Resolve

func (module Module) Resolve(osName string) (string, bool, error)

Resolve(...) checks to see if a module is valid and if it's a standalone module

type Plan

type Plan struct {
	Name      string
	Inventory Inventory
	Vars      VarsMap
	Tasks     []*Task
}

func PreprocessPlan

func PreprocessPlan(buf []byte, inv *Inventory) (*Plan, error)

Calls the other Preprocessing Compenents

func (*Plan) Cleanup

func (plan *Plan) Cleanup(machines []*Machine) error

For now it just removes the .henchman folder in each system

func (*Plan) Execute

func (plan *Plan) Execute(machines []*Machine) error

Does execution of tasks

func (*Plan) Setup

func (plan *Plan) Setup(machines []*Machine) error

*

  • These functions are functions that can be utilized by plans

Moves all modules to each host. If machines only has localhost, ignore this activity since we anyway do that later

type PlanProxy

type PlanProxy struct {
	Name            string       `yaml:"name"`
	Sudo            bool         `yaml:"sudo"`
	Debug           bool         `yaml:"debug"`
	TaskProxies     []*TaskProxy `yaml:"tasks"`
	VarsProxy       *VarsProxy   `yaml:"vars"`
	InventoryGroups []string     `yaml:"hosts"`
}

func (PlanProxy) PreprocessTasks

func (px PlanProxy) PreprocessTasks() ([]*Task, error)

Checks the a slice of TaskProxy ptrs passed in by a Plan and determines whether if it's an include value or a normal task. If it's a normal task it appends it as a standard task, otherwise it recursively expands the include statement NOTE: making this a function of PlanProxy in case we want to have more plan level variables

in the future.  Removes the need to pass each variable as a parameter.

func (PlanProxy) PreprocessVars

func (px PlanProxy) PreprocessVars() (VarsMap, error)

Processes plan level vars with includes All plan level vars will be in the vars map And any repeat vars in the includes will be a FCFS priority NOTE: if the user has multiple include blocks it'll grab the one closest to

the bottom

type RegMap

type RegMap map[string]interface{}

type SSHTransport

type SSHTransport struct {
	Host   string
	Port   uint16
	Config *ssh.ClientConfig
}

func NewSSH

func NewSSH(config *TransportConfig) (*SSHTransport, error)

func (*SSHTransport) Exec

func (sshTransport *SSHTransport) Exec(cmd string, stdin []byte, sudoEnabled bool) (*bytes.Buffer, error)

func (*SSHTransport) Initialize

func (sshTransport *SSHTransport) Initialize(config *TransportConfig) error

func (*SSHTransport) Put

func (sshTransport *SSHTransport) Put(source, destination string, srcType string) error

source is the source of the file/folder destination is the path of the FOLDER where source will be transferred to NOTE: source will keep it original name when transferred

type Task

type Task struct {
	Id           string
	Debug        bool
	IgnoreErrors bool `yaml:"ignore_errors"`
	Local        bool
	Module       Module
	Name         string
	Register     string
	Retry        int
	Sudo         bool
	Vars         VarsMap
	When         string
	WithItems    interface{} `yaml:"with_items"`
}

func (*Task) ProcessWhen

func (task *Task) ProcessWhen() (bool, error)

checks and converts when to bool

func (*Task) ProcessWithItems

func (task *Task) ProcessWithItems(varsMap VarsMap, regMap RegMap) ([]*Task, error)

ProcessWithItems checks for the with_items files in a task. If it's present it will generate a list of rendered tasks.

func (Task) Render

func (task Task) Render(vars VarsMap, registerMap RegMap) (*Task, error)

wrapper for Rendering each task This will return the rendered task and not manipulate the pointer to the task. b/c the pointer to the task is a template and a race condition can occur.

func (Task) RenderVars

func (task Task) RenderVars(varsMap VarsMap, registerMap map[string]interface{}) error

renders the task level variables with global vars

func (*Task) Run

func (task *Task) Run(machine *Machine, vars VarsMap, registerMap RegMap) (*TaskResult, error)

type TaskProxy

type TaskProxy struct {
	Task        `yaml:",inline"`
	SudoState   string
	DebugState  string
	Include     string
	IncludeVars VarsMap `yaml:"vars"`
}

Task is for the general Task format. Refer to task.go Vars are kept in scope for each Task. So there is a Vars field for each task Include is the file name for the included Tasks list

func (*TaskProxy) UnmarshalYAML

func (tp *TaskProxy) UnmarshalYAML(unmarshal func(interface{}) error) error

Custom unmarshaller which accounts for module names

type TaskResult

type TaskResult struct {
	State  string      `json:"status"`
	Output interface{} `json:"output,omitempty"`
	Msg    string      `json:"msg"`
}

type TransportConfig

type TransportConfig map[string]string

type TransportInterface

type TransportInterface interface {
	Initialize(config *TransportConfig) error
	Exec(cmd string, stdin []byte, sudo bool) (*bytes.Buffer, error)
	Put(source string, destination string, dstType string) error
}

type VarsMap

type VarsMap map[string]interface{}

NOTE: eventually change this to map[string]interface{}

func GetHenchmanVars

func GetHenchmanVars(vars VarsMap) VarsMap

*

  • Gets any vars with the prefix henchman

type VarsProxy

type VarsProxy struct {
	Vars VarsMap
}

func (*VarsProxy) UnmarshalYAML

func (vp *VarsProxy) UnmarshalYAML(unmarshal func(interface{}) error) error

Custom unmarshaller which account for multiple include statements and include types NOTE: Cannot account for double includes because unmarshal(&vMap) already does

under the hood unmarshaling and does what any map would do, which is override
repeating key values

type YAMLInventory

type YAMLInventory struct {
	Groups     map[string]HostGroup `yaml:"groups"`
	HostVars   map[string]VarsMap   `yaml:"host_vars"`
	GlobalVars VarsMap              `yaml:"global_vars"`
}

FIXME: Have a way to provide specifics

func (*YAMLInventory) Load

func (yi *YAMLInventory) Load(ic InventoryConfig) (Inventory, error)

Jump to

Keyboard shortcuts

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