* The Debug module provides debugging capabilities by printing variable values and messages. This module allows users to inspect variable values and debug playbook execution. Configuration: Users can specify either a message or a variable path to debug. debug: msg: "message" #
(_ context.Context, opts internal.ExecOptions)
| 85 | |
| 86 | // ModuleDebug handles the "debug" module, printing debug information |
| 87 | func ModuleDebug(_ context.Context, opts internal.ExecOptions) (string, string, error) { |
| 88 | // get host variable |
| 89 | ha, err := opts.GetAllVariables() |
| 90 | if err != nil { |
| 91 | return internal.StdoutFailed, internal.StderrGetHostVariable, err |
| 92 | } |
| 93 | args := variable.Extension2Variables(opts.Args) |
| 94 | |
| 95 | // Handle "var" field - for getting variable values |
| 96 | if v, ok := args["var"]; ok { |
| 97 | return handleVarField(v, ha, opts.LogOutput) |
| 98 | } |
| 99 | |
| 100 | // Handle "msg" field - for printing messages with template support |
| 101 | if v, ok := args["msg"]; ok { |
| 102 | return handleMsgField(v, ha, opts.LogOutput) |
| 103 | } |
| 104 | |
| 105 | return internal.StdoutFailed, internal.StderrUnsupportArgs, errors.New("either \"msg\" or \"var\" must be specified") |
| 106 | } |
| 107 | |
| 108 | // handleVarField handles the "var" field for variable debugging |
| 109 | // Supports both template syntax "{{ .var }}" and simple path ".var" |