ansible

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2019 License: MIT Imports: 15 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReturnedError

func ReturnedError(code int) error

ReturnedError returns a error corresponding to the provided Ansible returned code.

Will return `nil` if the code is not an known Ansible error or if it's equal to `0`

Types

type BaseParam

type BaseParam struct {
	// The content of the BaseParam
	Body model.Parameters
}

BaseParam contains the extra vars to be passed to a playbook

The BaseParam content is supposed to be serialized in yaml in order to be passed to a playbook

func BuildBaseParam

func BuildBaseParam(env *model.Environment, pubK string, privK string, nodesetName string) BaseParam

BuildBaseParam the common parameters required by all playbooks.

Parameters:

name: the qualified name of the environment
nodesetName: the name of the nodeset we are working with
provider: the name of the provider where to create the nodeset
pubK: the public SSH key to connect on the created nodeset ( the name of the file)
privK: the private SSH key to connect on the created nodeset ( the name of the file)

func (*BaseParam) AddBuffer

func (bp *BaseParam) AddBuffer(b Buffer)

AddBuffer adds the parameters coming from the given buffer

Only the "Param" content of the buffer will be processed.

func (*BaseParam) AddInt

func (bp *BaseParam) AddInt(name string, i int)

AddInt adds a int parameter for the given name

func (*BaseParam) AddInterface

func (bp *BaseParam) AddInterface(name string, i interface{})

AddInterface adds a parameter of type interface{} for the given name

func (*BaseParam) AddMap

func (bp *BaseParam) AddMap(m map[string]interface{})

AddMap adds parameters of interface{} for all the given map entries

func (*BaseParam) AddNamedMap

func (bp *BaseParam) AddNamedMap(name string, c map[string]interface{})

AddNamedMap adds a parameter of type map[string]interface{} for the given name

func (*BaseParam) AddString

func (bp *BaseParam) AddString(name string, s string)

AddString adds a string parameter for the given name

func (BaseParam) Content

func (bp BaseParam) Content() (b []byte, e error)

Content returns the yaml representation of the content

func (BaseParam) Copy

func (bp BaseParam) Copy() BaseParam

Copy returns a copy of the base parameter

type Buffer

type Buffer struct {
	// The environment variables to pass
	Envvars map[string]string
	// The extra vars to pass
	Extravars map[string]string
	// The inventories to pass
	Inventories map[string]string
	// The parameters to pass.
	// The parameters can be any valid yaml content
	Param map[string]interface{}
}

Buffer contains the data to be passed from one playbook to another one

func CreateBuffer

func CreateBuffer() Buffer

CreateBuffer creates an empty buffer

func GetBuffer

func GetBuffer(f util.FolderPath, logger *log.Logger, location string) (buffer Buffer, err error)

GetBuffer returns a buffer based on the content of the given folder.

  • The "Envvars" of the buffer will be filled by the content of the file name like EnvYamlFileName.
  • The "Extravars" of the buffer will be filled by the content of the file name like ExtraVarYamlFileName.
  • The "Inventories" of the buffer will be filled by the content of the file name like InventoryYamlFileName.
  • The "Param" of the buffer will be filled by the content of the file name like ParamYamlFileName.

Parameters:

f: the folder where to look for the buffer content
logger: the logger
location: a string used to specify, into the log messages, to which concept the buffer is related

See Also :

EnvYamlFileName
ExtraVarYamlFileName
InventoryYamlFileName
ParamYamlFileName

func (Buffer) Params

func (b Buffer) Params() (by []byte, e error)

Params returns the yaml content of the buffer

type EnvVars

type EnvVars struct {
	Content map[string]string
}

EnvVars contains the extra vars to be passed to a playbook

func BuildEnvVars

func BuildEnvVars() EnvVars

BuildEnvVars creates and empy EnvVars

func (*EnvVars) Add

func (ev *EnvVars) Add(key, value string)

Add adds the given key and value.

If the key already exists then its content will be overwritten by the by the value

func (*EnvVars) AddBuffer

func (ev *EnvVars) AddBuffer(b Buffer)

AddBuffer adds the environment variable coming from the given buffer

Only the "Extravars" content of the buffer will be processed.

If any of the buffered keys already exist then its content will be overwritten by the by the corresponding buffered value.

func (*EnvVars) AddDefaultOsVars

func (ev *EnvVars) AddDefaultOsVars()

AddDefaultOsVars adds the HOSTNAME, PATH, TERM and HOME OS variables

func (*EnvVars) AddOsVars

func (ev *EnvVars) AddOsVars(vars ...string)

AddOsVars adds the current OS value of the specified variables

If the var list is empty, all os variables are added

func (*EnvVars) AddProxy

func (ev *EnvVars) AddProxy(proxy model.Proxy)

AddProxy adds the proxy information if any

If proxy info is already present, it will be overwritten or removed if empty proxy values are passed

type ExtraVars

type ExtraVars struct {
	// Indicates if the struct has content or not
	Bool bool
	// The extra vars content
	Vals []string
}

ExtraVars extra vars, received into the buffer, to be passed to a playbook

func BuildExtraVars

func BuildExtraVars(extraVars string, inputFolder util.FolderPath, outputFolder util.FolderPath, b Buffer) ExtraVars

BuildExtraVars builds the extra var to pass to a playbook

func (ExtraVars) String

func (ev ExtraVars) String() string

type Manager

type Manager interface {
	// Execute runs a playbook within a component
	//
	// Parameters:
	//		cr: the component holding the playbook to launch
	//		playbook: the name of the playbook to launch
	//		extraVars: the extra vars passed to the playbook
	//		envars: the environment variables set before launching the playbook
	//		data: the template context required to template a used component
	//
	Execute(cr component.UsableComponent, playbook string, extraVars ExtraVars, envars EnvVars) (int, error)
}

Manager executes an ansible playbook

func CreateAnsibleManager

func CreateAnsibleManager(lC util.LaunchContext, componentManager component.Manager) Manager

CreateAnsibleManager returns a new AnsibleManager, able to launch playbook holded by the given component manager

type ParamValues

type ParamValues map[string]string

func ParseParamValues

func ParseParamValues(path string) (ParamValues, error)

ParseParamValues parses a yaml file into a map of "key:value" All the nested yaml levels will be concatenated to create the keys of the map.

As example :

level1:
  level2:value

Will generate the following key/value

level1.level2=value

Jump to

Keyboard shortcuts

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