* The Command module executes shell commands on remote hosts and returns their output. This module allows users to run arbitrary shell commands and capture their output. Configuration: Users can specify the command to execute: command: "ls -l" # The shell command to execute Usage Examples in P
(ctx context.Context, opts internal.ExecOptions)
| 61 | |
| 62 | // ModuleCommand handles the "command" module, executing shell commands on remote hosts |
| 63 | func ModuleCommand(ctx context.Context, opts internal.ExecOptions) (string, string, error) { |
| 64 | // get host variable |
| 65 | ha, err := opts.GetAllVariables() |
| 66 | if err != nil { |
| 67 | return internal.StdoutFailed, internal.StderrGetHostVariable, err |
| 68 | } |
| 69 | // get connector |
| 70 | conn, err := opts.GetConnector(ctx) |
| 71 | if err != nil { |
| 72 | return internal.StdoutFailed, internal.StderrGetConnector, err |
| 73 | } |
| 74 | defer conn.Close(ctx) |
| 75 | // command string |
| 76 | command, err := variable.Extension2String(ha, opts.Args) |
| 77 | if err != nil { |
| 78 | return internal.StdoutFailed, internal.StderrParseArgument, err |
| 79 | } |
| 80 | // execute command |
| 81 | stdout, stderr, err := conn.ExecuteCommand(ctx, string(command)) |
| 82 | return string(stdout), string(stderr), err |
| 83 | } |
nothing calls this directly
no test coverage detected