goansible

package module
v0.0.0-...-01eac64 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2016 License: BSD-3-Clause Imports: 30 Imported by: 0

README

goansible

https://github.com/vektra/goansible/commit/bd64e957bab0117e59cd663b954ecf90de2ba3dc からforkしました

変更点

  • template機能の追加
  • OK,Changed などの表示をansibleと同じように
  • debug,output表示をオプションで指定可能に

Tachyon is an experimental configuration management tool inspired by ansible implemented in golang.

Ok.. why?

I find the best way to learn something is to try to implement it. I'm curious about ansible's model for configuration management and as a fun weekend project began I this project.

Is this usable?

If you need to run some yaml that executes commands via shell/command, sure! Otherwise no. I'll probably continue to play with it, adding more functionality and fleshing out some ideas I've got.

Oohh what ideas?
  • Exploit golang's single binary module to bootstrap machines and run plays remotely.
  • Use golang's concurrency to make management of large scale changes easy.
  • Use github.com/evanphx/ssh to do integrated ssh
  • Allow creation of modules via templated tasks
Is that a lisp directory I see?

It is! ansible uses python as it's implementation lang and thus also uses it as it's runtime eval language. Obviously I can't do that and I don't wish to runtime eval any golang code. Thus I have opted to embed a simple lisp intepreter (taken and modified from https://github.com/janne/go-lisp) to run code. For instance:

name: Tell everyone things are great
action: shell echo wooooo!
when: $(== everything "awesome")
What should I do with this?

Whatever you want. Play around, tell me what you think about it. Send PRs for crazy ass features!

Documentation

Index

Constants

View Source
const MaxTaskResult = 500

Variables

View Source
var Arg0 string
View Source
var DefaultConfig = &Config{false, false, ""}
View Source
var Release string = "dev"
View Source
var Version string

Functions

func ChangePerm

func ChangePerm(owner string, suid, sgid int) (uid, gid int, err error)

func DisplayScope

func DisplayScope(s Scope)

func ExpandTemplates

func ExpandTemplates(s Scope, args string) (string, error)

func ExpandTemplatesIn

func ExpandTemplatesIn(s Scope, in []byte) ([]byte, error)

func ExpandVars

func ExpandVars(s Scope, args string) (string, error)

func ExpandVarsOnly

func ExpandVarsOnly(s Scope, args string) (string, error)

func HomeDir

func HomeDir() (string, error)

func ImportVarsFile

func ImportVarsFile(s Scope, path string) error

func Main

func Main(args []string) int

func MakeCommand

func MakeCommand(s Scope, task *Task, args string) (Command, Vars, error)

func RegisterCommand

func RegisterCommand(name string, cmd Command)

func SV

func SV(v interface{}, ok bool) interface{}

func StartPlaybook

func StartPlaybook(env *Environment, file string) error

Types

type AnyMap

type AnyMap struct {
	// contains filtered or unexported fields
}

func (AnyMap) Get

func (a AnyMap) Get(key string) (Value, bool)

func (AnyMap) MarshalJSON

func (a AnyMap) MarshalJSON() ([]byte, error)

func (AnyMap) Read

func (a AnyMap) Read() interface{}

type AnyValue

type AnyValue struct {
	// contains filtered or unexported fields
}

func (AnyValue) GetYAML

func (a AnyValue) GetYAML() (string, interface{})

func (AnyValue) MarshalJSON

func (a AnyValue) MarshalJSON() ([]byte, error)

func (AnyValue) Read

func (a AnyValue) Read() interface{}

func (AnyValue) SetYAML

func (a AnyValue) SetYAML(tag string, v interface{}) bool

type ArgParser

type ArgParser interface {
	ParseArgs(s Scope, args string) (Vars, error)
}

type CLIReporter

type CLIReporter struct {
	Output bool
	Debug  bool
	Start  time.Time
	// contains filtered or unexported fields
}

func (*CLIReporter) EndReporter

func (c *CLIReporter) EndReporter(r *Runner, err error)

func (*CLIReporter) FinishAll

func (c *CLIReporter) FinishAll(r *Runner)

func (*CLIReporter) FinishHandlers

func (c *CLIReporter) FinishHandlers(r *Runner)

func (*CLIReporter) FinishTask

func (c *CLIReporter) FinishTask(task *Task, res *Result)

func (*CLIReporter) FinishTasks

func (c *CLIReporter) FinishTasks(r *Runner)

func (*CLIReporter) StartHandlers

func (c *CLIReporter) StartHandlers(r *Runner)

func (*CLIReporter) StartTask

func (c *CLIReporter) StartTask(task *Task, name, args string, vars Vars)

func (*CLIReporter) StartTasks

func (c *CLIReporter) StartTasks(r *Runner)

type Command

type Command interface {
	Run(env *CommandEnv) (*Result, error)
}

type CommandCmd

type CommandCmd struct {
	Command       string `goansible:"command,required"`
	Creates       string `goansible:"creates"`
	IgnoreFail    bool   `goansible:"ignore_failure"`
	IgnoreChanged bool   `goansible:"ignore_changed"`
	ManualStatus  bool   `goansible:"manual_status"`
	OkRc          int    `goansible:"ok_rc"`
	ChangedRc     int    `goansible:"changed_rc"`
	ChangedCreate string `goansible:"changed_create"`
}

func (*CommandCmd) ParseArgs

func (cmd *CommandCmd) ParseArgs(s Scope, args string) (Vars, error)

func (*CommandCmd) Run

func (cmd *CommandCmd) Run(env *CommandEnv) (*Result, error)

type CommandEnv

type CommandEnv struct {
	Env   *Environment
	Paths Paths
}

func NewCommandEnv

func NewCommandEnv(env *Environment, task *Task) *CommandEnv

type CommandResult

type CommandResult struct {
	ReturnCode int
	Stdout     []byte
	Stderr     []byte
}

func RunCommand

func RunCommand(env *CommandEnv, parts ...string) (*CommandResult, error)

func RunCommandInEnv

func RunCommandInEnv(env *CommandEnv, unixEnv []string, parts ...string) (*CommandResult, error)

type Commands

type Commands map[string]reflect.Type
var AvailableCommands Commands

type Config

type Config struct {
	ShowCommandOutput bool
	Debug             bool
	Passphrase        string
}

type CopyCmd

type CopyCmd struct {
	Src   string `goansible:"src,required"`
	Dest  string `goansible:"dest,required"`
	Owner string `goansible:"owner"`
	Mkdir bool   `goansible:"mkdir"`
	Uid   int    `goansible:"uid"`
	Gid   int    `goansible:"gid"`
	Mode  int    `goansible:"mode"`
}

func (*CopyCmd) Run

func (cmd *CopyCmd) Run(env *CommandEnv) (*Result, error)

type DownloadCmd

type DownloadCmd struct {
	Url       string `goansible:"url,required"`
	Dest      string `goansible:"dest"`
	Sha256sum string `goansible:"sha256sum"`
	Once      bool   `goansible:"once"`
}

func (*DownloadCmd) Run

func (d *DownloadCmd) Run(env *CommandEnv) (*Result, error)

type Environment

type Environment struct {
	Vars Scope

	Paths Paths
	// contains filtered or unexported fields
}

func NewEnv

func NewEnv(s Scope, cfg *Config) *Environment

func (*Environment) Cleanup

func (e *Environment) Cleanup()

func (*Environment) ReportJSON

func (e *Environment) ReportJSON()

func (*Environment) ReportStruct

func (e *Environment) ReportStruct() error

func (*Environment) SetPaths

func (e *Environment) SetPaths(n Paths) Paths

func (*Environment) TempFile

func (e *Environment) TempFile(prefix string) (*os.File, error)

type Future

type Future struct {
	Task    *Task
	Start   time.Time
	Runtime time.Duration
	// contains filtered or unexported fields
}

func NewFuture

func NewFuture(start time.Time, task *Task, f func() (*Result, error)) *Future

func (*Future) Read

func (f *Future) Read() interface{}

func (*Future) Value

func (f *Future) Value() (*Result, error)

func (*Future) Wait

func (f *Future) Wait()

type FutureScope

type FutureScope struct {
	Scope
	// contains filtered or unexported fields
}

func NewFutureScope

func NewFutureScope(parent Scope) *FutureScope

func (*FutureScope) AddFuture

func (fs *FutureScope) AddFuture(key string, f *Future)

func (*FutureScope) Get

func (fs *FutureScope) Get(key string) (Value, bool)

func (*FutureScope) Results

func (fs *FutureScope) Results() []RunResult

func (*FutureScope) Wait

func (fs *FutureScope) Wait()

type Futures

type Futures map[string]*Future

type JsonChunkReporter

type JsonChunkReporter struct {
	Start time.Time
	// contains filtered or unexported fields
}

func (*JsonChunkReporter) EndReporter

func (c *JsonChunkReporter) EndReporter(r *Runner, err error)

func (*JsonChunkReporter) FinishAll

func (c *JsonChunkReporter) FinishAll(r *Runner)

func (*JsonChunkReporter) FinishHandlers

func (c *JsonChunkReporter) FinishHandlers(r *Runner)

func (*JsonChunkReporter) FinishTask

func (c *JsonChunkReporter) FinishTask(task *Task, res *Result)

func (*JsonChunkReporter) FinishTasks

func (c *JsonChunkReporter) FinishTasks(r *Runner)

func (*JsonChunkReporter) StartHandlers

func (c *JsonChunkReporter) StartHandlers(r *Runner)

func (*JsonChunkReporter) StartTask

func (c *JsonChunkReporter) StartTask(task *Task, name, args string, vars Vars)

func (*JsonChunkReporter) StartTasks

func (c *JsonChunkReporter) StartTasks(r *Runner)

type Map

type Map interface {
	Get(key string) (Value, bool)
}

type MkFileCmd

type MkFileCmd struct {
	Src   string `goansible:"src,required"`
	Dest  string `goansible:"dest,required"`
	Owner string `goansible:"owner"`
	Uid   int    `goansible:"uid"`
	Gid   int    `goansible:"gid"`
	Mode  int    `goansible:"mode"`
}

func (*MkFileCmd) Run

func (cmd *MkFileCmd) Run(env *CommandEnv) (*Result, error)

type Module

type Module struct {
	Name      string
	TaskDatas []TaskData             `yaml:"tasks"`
	RawVars   map[string]interface{} `yaml:"vars"`

	ModVars  Vars
	ModTasks []*Task
}

type ModuleRun

type ModuleRun struct {
	Play        *Play
	Task        *Task
	Module      *Module
	Runner      *Runner
	Scope       Scope
	FutureScope *FutureScope
	Vars        Vars
}

func (*ModuleRun) Run

func (m *ModuleRun) Run(env *CommandEnv) (*Result, error)

type NestedScope

type NestedScope struct {
	Scope Scope
	Vars  Vars
}

func NewNestedScope

func NewNestedScope(parent Scope) *NestedScope

func SpliceOverrides

func SpliceOverrides(cur Scope, override *NestedScope) *NestedScope

func (*NestedScope) Empty

func (n *NestedScope) Empty() bool

func (*NestedScope) Flatten

func (n *NestedScope) Flatten() Scope

func (*NestedScope) Get

func (n *NestedScope) Get(key string) (v Value, ok bool)

func (*NestedScope) Set

func (n *NestedScope) Set(key string, v interface{})

type Notifications

type Notifications []string

type Options

type Options struct {
	Vars        map[string]string `short:"s" long:"set" description:"Set a variable"`
	ShowOutput  bool              `short:"o" long:"output" description:"Show command output"`
	ShowVersion bool              `short:"v" long:"version" description:"Show version"`
	Passphrase  string            `short:"p" long:"Passphrase" description:"passphrase of decode"`
	Development bool              `long:"dev" description:"Use a dev version of goansible"`
	Debug       bool              `short:"d" long:"debug" description:"Show all information about commands"`
	JSON        bool              `long:"json" description:"Output the run details in chunked json"`
}

type Paths

type Paths interface {
	Base() string
	Role(name string) string
	Vars(name string) string
	Task(name string) string
	Handler(name string) string
	File(name string) string
	TemplateFile(name string) string
	Meta(name string) string
}

type Play

type Play struct {
	Hosts      string
	Connection string
	Vars       Scope
	VarsFiles  VarsFiles
	Tasks      Tasks
	Handlers   Tasks
	Roles      []string
	Modules    map[string]*Module
	// contains filtered or unexported fields
}

type Playbook

type Playbook struct {
	Path string

	Plays []*Play
	Env   *Environment
	Vars  *NestedScope
	// contains filtered or unexported fields
}

func NewPlaybook

func NewPlaybook(env *Environment, p string) (*Playbook, error)

func NewPlaybookBytes

func NewPlaybookBytes(env *Environment, playBytes []byte) (*Playbook, error)

func (*Playbook) LoadPlayDatas

func (pb *Playbook) LoadPlayDatas(seq []playData, s Scope) ([]*Play, error)

func (*Playbook) LoadPlays

func (pb *Playbook) LoadPlays(fpath string, s Scope) ([]*Play, error)

type PriorityScope

type PriorityScope struct {
	// contains filtered or unexported fields
}

func (*PriorityScope) Get

func (p *PriorityScope) Get(key string) (Value, bool)

func (*PriorityScope) Set

func (p *PriorityScope) Set(key string, val interface{})

type Reporter

type Reporter interface {
	StartTasks(r *Runner)
	FinishTasks(r *Runner)
	StartHandlers(r *Runner)
	FinishHandlers(r *Runner)
	FinishAll(r *Runner)
	EndReporter(r *Runner, err error)

	StartTask(task *Task, name, args string, vars Vars)
	FinishTask(task *Task, res *Result)
}

type Result

type Result struct {
	Changed bool
	Failed  bool
	Data    ResultData
}

func FailureResult

func FailureResult(err error) *Result

func NewResult

func NewResult(changed bool) *Result

func RunAdhocCommand

func RunAdhocCommand(cmd Command, debug, output bool, args string) (*Result, error)

func RunAdhocTask

func RunAdhocTask(cmd, args string) (*Result, error)

func RunAdhocTaskVars

func RunAdhocTaskVars(td TaskData) (*Result, error)

func WrapResult

func WrapResult(changed bool, data ResultData) *Result

func (*Result) Add

func (r *Result) Add(key string, v interface{})

func (*Result) Get

func (r *Result) Get(key string) (Value, bool)

func (*Result) MarshalJSON

func (r *Result) MarshalJSON() ([]byte, error)

type ResultData

type ResultData map[string]Value

func (ResultData) Get

func (rd ResultData) Get(key string) interface{}

func (ResultData) Set

func (rd ResultData) Set(key string, v interface{})

type RunResult

type RunResult struct {
	Task    *Task
	Result  *Result
	Runtime time.Duration
}

type Runner

type Runner struct {
	Results []RunResult
	Start   time.Time
	Runtime time.Duration
	// contains filtered or unexported fields
}

func NewRunner

func NewRunner(env *Environment, plays []*Play) *Runner

func RunCapture

func RunCapture(path string) (*Runner, string, error)

func (*Runner) AddNotify

func (r *Runner) AddNotify(n string)

func (*Runner) Run

func (r *Runner) Run(env *Environment) error

func (*Runner) SetReport

func (r *Runner) SetReport(rep Reporter)

func (*Runner) ShouldRunHandler

func (r *Runner) ShouldRunHandler(name string) bool

type SSH

type SSH struct {
	Host   string
	Config string
	Debug  bool
	// contains filtered or unexported fields
}

func NewSSH

func NewSSH(host string) *SSH

func (*SSH) Cleanup

func (s *SSH) Cleanup()

func (*SSH) Command

func (s *SSH) Command(args ...string) *exec.Cmd

func (*SSH) CommandWithOptions

func (s *SSH) CommandWithOptions(cmd string, args ...string) []string

func (*SSH) CopyToHost

func (s *SSH) CopyToHost(src, dest string) error

func (*SSH) ImportVagrant

func (s *SSH) ImportVagrant(target string) bool

func (*SSH) RsyncCommand

func (s *SSH) RsyncCommand() string

func (*SSH) Run

func (s *SSH) Run(args ...string) error

func (*SSH) RunAndCapture

func (s *SSH) RunAndCapture(args ...string) ([]byte, error)

func (*SSH) RunAndShow

func (s *SSH) RunAndShow(args ...string) error

func (*SSH) SSHCommand

func (s *SSH) SSHCommand(cmd string, args ...string) []string

func (*SSH) Start

func (s *SSH) Start() error

type Scope

type Scope interface {
	Get(key string) (Value, bool)
	Set(key string, val interface{})
}

type ScopeGetter

type ScopeGetter interface {
	Get(key string) (Value, bool)
}

type ScriptCmd

type ScriptCmd struct {
	Script        string `goansible:"command,required"`
	Creates       string `goansible:"creates"`
	IgnoreFail    bool   `goansible:"ignore_failure"`
	IgnoreChanged bool   `goansible:"ignore_changed"`
	ManualStatus  bool   `goansible:"manual_status"`
	OkRc          int    `goansible:"ok_rc"`
	ChangedRc     int    `goansible:"changed_rc"`
	ChangedCreate string `goansible:"changed_create"`
}

func (*ScriptCmd) ParseArgs

func (cmd *ScriptCmd) ParseArgs(s Scope, args string) (Vars, error)

func (*ScriptCmd) Run

func (cmd *ScriptCmd) Run(env *CommandEnv) (*Result, error)

type SeparatePaths

type SeparatePaths struct {
	Top  string
	Root string
}

func (SeparatePaths) Base

func (s SeparatePaths) Base() string

func (SeparatePaths) File

func (s SeparatePaths) File(name string) string

func (SeparatePaths) Handler

func (s SeparatePaths) Handler(name string) string

func (SeparatePaths) Meta

func (s SeparatePaths) Meta(name string) string

func (SeparatePaths) Role

func (s SeparatePaths) Role(name string) string

func (SeparatePaths) Task

func (s SeparatePaths) Task(name string) string

func (SeparatePaths) TemplateFile

func (s SeparatePaths) TemplateFile(name string) string

func (SeparatePaths) Vars

func (s SeparatePaths) Vars(name string) string

type ShellCmd

type ShellCmd struct {
	Command       string `goansible:"command,required"`
	Creates       string `goansible:"creates"`
	IgnoreFail    bool   `goansible:"ignore_failure"`
	IgnoreChanged bool   `goansible:"ignore_changed"`
	ManualStatus  bool   `goansible:"manual_status"`
	OkRc          int    `goansible:"ok_rc"`
	ChangedRc     int    `goansible:"changed_rc"`
	ChangedCreate string `goansible:"changed_create"`
}

func (*ShellCmd) ParseArgs

func (cmd *ShellCmd) ParseArgs(s Scope, args string) (Vars, error)

func (*ShellCmd) Run

func (cmd *ShellCmd) Run(env *CommandEnv) (*Result, error)

type SimplePath

type SimplePath struct {
	Root string
}

func (SimplePath) Base

func (s SimplePath) Base() string

func (SimplePath) File

func (s SimplePath) File(name string) string

func (SimplePath) Handler

func (s SimplePath) Handler(name string) string

func (SimplePath) Meta

func (s SimplePath) Meta(name string) string

func (SimplePath) Role

func (s SimplePath) Role(name string) string

func (SimplePath) Task

func (s SimplePath) Task(name string) string

func (SimplePath) TemplateFile

func (s SimplePath) TemplateFile(name string) string

func (SimplePath) Vars

func (s SimplePath) Vars(name string) string

type StrMap

type StrMap struct {
	// contains filtered or unexported fields
}

func (StrMap) Get

func (a StrMap) Get(key string) (Value, bool)

func (StrMap) MarshalJSON

func (a StrMap) MarshalJSON() ([]byte, error)

func (StrMap) Read

func (a StrMap) Read() interface{}

type StructReporter

type StructReporter struct {
	Hostname       string
	ServerType     string
	Project        string
	Start          time.Time
	TasksFinishDur time.Duration
	FinishDur      time.Duration
	TaskCount      int
	Out            []TaskResult
}

func (*StructReporter) EndReporter

func (c *StructReporter) EndReporter(r *Runner, err error)

func (*StructReporter) FinishAll

func (c *StructReporter) FinishAll(r *Runner)

func (*StructReporter) FinishHandlers

func (c *StructReporter) FinishHandlers(r *Runner)

func (*StructReporter) FinishTask

func (c *StructReporter) FinishTask(task *Task, res *Result)

func (*StructReporter) FinishTasks

func (c *StructReporter) FinishTasks(r *Runner)

func (*StructReporter) StartHandlers

func (c *StructReporter) StartHandlers(r *Runner)

func (*StructReporter) StartTask

func (c *StructReporter) StartTask(task *Task, name, args string, vars Vars)

func (*StructReporter) StartTasks

func (c *StructReporter) StartTasks(r *Runner)

type Svinfo

type Svinfo struct {
	Project    string `yaml:"project"`
	ServerType string `yaml:"servertype"`
}

type Task

type Task struct {
	Play *Play

	Vars Vars

	IncludeVars Vars
	Paths       Paths
	// contains filtered or unexported fields
}

func AdhocTask

func AdhocTask(cmd, args string) *Task

func (*Task) Args

func (t *Task) Args() string

func (*Task) Async

func (t *Task) Async() bool

func (*Task) Command

func (t *Task) Command() string

func (*Task) Future

func (t *Task) Future() string

func (*Task) Init

func (t *Task) Init(env *Environment) error

func (*Task) Items

func (t *Task) Items() []interface{}

func (*Task) Name

func (t *Task) Name() string

func (*Task) Notify

func (t *Task) Notify() []string

func (*Task) Register

func (t *Task) Register() string

func (*Task) When

func (t *Task) When() string

type TaskData

type TaskData map[string]interface{}

type TaskResult

type TaskResult struct {
	Name   string
	Cmd    string
	Args   string
	Vars   Vars
	Dur    time.Duration
	Result Result
}

type Tasks

type Tasks []*Task

type TemplateCmd

type TemplateCmd struct {
	Src   string `goansible:"src,required"`
	Dest  string `goansible:"dest,required"`
	Owner string `goansible:"owner"`
	Uid   int    `goansible:"uid"`
	Gid   int    `goansible:"gid"`
	Mode  int    `goansible:"mode"`
}

func (*TemplateCmd) Run

func (cmd *TemplateCmd) Run(env *CommandEnv) (*Result, error)

type Value

type Value interface {
	Read() interface{}
}

func Any

func Any(v interface{}) Value

type Vars

type Vars map[string]Value

func ParseSimpleMap

func ParseSimpleMap(s Scope, args string) (Vars, error)

func VarsFromStrMap

func VarsFromStrMap(sm map[string]string) Vars

func (Vars) Copy

func (v Vars) Copy() Vars

type VarsFiles

type VarsFiles []interface{}

Directories

Path Synopsis
net
s3
apt

Jump to

Keyboard shortcuts

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