From 68a99c109003d81a20fa7b66c69e3f635dcd428b Mon Sep 17 00:00:00 2001 From: TJ Hoplock Date: Fri, 21 Jul 2023 00:00:03 -0400 Subject: [PATCH] feat!: add host `group` concept to inventory, support globs + regex Lots of changes: - new `Group` type for new inventory component - new prometheus metrics with the component - `Store` interface functions that deal with enrollment have been updated to account for groups, as well - Manager has been updated to support keeping a list of group(s)/host variable file paths to source on reload, to allow for sourcing variables from `variables` files in any/all groups and/or from explicit host configs - `inventory.GetVariablesForSelf()` has been updated to return a slice of strings containing the paths to `variables` files relevant to the current host - add new func `filterDuplicateRoles()` to remove duplicate roles that could be assigned across multiple groups a host may be a member to - various test inventory updates to better utilize `group` configs --- go.mod | 1 + go.sum | 2 + internal/inventory/group.go | 216 ++++++++++++++++++ internal/inventory/host.go | 6 - internal/inventory/inventory.go | 154 ++++++++++++- internal/manager/manager.go | 68 +++--- internal/shell/shell.go | 12 +- test/mockup/inventory/groups/default/glob | 1 + test/mockup/inventory/groups/default/modules | 0 test/mockup/inventory/groups/default/regex | 0 test/mockup/inventory/groups/default/roles | 1 + .../mockup/inventory/groups/default/variables | 8 + .../inventory/groups/inventory-test/glob | 1 + .../inventory/groups/inventory-test/modules | 0 .../inventory/groups/inventory-test/regex | 0 .../inventory/groups/inventory-test/roles | 0 .../inventory/groups/inventory-test/variables | 1 + .../mockup/inventory/hosts/testbox-arch/roles | 1 - .../inventory/hosts/testbox-arch/variables | 7 - .../inventory/hosts/testbox-ubuntu/roles | 1 - .../inventory/hosts/testbox-ubuntu/variables | 7 - 21 files changed, 417 insertions(+), 70 deletions(-) create mode 100644 internal/inventory/group.go create mode 100644 test/mockup/inventory/groups/default/glob create mode 100644 test/mockup/inventory/groups/default/modules create mode 100644 test/mockup/inventory/groups/default/regex create mode 100644 test/mockup/inventory/groups/default/roles create mode 100644 test/mockup/inventory/groups/default/variables create mode 100644 test/mockup/inventory/groups/inventory-test/glob create mode 100644 test/mockup/inventory/groups/inventory-test/modules create mode 100644 test/mockup/inventory/groups/inventory-test/regex create mode 100644 test/mockup/inventory/groups/inventory-test/roles create mode 100644 test/mockup/inventory/groups/inventory-test/variables diff --git a/go.mod b/go.mod index 946acc8..343ba19 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.20 require ( github.com/dominikbraun/graph v0.22.3 + github.com/gobwas/glob v0.2.3 github.com/hashicorp/go-sockaddr v1.0.2 github.com/moby/moby v24.0.1+incompatible github.com/oklog/run v1.1.0 diff --git a/go.sum b/go.sum index 110d91b..5246eb7 100644 --- a/go.sum +++ b/go.sum @@ -72,6 +72,8 @@ github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbS github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= +github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y= +github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= diff --git a/internal/inventory/group.go b/internal/inventory/group.go new file mode 100644 index 0000000..ff14adc --- /dev/null +++ b/internal/inventory/group.go @@ -0,0 +1,216 @@ +package inventory + +import ( + "context" + "path/filepath" + "regexp" + "strings" + "time" + + "github.com/tjhop/mango/internal/utils" + + glob_util "github.com/gobwas/glob" + "github.com/prometheus/client_golang/prometheus" + log "github.com/sirupsen/logrus" +) + +// 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 +type Group struct { + id string + globs []string + patterns []string + modules []string + roles []string + variables string +} + +// String is a stringer to return the group ID +func (g Group) String() string { return g.id } + +// 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 (i *Inventory) ParseGroups(ctx context.Context) error { + commonLabels := prometheus.Labels{ + "inventory": i.inventoryPath, + "component": "groups", + } + + path := filepath.Join(i.inventoryPath, "groups") + groupDirs, err := utils.GetFilesInDirectory(path) + if err != nil { + log.WithFields(log.Fields{ + "path": path, + "error": err, + }).Error("Failed to get files in directory") + + // inventory counts haven't been altered, no need to update here + metricInventoryReloadFailedTotal.With(commonLabels).Inc() + + return err + } + + var groups []Group + + for _, groupDir := range groupDirs { + if groupDir.IsDir() { + groupPath := filepath.Join(path, groupDir.Name()) + groupFiles, err := utils.GetFilesInDirectory(groupPath) + if err != nil { + log.WithFields(log.Fields{ + "path": groupPath, + "error": err, + }).Error("Failed to parse group files") + + // inventory counts haven't been altered, no need to update here + metricInventoryReloadFailedTotal.With(commonLabels).Inc() + + return err + } + + group := Group{id: groupDir.Name()} + + for _, groupFile := range groupFiles { + if !groupFile.IsDir() && !strings.HasPrefix(groupFile.Name(), ".") { + fileName := groupFile.Name() + switch fileName { + case "glob": + var globs []string + globPath := filepath.Join(groupPath, "glob") + lines := utils.ReadFileLines(globPath) + + for line := range lines { + if line.Err != nil { + log.WithFields(log.Fields{ + "path": globPath, + "error": line.Err, + }).Error("Failed to read globs for group") + } else { + globs = append(globs, line.Text) + } + } + + group.globs = globs + case "regex": + var patterns []string + patternPath := filepath.Join(groupPath, "regex") + lines := utils.ReadFileLines(patternPath) + + for line := range lines { + if line.Err != nil { + log.WithFields(log.Fields{ + "path": patternPath, + "error": line.Err, + }).Error("Failed to read regexs for group") + } else { + patterns = append(patterns, line.Text) + } + } + + group.patterns = patterns + case "roles": + var roles []string + rolePath := filepath.Join(groupPath, "roles") + lines := utils.ReadFileLines(rolePath) + + for line := range lines { + if line.Err != nil { + log.WithFields(log.Fields{ + "path": rolePath, + "error": line.Err, + }).Error("Failed to read roles for group") + } else { + roles = append(roles, line.Text) + } + } + + group.roles = roles + case "modules": + var mods []string + modPath := filepath.Join(groupPath, "modules") + lines := utils.ReadFileLines(modPath) + + for line := range lines { + if line.Err != nil { + log.WithFields(log.Fields{ + "path": modPath, + "error": line.Err, + }).Error("Failed to read modules for group") + } else { + mods = append(mods, line.Text) + } + } + + group.modules = mods + case "variables": + group.variables = filepath.Join(groupPath, "variables") + default: + log.WithFields(log.Fields{ + "file": fileName, + }).Debug("Not sure what to do with this file, so skipping it.") + } + } + } + + groups = append(groups, group) + } + } + + i.groups = groups + metricInventory.With(commonLabels).Set(float64(len(i.groups))) + groupMatches := 0 + for _, group := range i.groups { + if group.IsHostEnrolled(i.hostname) { + groupMatches++ + } + } + metricInventoryApplicable.With(commonLabels).Set(float64(groupMatches)) + metricInventoryReloadSeconds.With(commonLabels).Set(float64(time.Now().Unix())) + metricInventoryReloadTotal.With(commonLabels).Inc() + + return nil +} + +func (g Group) MatchGlobs(hostname string) int { + matched := 0 + + for _, globPattern := range g.globs { + glob := glob_util.MustCompile(globPattern) + if glob.Match(hostname) { + matched++ + continue + } + } + + return matched +} + +func (g Group) MatchPatterns(hostname string) int { + matched := 0 + + for _, pattern := range g.patterns { + validPattern := regexp.MustCompile(pattern) + if validPattern.MatchString(hostname) { + matched++ + continue + } + } + + return matched +} + +func (g Group) MatchAll(hostname string) int { + return g.MatchGlobs(hostname) + g.MatchPatterns(hostname) +} + +func (g Group) IsHostEnrolled(hostname string) bool { + return g.MatchAll(hostname) > 0 +} diff --git a/internal/inventory/host.go b/internal/inventory/host.go index 16a094b..1f88310 100644 --- a/internal/inventory/host.go +++ b/internal/inventory/host.go @@ -24,12 +24,6 @@ type Host struct { variables string } -// GetVariables returns a VariableMap of variables -// assigned to this host -func (h Host) GetVariables() string { - return h.variables -} - // String is a stringer to return the host ID func (h Host) String() string { return h.id } diff --git a/internal/inventory/inventory.go b/internal/inventory/inventory.go index 2ae168f..dc30620 100644 --- a/internal/inventory/inventory.go +++ b/internal/inventory/inventory.go @@ -59,6 +59,7 @@ var ( // - 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 type Inventory struct { inventoryPath string hostname string @@ -66,6 +67,7 @@ type Inventory struct { modules []Module roles []Role directives []Directive + groups []Group } // String is a stringer to return the inventory path @@ -97,11 +99,13 @@ type Store interface { 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 @@ -114,7 +118,7 @@ type Store interface { GetDirectivesForSelf() []Directive GetModulesForSelf() []Module GetRolesForSelf() []Role - GetVariablesForSelf() string + GetVariablesForSelf() []string } // NewInventory parses the files/directories in the provided path @@ -140,6 +144,13 @@ func NewInventory(path, name string) *Inventory { func (i *Inventory) Reload(ctx context.Context) { // populate the inventory + // parse groups + if err := i.ParseGroups(ctx); err != nil { + log.WithFields(log.Fields{ + "error": err, + }).Error("Failed to reload groups") + } + // parse hosts if err := i.ParseHosts(ctx); err != nil { log.WithFields(log.Fields{ @@ -169,11 +180,21 @@ func (i *Inventory) Reload(ctx context.Context) { } } -// IsEnrolled returns true is this system's hostname is found -// in the inventory's Host map, and false otherwise. +// 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 (i *Inventory) IsEnrolled() bool { - _, found := i.GetHost(i.hostname) - return found + if _, found := i.GetHost(i.hostname); found { + return true + } + + for _, group := range i.groups { + if group.IsHostEnrolled(i.hostname) { + return true + } + } + + return false } // GetDirectives returns a copy of the inventory's slice of Directive @@ -250,10 +271,52 @@ func (i *Inventory) GetModulesForHost(host string) []Module { return filterDuplicateModules(mods) } +// 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 (i *Inventory) GetModulesForGroup(group string) []Module { + mods := []Module{} + + if g, found := i.GetGroup(group); found { + // get modules from all roles group is assigned + for _, r := range g.roles { + mods = append(mods, i.GetModulesForRole(r)...) + } + + // get raw group modules + for _, m := range g.modules { + if mod, found := i.GetModule(m); found { + mods = append(mods, mod) + } + } + } + + return filterDuplicateModules(mods) +} + +func (i *Inventory) GetRolesForGroup(group string) []Role { + roles := []Role{} + + if g, found := i.GetGroup(group); found { + for _, r := range g.roles { + if role, found := i.GetRole(r); found { + roles = append(roles, role) + } + } + } + return roles +} + // GetModulesForSelf returns a slice of Modules, containing all of the // Modules for the running system from the inventory. func (i *Inventory) GetModulesForSelf() []Module { - return i.GetModulesForHost(i.hostname) + var mods []Module + + mods = append(mods, i.GetModulesForHost(i.hostname)...) + for _, group := range i.groups { + mods = append(mods, i.GetModulesForGroup(group.String())...) + } + + return filterDuplicateModules(mods) } // GetRole returns a copy of the Role struct for a role identified @@ -294,7 +357,16 @@ func (i *Inventory) GetRolesForHost(host string) []Role { // GetRolesForSelf returns a slice of Roles, containing all of the // Roles for the running system from the inventory. func (i *Inventory) GetRolesForSelf() []Role { - return i.GetRolesForHost(i.hostname) + // return i.GetRolesForHost(i.hostname) + + var roles []Role + + roles = append(roles, i.GetRolesForHost(i.hostname)...) + for _, group := range i.groups { + roles = append(roles, i.GetRolesForGroup(group.String())...) + } + + return filterDuplicateRoles(roles) } // GetHosts returns a copy of the inventory's Hosts. @@ -325,10 +397,25 @@ func (i *Inventory) GetVariablesForHost(host string) string { return "" } -// GetVariablesForSelf returns a copy of the variable map for the running -// system. -func (i *Inventory) GetVariablesForSelf() string { - return i.GetVariablesForHost(i.hostname) +// 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 (i *Inventory) GetVariablesForSelf() []string { + var tmp, varFiles []string + + for _, group := range i.groups { + tmp = append(tmp, i.GetVariablesForGroup(group.String())) + } + + tmp = append(tmp, i.GetVariablesForHost(i.hostname)) + for _, file := range tmp { + if file != "" { + varFiles = append(varFiles, file) + } + } + + return varFiles } func filterDuplicateModules(input []Module) []Module { @@ -347,3 +434,48 @@ func filterDuplicateModules(input []Module) []Module { return output } + +func filterDuplicateRoles(input []Role) []Role { + roleMap := make(map[string]Role) + + for _, r := range input { + if _, found := roleMap[r.String()]; !found { + roleMap[r.String()] = r + } + } + + var output []Role + for _, role := range roleMap { + output = append(output, role) + } + + return output +} + +// GetGroups returns a copy of the inventory's Groups. +func (i *Inventory) GetGroups() []Group { + return i.groups +} + +// 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 (i *Inventory) GetGroup(group string) (Group, bool) { + for _, g := range i.groups { + if filepath.Base(g.id) == group { + return g, true + } + } + + return Group{}, false +} + +// GetVariablesForGroup returns the path of the group's variables file, or the +// empty string if no group/variables file found +func (i *Inventory) GetVariablesForGroup(group string) string { + if g, found := i.GetGroup(group); found { + return g.variables + } + + return "" +} diff --git a/internal/manager/manager.go b/internal/manager/manager.go index c372211..13cd344 100644 --- a/internal/manager/manager.go +++ b/internal/manager/manager.go @@ -249,7 +249,7 @@ func (mgr *Manager) ReloadModules(ctx context.Context) { // if the module has a variables file set, source it and store // the expanded variables if mod.Variables != "" { - newMod.Variables = mgr.ReloadVariables(ctx, mod.Variables, shell.MakeVariableMap(mgr.hostVariables)) + newMod.Variables = mgr.ReloadVariables(ctx, []string{mod.Variables}, shell.MakeVariableMap(mgr.hostVariables)) } else { mgr.logger.Debug("No module variables") } @@ -330,45 +330,51 @@ func (mgr *Manager) Reload(ctx context.Context, inv inventory.Store) { // ensure vars are only sourced on manager reload, to avoid needlessly // sourcing variables potentially multiple times during a run (which is // triggered directly after a reload of data from inventory) - hostVarsPath := inv.GetVariablesForSelf() - if hostVarsPath != "" { - mgr.hostVariables = mgr.ReloadVariables(ctx, hostVarsPath, nil) + hostVarsPaths := inv.GetVariablesForSelf() + if len(hostVarsPaths) > 0 { + mgr.hostVariables = mgr.ReloadVariables(ctx, hostVarsPaths, nil) } else { mgr.logger.Debug("No host variables") } } -func (mgr *Manager) ReloadVariables(ctx context.Context, path string, hostVars VariableMap) VariableSlice { - allTemplateData := mgr.getTemplateData(ctx, path, hostVars, nil, hostVars) - renderedVars, err := templateScript(ctx, path, allTemplateData, mgr.funcMap) - if err != nil { - mgr.logger.WithFields(log.Fields{ - "path": path, - "error": err, - }).Error("Failed to template variables") - return nil - } +func (mgr *Manager) ReloadVariables(ctx context.Context, paths []string, hostVars VariableMap) VariableSlice { + var varMaps []VariableMap - // source variables from the templated variables file - file, err := syntax.NewParser().Parse(strings.NewReader(renderedVars), "") - if err != nil { - mgr.logger.WithFields(log.Fields{ - "path": path, - "error": err, - }).Error("Failed to parse variables") - return nil - } + for _, path := range paths { + allTemplateData := mgr.getTemplateData(ctx, path, hostVars, nil, hostVars) + renderedVars, err := templateScript(ctx, path, allTemplateData, mgr.funcMap) + if err != nil { + mgr.logger.WithFields(log.Fields{ + "path": path, + "error": err, + }).Error("Failed to template variables") + return nil + } - vars, err := shell.SourceNode(ctx, file) - if err != nil { - mgr.logger.WithFields(log.Fields{ - "path": path, - "error": err, - }).Error("Failed to reload variables") - return nil + // source variables from the templated variables file + file, err := syntax.NewParser().Parse(strings.NewReader(renderedVars), "") + if err != nil { + mgr.logger.WithFields(log.Fields{ + "path": path, + "error": err, + }).Error("Failed to parse variables") + return nil + } + + vars, err := shell.SourceNode(ctx, file) + if err != nil { + mgr.logger.WithFields(log.Fields{ + "path": path, + "error": err, + }).Error("Failed to reload variables") + return nil + } + + varMaps = append(varMaps, shell.MakeVariableMap(vars)) } - return vars + return shell.MergeVariables(varMaps...) } // RunDirective is responsible for actually executing a directive, using the `shell` diff --git a/internal/shell/shell.go b/internal/shell/shell.go index 95264ef..e7a1c44 100644 --- a/internal/shell/shell.go +++ b/internal/shell/shell.go @@ -174,13 +174,13 @@ func MakeVariableMap(varSlice VariableSlice) VariableMap { return varMap } -func MergeVariables(base, top VariableMap) VariableSlice { +func MergeVariables(maps ...VariableMap) VariableSlice { vars := make(VariableMap) - for k, v := range base { - vars[k] = v - } - for k, v := range top { - vars[k] = v + + for _, varMap := range maps { + for k, v := range varMap { + vars[k] = v + } } varSlice := make(VariableSlice, len(vars)) diff --git a/test/mockup/inventory/groups/default/glob b/test/mockup/inventory/groups/default/glob new file mode 100644 index 0000000..72e8ffc --- /dev/null +++ b/test/mockup/inventory/groups/default/glob @@ -0,0 +1 @@ +* diff --git a/test/mockup/inventory/groups/default/modules b/test/mockup/inventory/groups/default/modules new file mode 100644 index 0000000..e69de29 diff --git a/test/mockup/inventory/groups/default/regex b/test/mockup/inventory/groups/default/regex new file mode 100644 index 0000000..e69de29 diff --git a/test/mockup/inventory/groups/default/roles b/test/mockup/inventory/groups/default/roles new file mode 100644 index 0000000..30e1159 --- /dev/null +++ b/test/mockup/inventory/groups/default/roles @@ -0,0 +1 @@ +common diff --git a/test/mockup/inventory/groups/default/variables b/test/mockup/inventory/groups/default/variables new file mode 100644 index 0000000..e74c043 --- /dev/null +++ b/test/mockup/inventory/groups/default/variables @@ -0,0 +1,8 @@ +mango_group_template_var="Hi, I'm a group variable!" +{{- with $os := .Mango.OS.OSRelease.ID }} +{{- if eq $os "arch" }} +package_install="pacman -Sy" +{{- else if or (eq $os "ubuntu") (eq $os "debian") }} +package_install="apt-get install -y" +{{- end }} +{{- end }} diff --git a/test/mockup/inventory/groups/inventory-test/glob b/test/mockup/inventory/groups/inventory-test/glob new file mode 100644 index 0000000..1549dd2 --- /dev/null +++ b/test/mockup/inventory/groups/inventory-test/glob @@ -0,0 +1 @@ +testbox* diff --git a/test/mockup/inventory/groups/inventory-test/modules b/test/mockup/inventory/groups/inventory-test/modules new file mode 100644 index 0000000..e69de29 diff --git a/test/mockup/inventory/groups/inventory-test/regex b/test/mockup/inventory/groups/inventory-test/regex new file mode 100644 index 0000000..e69de29 diff --git a/test/mockup/inventory/groups/inventory-test/roles b/test/mockup/inventory/groups/inventory-test/roles new file mode 100644 index 0000000..e69de29 diff --git a/test/mockup/inventory/groups/inventory-test/variables b/test/mockup/inventory/groups/inventory-test/variables new file mode 100644 index 0000000..872ff6f --- /dev/null +++ b/test/mockup/inventory/groups/inventory-test/variables @@ -0,0 +1 @@ +mango_group_template_var="Hi, I'm a group variable!" diff --git a/test/mockup/inventory/hosts/testbox-arch/roles b/test/mockup/inventory/hosts/testbox-arch/roles index 30e1159..e69de29 100644 --- a/test/mockup/inventory/hosts/testbox-arch/roles +++ b/test/mockup/inventory/hosts/testbox-arch/roles @@ -1 +0,0 @@ -common diff --git a/test/mockup/inventory/hosts/testbox-arch/variables b/test/mockup/inventory/hosts/testbox-arch/variables index 0985261..0204750 100644 --- a/test/mockup/inventory/hosts/testbox-arch/variables +++ b/test/mockup/inventory/hosts/testbox-arch/variables @@ -1,9 +1,2 @@ mango_host_template_var="Hi, I'm a host variable!" mango_host_var_for_override="This is the original host variable content." -{{- with $os := .Mango.OS.OSRelease.ID }} -{{- if eq $os "arch" }} -package_install="pacman -Sy" -{{- else if or (eq $os "ubuntu") (eq $os "debian") }} -package_install="apt-get install -y" -{{- end }} -{{- end }} diff --git a/test/mockup/inventory/hosts/testbox-ubuntu/roles b/test/mockup/inventory/hosts/testbox-ubuntu/roles index 30e1159..e69de29 100644 --- a/test/mockup/inventory/hosts/testbox-ubuntu/roles +++ b/test/mockup/inventory/hosts/testbox-ubuntu/roles @@ -1 +0,0 @@ -common diff --git a/test/mockup/inventory/hosts/testbox-ubuntu/variables b/test/mockup/inventory/hosts/testbox-ubuntu/variables index 0985261..0204750 100644 --- a/test/mockup/inventory/hosts/testbox-ubuntu/variables +++ b/test/mockup/inventory/hosts/testbox-ubuntu/variables @@ -1,9 +1,2 @@ mango_host_template_var="Hi, I'm a host variable!" mango_host_var_for_override="This is the original host variable content." -{{- with $os := .Mango.OS.OSRelease.ID }} -{{- if eq $os "arch" }} -package_install="pacman -Sy" -{{- else if or (eq $os "ubuntu") (eq $os "debian") }} -package_install="apt-get install -y" -{{- end }} -{{- end }}