Skip to content

Commit

Permalink
feat(inv): add GetTemplatesForHost and self to inventory.Store interface
Browse files Browse the repository at this point in the history
  • Loading branch information
tjhop committed Jul 8, 2024
1 parent 9edb34a commit bb008a3
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions internal/inventory/inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,15 @@ type Store interface {
GetRolesForHost(host string) []Role
GetGroupsForHost(host string) []Group
GetVariablesForHost(host string) []string
GetTemplatesForHost(host string) []string

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

// NewInventory parses the files/directories in the provided path
Expand Down Expand Up @@ -463,6 +465,36 @@ func (i *Inventory) GetVariablesForSelf() []string {
return i.GetVariablesForHost(i.hostname)
}

// GetTemplatesForHost returns slice of strings, containing the paths of any
// templates files found for this host. All role templates are provided first,
// then group templates second, with host-specific templates provided last (to
// allow for overriding default group variable data).
func (i *Inventory) GetTemplatesForHost(host string) []string {
var tmpls []string

for _, role := range i.GetRolesForHost(host) {
tmpls = append(tmpls, role.templateFiles...)
}

for _, group := range i.GetGroupsForHost(host) {
tmpls = append(tmpls, group.templateFiles...)
}

if h, found := i.GetHost(host); found {
tmpls = append(tmpls, h.templateFiles...)
}

return tmpls
}

// GetTemplatesForSelf returns slice of strings, containing the paths of any
// templates files found for the running host. All role templates are provided
// first, then group templates second, with host-specific templates provided
// last (to allow for overriding default group variable data).
func (i *Inventory) GetTemplatesForSelf() []string {
return i.GetTemplatesForHost(i.hostname)
}

func filterDuplicateModules(input []Module) []Module {
modMap := make(map[string]Module)

Expand Down

0 comments on commit bb008a3

Please sign in to comment.