playbook

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2024 License: MIT Imports: 7 Imported by: 3

Documentation

Index

Constants

View Source
const (
	// TODO: error management
	// 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"
)
View Source
const (
	// AskVaultPasswordFlag ask for vault password
	AskVaultPasswordFlag = "--ask-vault-password"

	// CheckFlag don't make any changes; instead, try to predict some of the changes that may occur
	CheckFlag = "--check"

	// DiffFlag when changing (small) files and templates, show the differences in those files; works great with --check
	DiffFlag = "--diff"

	// ExtraVarsFlag is the extra variables flag for ansible-playbook
	ExtraVarsFlag = "--extra-vars"

	// FlushCacheFlag is the flush cache flag for ansible-playbook
	FlushCacheFlag = "--flush-cache"

	// ForceHandlersFlag run handlers even if a task fails
	ForceHandlersFlag = "--force-handlers"

	// ForksFlag specify number of parallel processes to use (default=50)
	ForksFlag = "--forks"

	// InventoryFlag is the inventory flag for ansible-playbook
	InventoryFlag = "--inventory"

	// LimitFlag is the limit flag for ansible-playbook
	LimitFlag = "--limit"

	// ListHostsFlag is the list hosts flag for ansible-playbook
	ListHostsFlag = "--list-hosts"

	// ListTagsFlag is the list tags flag for ansible-playbook
	ListTagsFlag = "--list-tags"

	// ListTasksFlag is the list tasks flag for ansible-playbook
	ListTasksFlag = "--list-tasks"

	// ModulePathFlag repend colon-separated path(s) to module library (default=~/.ansible/plugins/modules:/usr/share/ansible/plugins/modules)
	ModulePathFlag = "--module-path"

	// SkipTagsFlag only run plays and tasks whose tags do not match these values
	SkipTagsFlag = "--skip-tags"

	// StartAtTaskFlag start the playbook at the task matching this name
	StartAtTaskFlag = "--start-at-task"

	// StepFlag one-step-at-a-time: confirm each task before running
	StepFlag = "--step"

	// SyntaxCheckFlag is the syntax check flag for ansible-playbook
	SyntaxCheckFlag = "--syntax-check"

	// TagsFlag is the tags flag for ansible-playbook
	TagsFlag = "--tags"

	// VaultIDFlag the vault identity to use
	VaultIDFlag = "--vault-id"

	// VaultPasswordFileFlag is the vault password file flag for ansible-playbook
	VaultPasswordFileFlag = "--vault-password-file"

	// VersionFlag show program's version number, config file location, configured module search path, module location, executable location and exit
	VersionFlag = "--version"

	// VerboseFlag verbose mode enabled
	VerboseFlag = "-vvvv"

	// VerboseVFlag verbose with -v is enabled
	VerboseVFlag = "-v"

	// VerboseVVFlag verbose with -vv is enabled
	VerboseVVFlag = "-vv"

	// VerboseVFlag verbose with -vvv is enabled
	VerboseVVVFlag = "-vvv"

	// VerboseVFlag verbose with -vvvv is enabled
	VerboseVVVVFlag = "-vvvv"

	// AskPassFlag is ansble-playbook's ask for connection password flag
	AskPassFlag = "--ask-pass"

	// ConnectionFlag is the connection flag for ansible-playbook
	ConnectionFlag = "--connection"

	// PrivateKeyFlag is the private key file flag for ansible-playbook
	PrivateKeyFlag = "--private-key"

	// SCPExtraArgsFlag specify extra arguments to pass to scp only
	SCPExtraArgsFlag = "--scp-extra-args"

	// SFTPExtraArgsFlag specify extra arguments to pass to sftp only
	SFTPExtraArgsFlag = "--sftp-extra-args"

	// SSHCommonArgsFlag specify common arguments to pass to sftp/scp/ssh
	SSHCommonArgsFlag = "--ssh-common-args"

	// SSHExtraArgsFlag specify extra arguments to pass to ssh only
	SSHExtraArgsFlag = "--ssh-extra-args"

	// TimeoutFlag is the timeout flag for ansible-playbook
	TimeoutFlag = "--timeout"

	// UserFlag is the user flag for ansible-playbook
	UserFlag = "--user"

	// BecomeMethodFlag is ansble-playbook's become method flag
	BecomeMethodFlag = "--become-method"

	// BecomeUserFlag is ansble-playbook's become user flag
	BecomeUserFlag = "--become-user"

	// AskBecomePassFlag is ansble-playbook's ask for become user password flag
	AskBecomePassFlag = "--ask-become-pass"

	// BecomeFlag is ansble-playbook's become flag
	BecomeFlag = "--become"
)
View Source
const (
	// DefaultAnsiblePlaybookBinary is the ansible-playbook binary file default value
	DefaultAnsiblePlaybookBinary = "ansible-playbook"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AnsiblePlaybookCmd

type AnsiblePlaybookCmd struct {
	// Ansible binary file
	Binary string
	// Playbooks is the ansible's playbooks list to be used
	Playbooks []string
	// PlaybookOptions are the ansible's playbook options
	PlaybookOptions *AnsiblePlaybookOptions
}

AnsiblePlaybookCmd object is the main object which defines the `ansible-playbook` command and how to execute it.

func NewAnsiblePlaybookCmd

func NewAnsiblePlaybookCmd(options ...AnsiblePlaybookOptionsFunc) *AnsiblePlaybookCmd

NewAnsiblePlaybookCmd creates a new AnsiblePlaybookCmd instance

func (*AnsiblePlaybookCmd) Command

func (p *AnsiblePlaybookCmd) Command() ([]string, error)

Command generate the ansible-playbook command which will be executed

func (*AnsiblePlaybookCmd) String

func (p *AnsiblePlaybookCmd) String() string

String returns AnsiblePlaybookCmd as string

type AnsiblePlaybookErrorEnrich

type AnsiblePlaybookErrorEnrich struct{}

AnsiblePlaybookErrorEnrich is an error enricher for ansible-playbook errors

func NewAnsiblePlaybookErrorEnrich

func NewAnsiblePlaybookErrorEnrich() *AnsiblePlaybookErrorEnrich

NewAnsiblePlaybookErrorEnrich creates a new AnsiblePlaybookErrorEnrich instance

func (*AnsiblePlaybookErrorEnrich) Enrich

func (e *AnsiblePlaybookErrorEnrich) Enrich(err error) error

Enrich return an error enriched with ansible-playbook error information

type AnsiblePlaybookExecute

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

AnsiblePlaybookExecute is an executor for ansible-playbook command that runs the command using a DefaultExecute with default options

func NewAnsiblePlaybookExecute

func NewAnsiblePlaybookExecute(playbook ...string) *AnsiblePlaybookExecute

NewAnsiblePlaybookExecute returns a new AnsiblePlaybookExecute. It receives a list of playbooks to be executed

func (*AnsiblePlaybookExecute) Execute

func (e *AnsiblePlaybookExecute) Execute(ctx context.Context) error

Execute method runs the ansible-playbook command using a DefaultExecute with default options

func (*AnsiblePlaybookExecute) WithBinary

func (e *AnsiblePlaybookExecute) WithBinary(binary string) *AnsiblePlaybookExecute

WithAnsible return a AnsiblePlaybookExecute withthe binary file set

func (*AnsiblePlaybookExecute) WithPlaybookOptions

func (e *AnsiblePlaybookExecute) WithPlaybookOptions(options *AnsiblePlaybookOptions) *AnsiblePlaybookExecute

WithPlaybookOptions returns an AnsiblePlaybookExecute with the ansible's playbook options set

type AnsiblePlaybookOptions

type AnsiblePlaybookOptions struct {

	// AskVaultPassword ask for vault password
	AskVaultPassword bool

	// Check don't make any changes; instead, try to predict some of the changes that may occur
	Check bool

	// Diff when changing (small) files and templates, show the differences in those files; works great with --check
	Diff bool

	// ExtraVars is a map of extra variables used on ansible-playbook execution
	ExtraVars map[string]interface{}

	// ExtraVarsFile is a list of files used to load extra-vars
	ExtraVarsFile []string

	// FlushCache is the flush cache flag for ansible-playbook
	FlushCache bool

	// ForceHandlers run handlers even if a task fails
	ForceHandlers bool

	// Forks specify number of parallel processes to use (default=50)
	Forks string

	// Inventory specify inventory host path
	Inventory string

	// Limit is selected hosts additional pattern
	Limit string

	// ListHosts outputs a list of matching hosts
	ListHosts bool

	// ListTags is the list tags flag for ansible-playbook
	ListTags bool

	// ListTasks is the list tasks flag for ansible-playbook
	ListTasks bool

	// ModulePath repend colon-separated path(s) to module library (default=~/.ansible/plugins/modules:/usr/share/ansible/plugins/modules)
	ModulePath string

	// SkipTags only run plays and tasks whose tags do not match these values
	SkipTags string

	// StartAtTask start the playbook at the task matching this name
	StartAtTask string

	// Step one-step-at-a-time: confirm each task before running
	Step bool

	// SyntaxCheck is the syntax check flag for ansible-playbook
	SyntaxCheck bool

	// Tags is the tags flag for ansible-playbook
	Tags string

	// VaultID the vault identity to use
	VaultID string

	// VaultPasswordFile path to the file holding vault decryption key
	VaultPasswordFile string

	// Verbose verbose mode enabled
	Verbose bool

	// Verbose verbose mode -v enabled
	VerboseV bool

	// Verbose verbose mode -vv enabled
	VerboseVV bool

	// Verbose verbose mode -vvv enabled
	VerboseVVV bool

	// Verbose verbose mode -vvvv enabled
	VerboseVVVV bool

	// Version show program's version number, config file location, configured module search path, module location, executable location and exit
	Version bool

	// AskPass defines whether user's password should be asked to connect to host
	AskPass bool

	// Connection is the type of connection used by ansible-playbook
	Connection string

	// PrivateKey is the user's private key file used to connect to a host
	PrivateKey string

	// SCPExtraArgs specify extra arguments to pass to scp only
	SCPExtraArgs string

	// SFTPExtraArgs specify extra arguments to pass to sftp only
	SFTPExtraArgs string

	// SSHCommonArgs specify common arguments to pass to sftp/scp/ssh
	SSHCommonArgs string

	// SSHExtraArgs specify extra arguments to pass to ssh only
	SSHExtraArgs string

	// Timeout is the connection timeout on ansible-playbook. Take care because Timeout is defined ad string
	Timeout int

	// User is the user to use to connect to a host
	User string

	// AskBecomePass is ansble-playbook's ask for become user password flag
	AskBecomePass bool

	// Become is ansble-playbook's become flag
	Become bool

	// BecomeMethod is ansble-playbook's become method. The accepted become methods are:
	// 	- ksu        Kerberos substitute user
	// 	- pbrun      PowerBroker run
	// 	- enable     Switch to elevated permissions on a network device
	// 	- sesu       CA Privileged Access Manager
	// 	- pmrun      Privilege Manager run
	// 	- runas      Run As user
	// 	- sudo       Substitute User DO
	// 	- su         Substitute User
	// 	- doas       Do As user
	// 	- pfexec     profile based execution
	// 	- machinectl Systemd's machinectl privilege escalation
	// 	- dzdo       Centrify's Direct Authorize
	BecomeMethod string

	// BecomeUser is ansble-playbook's become user
	BecomeUser string
}

AnsiblePlaybookOptions object has those parameters described on `Options` section within ansible-playbook's man page, and which defines which should be the ansible-playbook execution behavior.

func (*AnsiblePlaybookOptions) AddExtraVar

func (o *AnsiblePlaybookOptions) AddExtraVar(name string, value interface{}) error

AddExtraVar registers a new extra variable on ansible-playbook options item

func (*AnsiblePlaybookOptions) AddExtraVarsFile

func (o *AnsiblePlaybookOptions) AddExtraVarsFile(file string) error

AddExtraVarsFile adds an extra-vars file on ansible-playbook options item

func (*AnsiblePlaybookOptions) AddVaultedExtraVar

func (o *AnsiblePlaybookOptions) AddVaultedExtraVar(vaulter Vaulter, name string, value string) error

AddVaultedExtraVar registers a new extra variable on ansible-playbook options item vaulting its value

func (*AnsiblePlaybookOptions) GenerateCommandOptions

func (o *AnsiblePlaybookOptions) GenerateCommandOptions() ([]string, error)

GenerateCommandOptions return a list of options flags to be used on ansible-playbook execution

func (*AnsiblePlaybookOptions) String

func (o *AnsiblePlaybookOptions) String() string

String returns AnsiblePlaybookOptions as string

type AnsiblePlaybookOptionsFunc

type AnsiblePlaybookOptionsFunc func(*AnsiblePlaybookCmd)

AnsiblePlaybookOptionsFunc is a function to set executor options

func WithBinary

func WithBinary(binary string) AnsiblePlaybookOptionsFunc

WithBinary set the ansible-playbook binary file

func WithPlaybookOptions

func WithPlaybookOptions(options *AnsiblePlaybookOptions) AnsiblePlaybookOptionsFunc

WithPlaybookOptions set the ansible-playbook options

func WithPlaybooks

func WithPlaybooks(playbooks ...string) AnsiblePlaybookOptionsFunc

WithPlaybooks set the ansible-playbook playbooks

type ExitCodeErrorer

type ExitCodeErrorer interface {
	ExitCode() int
}

type Vaulter

type Vaulter interface {
	Vault(value string) (*vault.VaultVariableValue, error)
}

Jump to

Keyboard shortcuts

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