execute

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2024 License: MIT Imports: 13 Imported by: 39

Documentation

Index

Constants

View Source
const (
	// AnsiblePlaybookErrorCodeGeneralError is the error code for a general error
	AnsiblePlaybookErrorCodeGeneralError = 1
	// AnsiblePlaybookErrorCodeOneOrMoreHostFailed is the error code for a one or more host failed
	AnsiblePlaybookErrorCodeOneOrMoreHostFailed = 2
	// AnsiblePlaybookErrorCodeOneOrMoreHostUnreachable is the error code for a one or more host unreachable
	AnsiblePlaybookErrorCodeOneOrMoreHostUnreachable = 3
	// AnsiblePlaybookErrorCodeParserError is the error code for a parser error
	AnsiblePlaybookErrorCodeParserError = 4
	// AnsiblePlaybookErrorCodeBadOrIncompleteOptions is the error code for a bad or incomplete options
	AnsiblePlaybookErrorCodeBadOrIncompleteOptions = 5
	// AnsiblePlaybookErrorCodeUserInterruptedExecution is the error code for a user interrupted execution
	AnsiblePlaybookErrorCodeUserInterruptedExecution = 99
	// AnsiblePlaybookErrorCodeUnexpectedError is the error code for a unexpected error
	AnsiblePlaybookErrorCodeUnexpectedError = 250

	// AnsiblePlaybookErrorMessageGeneralError is the error message for a general error
	AnsiblePlaybookErrorMessageGeneralError = "ansible-playbook error: general error"
	// AnsiblePlaybookErrorMessageOneOrMoreHostFailed is the error message for a one or more host failed
	AnsiblePlaybookErrorMessageOneOrMoreHostFailed = "ansible-playbook error: one or more host failed"
	// AnsiblePlaybookErrorMessageOneOrMoreHostUnreachable is the error message for a one or more host unreachable
	AnsiblePlaybookErrorMessageOneOrMoreHostUnreachable = "ansible-playbook error: one or more host unreachable"
	// AnsiblePlaybookErrorMessageParserError is the error message for a parser error
	AnsiblePlaybookErrorMessageParserError = "ansible-playbook error: parser error"
	// AnsiblePlaybookErrorMessageBadOrIncompleteOptions is the error message for a bad or incomplete options
	AnsiblePlaybookErrorMessageBadOrIncompleteOptions = "ansible-playbook error: bad or incomplete options"
	// AnsiblePlaybookErrorMessageUserInterruptedExecution is the error message for a user interrupted execution
	AnsiblePlaybookErrorMessageUserInterruptedExecution = "ansible-playbook error: user interrupted execution"
	// AnsiblePlaybookErrorMessageUnexpectedError is the error message for a unexpected error
	AnsiblePlaybookErrorMessageUnexpectedError = "ansible-playbook error: unexpected error"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DefaultExecute

type DefaultExecute struct {
	// Writer is where is written the command stdout
	Write io.Writer
	// WriterError is where is written the command stderr
	WriterError io.Writer
	// ShowDuration enables to show the execution duration time after the command finishes
	ShowDuration bool
	// CmdRunDir specifies the working directory of the command.
	CmdRunDir string
	// EnvVars specifies env vars of the command.
	EnvVars EnvVars
	// OutputFormat
	Transformers []results.TransformerFunc
}

DefaultExecute is a simple definition of an executor

func NewDefaultExecute

func NewDefaultExecute(options ...ExecuteOptions) *DefaultExecute

NewDefaultExecute return a new DefaultExecute instance with all options

func (*DefaultExecute) Execute

func (e *DefaultExecute) Execute(ctx context.Context, command []string, resultsFunc stdoutcallback.StdoutCallbackResultsFunc, options ...ExecuteOptions) error

Execute takes a command and args and runs it, streaming output to stdout

type EnvVars added in v1.1.6

type EnvVars map[string]string

EnvVars represents a custom environment for an ansible playbook execution.

func (EnvVars) Environ added in v1.1.6

func (e EnvVars) Environ() []string

Environ returns a copy of strings representing the custom environment, in the form "key=value".

type ExecuteOptions

type ExecuteOptions func(Executor)

ExecuteOptions is a function to set executor options

func WithCmdRunDir

func WithCmdRunDir(cmdRunDir string) ExecuteOptions

WithCmdRunDir set the command run directory to be used by DefaultExecutor

func WithEnvVar added in v1.1.5

func WithEnvVar(key, value string) ExecuteOptions

WithEnvVar adds the provided env var to the command

func WithShowDuration

func WithShowDuration() ExecuteOptions

WithShowDuration enables to show command duration

func WithTransformers

func WithTransformers(trans ...results.TransformerFunc) ExecuteOptions

WithTransformers add trasformes

func WithWrite

func WithWrite(w io.Writer) ExecuteOptions

WithWrite set the writer to be used by DefaultExecutor

func WithWriteError

func WithWriteError(w io.Writer) ExecuteOptions

WithWriteError set the error writer to be used by DefaultExecutor

type Executor

type Executor interface {
	Execute(ctx context.Context, command []string, resultsFunc stdoutcallback.StdoutCallbackResultsFunc, options ...ExecuteOptions) error
}

Executor interface is satisfied by those types which has a Execute(context.Context,[]string,stdoutcallback.StdoutCallbackResultsFunc,...ExecuteOptions)error method

type MockExecute

type MockExecute struct {
	mock.Mock
}

MockExecute is a mock of Execute interface

func NewMockExecute added in v1.1.6

func NewMockExecute() *MockExecute

NewMockExecute returns a new instance of MockExecute

func (*MockExecute) Execute

func (e *MockExecute) Execute(ctx context.Context, command []string, resultsFunc stdoutcallback.StdoutCallbackResultsFunc, options ...ExecuteOptions) error

Execute is a mock

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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