Skip to content

Commit b5856ec

Browse files
inventory_plugins
1 parent 4d61168 commit b5856ec

4 files changed

Lines changed: 134 additions & 232 deletions

File tree

pkg/config/config.go

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,23 @@ import (
1111

1212
// Config holds all configuration settings
1313
type Config struct {
14-
Logging LoggingConfig `mapstructure:"logging"`
15-
ExecutionMode string `mapstructure:"execution_mode"`
16-
Executor string `mapstructure:"executor"` // "local" or "temporal"
17-
Temporal TemporalConfig `mapstructure:"temporal"`
18-
API APIConfig `mapstructure:"api"`
19-
Daemon DaemonConfig `mapstructure:"daemon"`
20-
Revert bool `mapstructure:"revert"`
21-
Tags TagsConfig `mapstructure:"tags"`
22-
Facts map[string]interface{} `mapstructure:"facts"`
23-
HostKeyChecking bool `mapstructure:"host_key_checking"`
24-
RolesPath string `mapstructure:"roles_path"` // Colon-delimited paths to search for roles
25-
Inventory string `mapstructure:"inventory"` // Colon-delimited paths to search for inventory files
14+
Logging LoggingConfig `mapstructure:"logging"`
15+
ExecutionMode string `mapstructure:"execution_mode"`
16+
Executor string `mapstructure:"executor"` // "local" or "temporal"
17+
Temporal TemporalConfig `mapstructure:"temporal"`
18+
API APIConfig `mapstructure:"api"`
19+
Daemon DaemonConfig `mapstructure:"daemon"`
20+
Revert bool `mapstructure:"revert"`
21+
Tags TagsConfig `mapstructure:"tags"`
22+
Facts map[string]interface{} `mapstructure:"facts"`
23+
HostKeyChecking bool `mapstructure:"host_key_checking"`
24+
RolesPath string `mapstructure:"roles_path"` // Colon-delimited paths to search for roles
25+
Inventory string `mapstructure:"inventory"` // Colon-delimited paths to search for inventory files
26+
// Inventory plugins configuration (Ansible-like behaviour)
27+
// Colon-delimited paths to search for inventory plugins (e.g. "./plugins/inventory:/usr/share/ansible/plugins/inventory")
28+
InventoryPlugins string `mapstructure:"inventory_plugins"`
29+
// List of enabled plugin names/patterns (e.g. ["host_list", "script", "yaml", "monkeypatch_batch_strategy"])
30+
EnablePlugins []string `mapstructure:"enable_plugins"`
2631
PrivilegeEscalation PrivilegeEscalationConfig `mapstructure:"privilege_escalation"`
2732
SSH SSHConfig `mapstructure:"ssh"`
2833

@@ -302,6 +307,9 @@ func setDefaults(v *viper.Viper) {
302307

303308
// Inventory default
304309
v.SetDefault("inventory", "") // Default to empty, SDK will use default inventory
310+
// Inventory plugins defaults
311+
v.SetDefault("inventory_plugins", "")
312+
v.SetDefault("enable_plugins", []string{})
305313

306314
// PrivilegeEscalation defaults
307315
v.SetDefault("privilege_escalation.use_interactive", false) // Default to non-interactive (-u) for SSH sessions

pkg/config/config_test.go

Lines changed: 0 additions & 172 deletions
This file was deleted.

pkg/inventory.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,20 @@ func LoadInventoryWithPaths(path string, inventoryPaths string, workingDir strin
702702
"plugin": pluginName,
703703
})
704704

705-
// Load inventory via plugin
705+
// Hint plugin loader about the working directory of this inventory file
706+
if pluginConfig == nil {
707+
pluginConfig = make(map[string]interface{})
708+
}
709+
pluginConfig["__spage_cwd"] = filepath.Dir(filePath)
710+
// Pass through inventory plugin settings from spage config
711+
if cfg != nil {
712+
if cfg.InventoryPlugins != "" {
713+
pluginConfig["__spage_inventory_plugins"] = cfg.InventoryPlugins
714+
}
715+
if len(cfg.EnablePlugins) > 0 {
716+
pluginConfig["__spage_enable_plugins"] = cfg.EnablePlugins
717+
}
718+
}
706719
pluginInventory, err := pm.LoadInventoryFromPlugin(context.Background(), fmt.Sprintf("%v", pluginName), pluginConfig)
707720
if err != nil {
708721
return nil, fmt.Errorf("failed to load inventory from plugin %s: %w", pluginName, err)

0 commit comments

Comments
 (0)