* Module Setup This module is used to set up the connection to a remote host and gather facts about it. It performs the following operations: 1. Establishes a connection to the specified host using the appropriate connector 2. If the connector supports fact gathering (implements GatherFacts interfa
(ctx context.Context, opts internal.ExecOptions)
| 28 | // ModuleSetup establishes a connection to a remote host and gathers facts about it. |
| 29 | // It returns StdoutSuccess if successful, or an error message if any step fails. |
| 30 | func ModuleSetup(ctx context.Context, opts internal.ExecOptions) (string, string, error) { |
| 31 | ha, err := opts.GetAllVariables() |
| 32 | if err != nil { |
| 33 | return internal.StdoutFailed, internal.StderrGetHostVariable, err |
| 34 | } |
| 35 | args := variable.Extension2Variables(opts.Args) |
| 36 | if force, err := variable.BoolVar(ha, args, "force"); err == nil && *force { |
| 37 | ctx = context.WithValue(ctx, _const.CTXSetupForceKey, true) |
| 38 | } |
| 39 | // get connector |
| 40 | conn, err := opts.GetConnector(ctx) |
| 41 | if err != nil { |
| 42 | return internal.StdoutFailed, internal.StderrGetConnector, nil |
| 43 | } |
| 44 | defer conn.Close(ctx) |
| 45 | |
| 46 | if gf, ok := conn.(connector.GatherFacts); ok { |
| 47 | remoteInfo, err := gf.HostInfo(ctx) |
| 48 | if err != nil { |
| 49 | return internal.StdoutFailed, "failed to get host info", err |
| 50 | } |
| 51 | if err := opts.Merge(variable.MergeRemoteVariable(remoteInfo, opts.Host)); err != nil { |
| 52 | return internal.StdoutFailed, "failed to merge setup variable", err |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | return internal.StdoutSuccess, "", nil |
| 57 | } |
nothing calls this directly
no test coverage detected