mirror of
https://github.com/thegeeklab/wp-ansible.git
synced 2024-11-21 23:50:40 +00:00
chore: cleanup docs and use cmd trace from plugin lib (#9)
This commit is contained in:
parent
c92e1cebd0
commit
01711c9daa
@ -13,6 +13,7 @@ import (
|
|||||||
"github.com/thegeeklab/wp-ansible/plugin"
|
"github.com/thegeeklab/wp-ansible/plugin"
|
||||||
"github.com/thegeeklab/wp-plugin-go/docs"
|
"github.com/thegeeklab/wp-plugin-go/docs"
|
||||||
wp "github.com/thegeeklab/wp-plugin-go/plugin"
|
wp "github.com/thegeeklab/wp-plugin-go/plugin"
|
||||||
|
wp_template "github.com/thegeeklab/wp-plugin-go/template"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -43,7 +44,7 @@ func main() {
|
|||||||
func toYAML(app *cli.App) (string, error) {
|
func toYAML(app *cli.App) (string, error) {
|
||||||
var w bytes.Buffer
|
var w bytes.Buffer
|
||||||
|
|
||||||
yamlTmpl, err := template.New("docs").ParseFS(yamlTemplate, "templates/docs-data.yaml.tmpl")
|
yamlTmpl, err := template.New("docs").Funcs(wp_template.LoadFuncMap()).ParseFS(yamlTemplate, "templates/docs-data.yaml.tmpl")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(yamlTmpl)
|
fmt.Println(yamlTmpl)
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -68,7 +68,7 @@ func settingsFlags(settings *plugin.Settings, category string) []cli.Flag {
|
|||||||
},
|
},
|
||||||
&cli.StringSliceFlag{
|
&cli.StringSliceFlag{
|
||||||
Name: "extra-vars",
|
Name: "extra-vars",
|
||||||
Usage: "set additional variables as key=value",
|
Usage: "set additional variables as `key=value`",
|
||||||
EnvVars: []string{"PLUGIN_EXTRA_VARS", "ANSIBLE_EXTRA_VARS"},
|
EnvVars: []string{"PLUGIN_EXTRA_VARS", "ANSIBLE_EXTRA_VARS"},
|
||||||
Destination: &settings.ExtraVars,
|
Destination: &settings.ExtraVars,
|
||||||
Category: category,
|
Category: category,
|
||||||
@ -167,7 +167,7 @@ func settingsFlags(settings *plugin.Settings, category string) []cli.Flag {
|
|||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "private-key",
|
Name: "private-key",
|
||||||
Usage: "ssh private key used to authenticate the connection",
|
Usage: "SSH private key used to authenticate the connection",
|
||||||
EnvVars: []string{"PLUGIN_PRIVATE_KEY", "ANSIBLE_PRIVATE_KEY"},
|
EnvVars: []string{"PLUGIN_PRIVATE_KEY", "ANSIBLE_PRIVATE_KEY"},
|
||||||
Destination: &settings.PrivateKey,
|
Destination: &settings.PrivateKey,
|
||||||
Category: category,
|
Category: category,
|
||||||
@ -195,28 +195,28 @@ func settingsFlags(settings *plugin.Settings, category string) []cli.Flag {
|
|||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "ssh-common-args",
|
Name: "ssh-common-args",
|
||||||
Usage: "specify common arguments to pass to sftp,scp and ssh connections",
|
Usage: "specify common arguments to pass to SFTP, SCP and SSH connections",
|
||||||
EnvVars: []string{"PLUGIN_SSH_COMMON_ARGS"},
|
EnvVars: []string{"PLUGIN_SSH_COMMON_ARGS"},
|
||||||
Destination: &settings.SSHCommonArgs,
|
Destination: &settings.SSHCommonArgs,
|
||||||
Category: category,
|
Category: category,
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "sftp-extra-args",
|
Name: "sftp-extra-args",
|
||||||
Usage: "specify extra arguments to pass to sftp connections only",
|
Usage: "specify extra arguments to pass to SFTP connections only",
|
||||||
EnvVars: []string{"PLUGIN_SFTP_EXTRA_ARGS"},
|
EnvVars: []string{"PLUGIN_SFTP_EXTRA_ARGS"},
|
||||||
Destination: &settings.SFTPExtraArgs,
|
Destination: &settings.SFTPExtraArgs,
|
||||||
Category: category,
|
Category: category,
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "scp-extra-args",
|
Name: "scp-extra-args",
|
||||||
Usage: "specify extra arguments to pass to scp connections only",
|
Usage: "specify extra arguments to pass to SCP connections only",
|
||||||
EnvVars: []string{"PLUGIN_SCP_EXTRA_ARGS"},
|
EnvVars: []string{"PLUGIN_SCP_EXTRA_ARGS"},
|
||||||
Destination: &settings.SCPExtraArgs,
|
Destination: &settings.SCPExtraArgs,
|
||||||
Category: category,
|
Category: category,
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "ssh-extra-args",
|
Name: "ssh-extra-args",
|
||||||
Usage: "specify extra arguments to pass to ssh connections only",
|
Usage: "specify extra arguments to pass to SSH connections only",
|
||||||
EnvVars: []string{"PLUGIN_SSH_EXTRA_ARGS"},
|
EnvVars: []string{"PLUGIN_SSH_EXTRA_ARGS"},
|
||||||
Destination: &settings.SSHExtraArgs,
|
Destination: &settings.SSHExtraArgs,
|
||||||
Category: category,
|
Category: category,
|
||||||
|
@ -5,10 +5,14 @@ properties:
|
|||||||
- name: {{ $v.Name }}
|
- name: {{ $v.Name }}
|
||||||
{{- with $v.Description }}
|
{{- with $v.Description }}
|
||||||
description: |
|
description: |
|
||||||
{{ . }}
|
{{ . | ToSentence }}
|
||||||
|
{{- end }}
|
||||||
|
{{- with $v.Type }}
|
||||||
|
type: {{ . }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- with $v.Default }}
|
{{- with $v.Default }}
|
||||||
defaultvalue: {{ . }}
|
defaultvalue: {{ . }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
required: {{ default false $v.Required }}
|
||||||
{{ end -}}
|
{{ end -}}
|
||||||
{{ end -}}
|
{{ end -}}
|
||||||
|
@ -3,143 +3,209 @@ properties:
|
|||||||
- name: become
|
- name: become
|
||||||
description: |
|
description: |
|
||||||
Enable privilege escalation.
|
Enable privilege escalation.
|
||||||
|
type: bool
|
||||||
defaultvalue: false
|
defaultvalue: false
|
||||||
|
required: false
|
||||||
|
|
||||||
- name: become_method
|
- name: become_method
|
||||||
description: |
|
description: |
|
||||||
Privilege escalation method to use.
|
Privilege escalation method to use.
|
||||||
|
type: string
|
||||||
|
required: false
|
||||||
|
|
||||||
- name: become_user
|
- name: become_user
|
||||||
description: |
|
description: |
|
||||||
Privilege escalation user to use.
|
Privilege escalation user to use.
|
||||||
|
type: string
|
||||||
|
required: false
|
||||||
|
|
||||||
- name: check
|
- name: check
|
||||||
description: |
|
description: |
|
||||||
Run a check, do not apply any changes.
|
Run a check, do not apply any changes.
|
||||||
|
type: bool
|
||||||
defaultvalue: false
|
defaultvalue: false
|
||||||
|
required: false
|
||||||
|
|
||||||
- name: connection
|
- name: connection
|
||||||
description: |
|
description: |
|
||||||
Connection type to use.
|
Connection type to use.
|
||||||
|
type: string
|
||||||
|
required: false
|
||||||
|
|
||||||
- name: diff
|
- name: diff
|
||||||
description: |
|
description: |
|
||||||
Show the differences. Be careful when using it in public CI environments as it can print secrets.
|
Show the differences. Be careful when using it in public CI environments as it can print secrets.
|
||||||
|
type: bool
|
||||||
defaultvalue: false
|
defaultvalue: false
|
||||||
|
required: false
|
||||||
|
|
||||||
- name: extra_vars
|
- name: extra_vars
|
||||||
description: |
|
description: |
|
||||||
Set additional variables as `key=value`.
|
Set additional variables as `key=value`.
|
||||||
|
type: list
|
||||||
|
required: false
|
||||||
|
|
||||||
- name: flush_cache
|
- name: flush_cache
|
||||||
description: |
|
description: |
|
||||||
Clear the fact cache for every host in inventory.
|
Clear the fact cache for every host in inventory.
|
||||||
|
type: bool
|
||||||
defaultvalue: false
|
defaultvalue: false
|
||||||
|
required: false
|
||||||
|
|
||||||
- name: force_handlers
|
- name: force_handlers
|
||||||
description: |
|
description: |
|
||||||
Run handlers even if a task fails.
|
Run handlers even if a task fails.
|
||||||
|
type: bool
|
||||||
defaultvalue: false
|
defaultvalue: false
|
||||||
|
required: false
|
||||||
|
|
||||||
- name: forks
|
- name: forks
|
||||||
description: |
|
description: |
|
||||||
Specify number of parallel processes to use.
|
Specify number of parallel processes to use.
|
||||||
|
type: integer
|
||||||
defaultvalue: 5
|
defaultvalue: 5
|
||||||
|
required: false
|
||||||
|
|
||||||
- name: galaxy_requirements
|
- name: galaxy_requirements
|
||||||
description: |
|
description: |
|
||||||
Path to galaxy requirements file.
|
Path to galaxy requirements file.
|
||||||
|
type: string
|
||||||
|
required: false
|
||||||
|
|
||||||
- name: inventory
|
- name: inventory
|
||||||
description: |
|
description: |
|
||||||
Path to inventory file.
|
Path to inventory file.
|
||||||
|
type: list
|
||||||
|
required: false
|
||||||
|
|
||||||
- name: limit
|
- name: limit
|
||||||
description: |
|
description: |
|
||||||
Limit selected hosts to an additional pattern.
|
Limit selected hosts to an additional pattern.
|
||||||
|
type: string
|
||||||
|
required: false
|
||||||
|
|
||||||
- name: list_hosts
|
- name: list_hosts
|
||||||
description: |
|
description: |
|
||||||
Outputs a list of matching hosts.
|
Outputs a list of matching hosts.
|
||||||
|
type: bool
|
||||||
defaultvalue: false
|
defaultvalue: false
|
||||||
|
required: false
|
||||||
|
|
||||||
- name: list_tags
|
- name: list_tags
|
||||||
description: |
|
description: |
|
||||||
List all available tags.
|
List all available tags.
|
||||||
|
type: bool
|
||||||
defaultvalue: false
|
defaultvalue: false
|
||||||
|
required: false
|
||||||
|
|
||||||
- name: list_tasks
|
- name: list_tasks
|
||||||
description: |
|
description: |
|
||||||
List all tasks that would be executed.
|
List all tasks that would be executed.
|
||||||
|
type: bool
|
||||||
defaultvalue: false
|
defaultvalue: false
|
||||||
|
required: false
|
||||||
|
|
||||||
- name: module_path
|
- name: module_path
|
||||||
description: |
|
description: |
|
||||||
Prepend paths to module library.
|
Prepend paths to module library.
|
||||||
|
type: list
|
||||||
|
required: false
|
||||||
|
|
||||||
- name: playbook
|
- name: playbook
|
||||||
description: |
|
description: |
|
||||||
List of playbooks to apply.
|
List of playbooks to apply.
|
||||||
|
type: list
|
||||||
|
required: false
|
||||||
|
|
||||||
- name: private_key
|
- name: private_key
|
||||||
description: |
|
description: |
|
||||||
SSH private key used to authenticate the connection.
|
SSH private key used to authenticate the connection.
|
||||||
|
type: string
|
||||||
|
required: false
|
||||||
|
|
||||||
- name: python_requirements
|
- name: python_requirements
|
||||||
description: |
|
description: |
|
||||||
Path to python requirements file.
|
Path to python requirements file.
|
||||||
|
type: string
|
||||||
|
required: false
|
||||||
|
|
||||||
- name: scp_extra_args
|
- name: scp_extra_args
|
||||||
description: |
|
description: |
|
||||||
Specify extra arguments to pass to SCP connections only.
|
Specify extra arguments to pass to SCP connections only.
|
||||||
|
type: string
|
||||||
|
required: false
|
||||||
|
|
||||||
- name: sftp_extra_args
|
- name: sftp_extra_args
|
||||||
description: |
|
description: |
|
||||||
Specify extra arguments to pass to SFTP connections only.
|
Specify extra arguments to pass to SFTP connections only.
|
||||||
|
type: string
|
||||||
|
required: false
|
||||||
|
|
||||||
- name: skip_tags
|
- name: skip_tags
|
||||||
description: |
|
description: |
|
||||||
Only run plays and tasks whose tags do not match.
|
Only run plays and tasks whose tags do not match.
|
||||||
|
type: string
|
||||||
|
required: false
|
||||||
|
|
||||||
- name: ssh_common_args
|
- name: ssh_common_args
|
||||||
description: |
|
description: |
|
||||||
Specify common arguments to pass to SFTP, SCP and SSH connections.
|
Specify common arguments to pass to SFTP, SCP and SSH connections.
|
||||||
|
type: string
|
||||||
|
required: false
|
||||||
|
|
||||||
- name: ssh_extra_args
|
- name: ssh_extra_args
|
||||||
description: |
|
description: |
|
||||||
Specify extra arguments to pass to ssh connections only.
|
Specify extra arguments to pass to SSH connections only.
|
||||||
|
type: string
|
||||||
|
required: false
|
||||||
|
|
||||||
- name: start_at_task
|
- name: start_at_task
|
||||||
description: |
|
description: |
|
||||||
Start the playbook at the task matching this name.
|
Start the playbook at the task matching this name.
|
||||||
|
type: string
|
||||||
|
required: false
|
||||||
|
|
||||||
- name: syntax_check
|
- name: syntax_check
|
||||||
description: |
|
description: |
|
||||||
Perform a syntax check on the playbook.
|
Perform a syntax check on the playbook.
|
||||||
|
type: bool
|
||||||
defaultvalue: false
|
defaultvalue: false
|
||||||
|
required: false
|
||||||
|
|
||||||
- name: tags
|
- name: tags
|
||||||
description: |
|
description: |
|
||||||
Only run plays and tasks tagged with these values.
|
Only run plays and tasks tagged with these values.
|
||||||
|
type: string
|
||||||
|
required: false
|
||||||
|
|
||||||
- name: timeout
|
- name: timeout
|
||||||
description: |
|
description: |
|
||||||
Override the connection timeout in seconds.
|
Override the connection timeout in seconds.
|
||||||
|
type: integer
|
||||||
defaultvalue: 0
|
defaultvalue: 0
|
||||||
|
required: false
|
||||||
|
|
||||||
- name: user
|
- name: user
|
||||||
description: |
|
description: |
|
||||||
Connect as this user.
|
Connect as this user.
|
||||||
|
type: string
|
||||||
|
required: false
|
||||||
|
|
||||||
- name: vault_id
|
- name: vault_id
|
||||||
description: |
|
description: |
|
||||||
The vault identity to use.
|
The vault identity to use.
|
||||||
|
type: string
|
||||||
|
required: false
|
||||||
|
|
||||||
- name: vault_password
|
- name: vault_password
|
||||||
description: |
|
description: |
|
||||||
The vault password to use.
|
The vault password to use.
|
||||||
|
type: string
|
||||||
|
required: false
|
||||||
|
|
||||||
- name: verbose
|
- name: verbose
|
||||||
description: |
|
description: |
|
||||||
Level of verbosity, 0 up to 4.
|
Level of verbosity, 0 up to 4.
|
||||||
|
type: integer
|
||||||
defaultvalue: 0
|
defaultvalue: 0
|
||||||
|
required: false
|
||||||
|
@ -290,7 +290,3 @@ func (p *Plugin) ansibleCommand(inventory string) *execabs.Cmd {
|
|||||||
args...,
|
args...,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func trace(cmd *execabs.Cmd) {
|
|
||||||
fmt.Println("$", strings.Join(cmd.Args, " "))
|
|
||||||
}
|
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/thegeeklab/wp-plugin-go/trace"
|
||||||
"golang.org/x/sys/execabs"
|
"golang.org/x/sys/execabs"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -89,7 +90,7 @@ func (p *Plugin) Execute() error {
|
|||||||
cmd.Env = os.Environ()
|
cmd.Env = os.Environ()
|
||||||
cmd.Env = append(cmd.Env, "ANSIBLE_FORCE_COLOR=1")
|
cmd.Env = append(cmd.Env, "ANSIBLE_FORCE_COLOR=1")
|
||||||
|
|
||||||
trace(cmd)
|
trace.Cmd(cmd)
|
||||||
|
|
||||||
if err := cmd.Run(); err != nil {
|
if err := cmd.Run(); err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
Reference in New Issue
Block a user