inventory

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Directive added in v0.0.4

type Directive struct {
	ID string
}

Directive contains fields that are relevant specifically to directive scripts, which are only executed if their modification time is within the last 24h Directive contains fields that represent a script in the inventory's directives directory. These scripts are executed first when changes are detected in the inventory, if and only if the script has a modification time within the last 24h. - ID: string idenitfying the directive script (generally the file path to the script)

func (Directive) String added in v0.0.4

func (d Directive) String() string

String is a stringer to return the module ID

type Group added in v0.7.0

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

Group contains fields that represent a given group of groups in the inventory. - id: string idenitfying the group - globs: a slice of glob patterns to match against the instance's hostname - patterns: a slice of regex patterns to match against the instance's hostname - roles: a slice of roles that are applied to this host - modules: a slice of ad-hoc module names applied to this host - variables: path to the variables file for this group, if present

func (Group) IsHostEnrolled added in v0.7.0

func (g Group) IsHostEnrolled(hostname string) bool

func (Group) MatchAll added in v0.7.0

func (g Group) MatchAll(hostname string) int

func (Group) MatchGlobs added in v0.7.0

func (g Group) MatchGlobs(hostname string) int

func (Group) MatchPatterns added in v0.7.0

func (g Group) MatchPatterns(hostname string) int

func (Group) String added in v0.7.0

func (g Group) String() string

String is a stringer to return the group ID

type Host

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

Host contains fields that represent a given host in the inventory. - id: string idenitfying the host (generally the hostname of the system) - roles: a slice of roles that are applied to this host - modules: a slice of ad-hoc module names applied to this host - variables: path to the variables file for this host, if present

func (Host) String

func (h Host) String() string

String is a stringer to return the host ID

type Inventory

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

Inventory contains fields that comprise the data that makes up our inventory. - Hosts: a slice of `Host` structs for each parsed host - Modules: a slice of `Module` structs for each parsed module - Roles: a slice of `Role` structs for each parsed role - Directives: a slice of `Directive` structs, containing for each parsed directive - Groups: a slice of `Group` structs, containing globs/patterns for hostname matching

func NewInventory

func NewInventory(path, name string) *Inventory

NewInventory parses the files/directories in the provided path to populate the inventory.

func (*Inventory) GetDirectives

func (i *Inventory) GetDirectives() []Directive

GetDirectives returns a copy of the inventory's slice of Directive

func (*Inventory) GetDirectivesForHost

func (i *Inventory) GetDirectivesForHost(host string) []Directive

GetDirectivesForHost returns a copy of the inventory's slice of Directive. Since directives are applied to all hosts, this internally just calls `inventory.GetDirectives()`

func (*Inventory) GetDirectivesForSelf

func (i *Inventory) GetDirectivesForSelf() []Directive

GetDirectivesForSelf returns a copy of the inventory's slice of Directive. Since directives are applied to all hosts, this internally just calls `inventory.GetDirectives()`

func (*Inventory) GetGroup added in v0.7.0

func (i *Inventory) GetGroup(group string) (Group, bool)

GetGroup returns a copy of the Group struct for a system identified by `group` name, and a boolean indicating whether or not the named group was found in the inventory.

func (*Inventory) GetGroups added in v0.7.0

func (i *Inventory) GetGroups() []Group

GetGroups returns a copy of the inventory's Groups.

func (*Inventory) GetHost

func (i *Inventory) GetHost(host string) (Host, bool)

GetHost returns a copy of the Host struct for a system identified by `host` name, and a boolean indicating whether or not the named host was found in the inventory.

func (*Inventory) GetHostname added in v0.2.0

func (i *Inventory) GetHostname() string

GetHostname returns the inventory path as a string

func (*Inventory) GetHosts

func (i *Inventory) GetHosts() []Host

GetHosts returns a copy of the inventory's Hosts.

func (*Inventory) GetInventoryPath added in v0.2.0

func (i *Inventory) GetInventoryPath() string

GetInventoryPath returns the inventory path as a string

func (*Inventory) GetModule

func (i *Inventory) GetModule(module string) (Module, bool)

GetModule returns a copy of the Module struct for a module identified by `module`, and a boolean indicating whether or not the named module was found in the inventory.

func (*Inventory) GetModules

func (i *Inventory) GetModules() []Module

GetModules returns a copy of the inventory's Modules.

func (*Inventory) GetModulesForGroup added in v0.7.0

func (i *Inventory) GetModulesForGroup(group string) []Module

GetModulesForGroup returns a slice of Modules, containing all of the Modules for the specified host system (including modules in all assigned roles, as well as ad-hoc modules).

func (*Inventory) GetModulesForHost

func (i *Inventory) GetModulesForHost(host string) []Module

GetModulesForHost returns a slice of Modules, containing all of the Modules for the specified host system (including modules in all assigned roles, as well as ad-hoc modules).

func (*Inventory) GetModulesForRole

func (i *Inventory) GetModulesForRole(role string) []Module

GetModulesForRole returns a slice of Modules, containing all of the Modules for the specified role.

func (*Inventory) GetModulesForSelf

func (i *Inventory) GetModulesForSelf() []Module

GetModulesForSelf returns a slice of Modules, containing all of the Modules for the running system from the inventory.

func (*Inventory) GetRole

func (i *Inventory) GetRole(role string) (Role, bool)

GetRole returns a copy of the Role struct for a role identified by `role`. If the named role is not found in the inventory, an empty Role is returned.

func (*Inventory) GetRoles

func (i *Inventory) GetRoles() []Role

GetRoles returns a copy of the inventory's Roles.

func (*Inventory) GetRolesForGroup added in v0.7.0

func (i *Inventory) GetRolesForGroup(group string) []Role

func (*Inventory) GetRolesForHost

func (i *Inventory) GetRolesForHost(host string) []Role

GetRolesForHost returns a slice of Roles, containing all of the Roles for the specified host system.

func (*Inventory) GetRolesForSelf

func (i *Inventory) GetRolesForSelf() []Role

GetRolesForSelf returns a slice of Roles, containing all of the Roles for the running system from the inventory.

func (*Inventory) GetVariablesForGroup added in v0.7.0

func (i *Inventory) GetVariablesForGroup(group string) string

GetVariablesForGroup returns the path of the group's variables file, or the empty string if no group/variables file found

func (*Inventory) GetVariablesForHost

func (i *Inventory) GetVariablesForHost(host string) string

GetVariablesForHost returns the path of the host's variables file, or the empty string if no host/variables file found

func (*Inventory) GetVariablesForSelf

func (i *Inventory) GetVariablesForSelf() []string

GetVariablesForSelf returns slice of strings, containing the paths of any variables files found for this host. All group variables a provided first, with host-specific variables provided last (to allow for overriding default group variable data).

func (*Inventory) IsEnrolled

func (i *Inventory) IsEnrolled() bool

IsEnrolled returns if the hostname of the system is defined in the inventory, or if the hostname of the system matches any group match parameters

func (*Inventory) ParseDirectives

func (i *Inventory) ParseDirectives(ctx context.Context, logger *slog.Logger) error

ParseDirectives looks for scripts in the inventory's `directives/` folder and adds them

func (*Inventory) ParseGroups added in v0.7.0

func (i *Inventory) ParseGroups(ctx context.Context, logger *slog.Logger) error

ParseGroups looks for groups in the inventory's `groups/` folder. It looks for folders within this directory, and then parses each directory into a Group struct. Each Group folder may contain a file `glob` containing a newline separated list of glob matches, and a `regex` file containing regular expression patterns for comparing groupnames.

func (*Inventory) ParseHosts

func (i *Inventory) ParseHosts(ctx context.Context, logger *slog.Logger) error

ParseHosts looks for hosts in the inventory's `hosts/` folder. It looks for folders within this directory, and then parses each directory into a Host struct. Each host folder is expected to contain files for `apply`, `variables`, and `test`, which get set to the corresponding fields in the Host struct for the host.

func (*Inventory) ParseModules

func (i *Inventory) ParseModules(ctx context.Context, logger *slog.Logger) error

ParseModules looks for modules in the inventory's `modules/` folder. It looks for folders within this directory, and then parses each directory into a Module struct. Each module folder is expected to contain files for `apply`, `variables`, and `test`, which get set to the corresponding fields in the Module struct for the module.

func (*Inventory) ParseRoles

func (i *Inventory) ParseRoles(ctx context.Context, logger *slog.Logger) error

ParseRoles searches for directories in the provided path. Each directory is treated as a role -- each role is checked for the appropriate `modules` file to parse for the list of modules for the role.

func (*Inventory) Reload

func (i *Inventory) Reload(ctx context.Context, logger *slog.Logger)

Reload reloads Inventory from it's configured path. Components that are reloaded: - Hosts - Roles - Modules - Directives

func (*Inventory) String

func (i *Inventory) String() string

String is a stringer to return the inventory path

type Module

type Module struct {
	ID        string
	Apply     string
	Variables string
	Test      string
	Requires  string
}

Module contains fields that represent a single module in the inventory. - ID: string idenitfying the module (generally the file path to the module) - Apply: path to apply script for the module - Variables: path to variables file for the module, if present - Requires: path to requirements file for the module, if present - Test: path to test script to check module's application status

func (Module) String

func (m Module) String() string

String is a stringer to return the module ID

type Role

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

Role contains fields that represent a single role in the inventory. - ID: string idenitfying the role (generally the file path to the role) - Modules: a []string of module names that satisfy this role

func (Role) String

func (r Role) String() string

String is a stringer to return the role ID

type Store

type Store interface {
	// Inventory management functions
	Reload(ctx context.Context, logger *slog.Logger)

	// Enrollment and runtime/metadata checks
	IsEnrolled() bool
	GetInventoryPath() string
	GetHostname() string

	// General Inventory Getters
	GetDirectives() []Directive
	GetHosts() []Host
	GetModules() []Module
	GetRoles() []Role
	GetGroups() []Group

	// Inventory checks by component IDs
	GetHost(host string) (Host, bool)
	GetModule(module string) (Module, bool)
	GetRole(role string) (Role, bool)
	GetGroup(group string) (Group, bool)

	// Checks by host
	GetDirectivesForHost(host string) []Directive
	GetModulesForRole(role string) []Module
	GetModulesForHost(host string) []Module
	GetRolesForHost(host string) []Role
	GetVariablesForHost(host string) string

	// Self checks
	GetDirectivesForSelf() []Directive
	GetModulesForSelf() []Module
	GetRolesForSelf() []Role
	GetVariablesForSelf() []string
}

Store is the set of methods that Inventory must implement to serve as a backing store for an inventory implementation. This is to try and keep a consistent API in the event that other inventory types are introduced, as well as to keep the required methods centralized if new features are introduced.

Jump to

Keyboard shortcuts

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