From 2f1a89a6cbdaefb45af605134648286e61bfba8f Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Sat, 4 May 2024 14:35:41 +0200 Subject: [PATCH] fix: fix static bin paths and required flags (#50) --- cmd/wp-ansible/flags.go | 2 ++ docs/data/data.yaml | 4 ++-- plugin/ansible.go | 8 ++++---- plugin/impl.go | 17 +---------------- 4 files changed, 9 insertions(+), 22 deletions(-) diff --git a/cmd/wp-ansible/flags.go b/cmd/wp-ansible/flags.go index 958b9d6..44b7eb1 100644 --- a/cmd/wp-ansible/flags.go +++ b/cmd/wp-ansible/flags.go @@ -28,6 +28,7 @@ func settingsFlags(settings *plugin.Settings, category string) []cli.Flag { Name: "inventory", Usage: "path to inventory file", EnvVars: []string{"PLUGIN_INVENTORY", "PLUGIN_INVENTORIES"}, + Required: true, Destination: &settings.Inventories, Category: category, }, @@ -35,6 +36,7 @@ func settingsFlags(settings *plugin.Settings, category string) []cli.Flag { Name: "playbook", Usage: "list of playbooks to apply", EnvVars: []string{"PLUGIN_PLAYBOOK", "PLUGIN_PLAYBOOKS"}, + Required: true, Destination: &settings.Playbooks, Category: category, }, diff --git a/docs/data/data.yaml b/docs/data/data.yaml index 8d30b9e..71a4668 100644 --- a/docs/data/data.yaml +++ b/docs/data/data.yaml @@ -76,7 +76,7 @@ properties: description: | Path to inventory file. type: list - required: false + required: true - name: limit description: | @@ -115,7 +115,7 @@ properties: description: | List of playbooks to apply. type: list - required: false + required: true - name: private_key description: | diff --git a/plugin/ansible.go b/plugin/ansible.go index fa3a2df..a5b56e7 100644 --- a/plugin/ansible.go +++ b/plugin/ansible.go @@ -18,10 +18,10 @@ const ( ansibleFolder = "/etc/ansible" ansibleConfig = "/etc/ansible/ansible.cfg" - pipBin = "/usr/bin/pip" - ansibleBin = "/usr/bin/ansible" - ansibleGalaxyBin = "/usr/bin/ansible-galaxy" - ansiblePlaybookBin = "/usr/bin/ansible-playbook" + pipBin = "/usr/local/bin/pip" + ansibleBin = "/usr/local/bin/ansible" + ansibleGalaxyBin = "/usr/local/bin/ansible-galaxy" + ansiblePlaybookBin = "/usr/local/bin/ansible-playbook" strictFilePerm = 0o600 ) diff --git a/plugin/impl.go b/plugin/impl.go index 008df04..b593583 100644 --- a/plugin/impl.go +++ b/plugin/impl.go @@ -2,7 +2,6 @@ package plugin import ( "context" - "errors" "fmt" "os" @@ -10,13 +9,7 @@ import ( "golang.org/x/sys/execabs" ) -var ( - ErrPluginPlaybookNotSet = errors.New("playbook is required") - ErrPluginInventoryNotSet = errors.New("inventory is required") -) - -//nolint:revive -func (p *Plugin) run(ctx context.Context) error { +func (p *Plugin) run(_ context.Context) error { if err := p.Validate(); err != nil { return fmt.Errorf("validation failed: %w", err) } @@ -30,14 +23,6 @@ func (p *Plugin) run(ctx context.Context) error { // Validate handles the settings validation of the plugin. func (p *Plugin) Validate() error { - if len(p.Settings.Playbooks.Value()) == 0 { - return ErrPluginPlaybookNotSet - } - - if len(p.Settings.Inventories.Value()) == 0 { - return ErrPluginInventoryNotSet - } - return nil }