RunPlaybookStream executes ansible-playbook and streams output lines when handler is provided.
( ctx context.Context, inventoryText, inventoryFormat string, opts PlaybookOptions, handler OutputLineHandler, )
| 217 | |
| 218 | // RunPlaybookStream executes ansible-playbook and streams output lines when handler is provided. |
| 219 | func (r *Runner) RunPlaybookStream( |
| 220 | ctx context.Context, |
| 221 | inventoryText, |
| 222 | inventoryFormat string, |
| 223 | opts PlaybookOptions, |
| 224 | handler OutputLineHandler, |
| 225 | ) CommandResult { |
| 226 | playbookPath := strings.TrimSpace(opts.PlaybookPath) |
| 227 | if playbookPath == "" { |
| 228 | return CommandResult{Err: fmt.Errorf("playbook path is required")} |
| 229 | } |
| 230 | |
| 231 | inventoryPath, cleanup, err := writeTempInventory(inventoryText, inventoryFormat) |
| 232 | if err != nil { |
| 233 | return CommandResult{Err: fmt.Errorf("create temp inventory: %w", err)} |
| 234 | } |
| 235 | defer cleanup() |
| 236 | |
| 237 | args := buildPlaybookArgs(inventoryPath, playbookPath, opts) |
| 238 | return runAnsiblePlaybookCommand(ctx, r.env, args, handler) |
| 239 | } |
| 240 | |
| 241 | func buildAdhocArgs(inventoryPath string, opts AdhocOptions) []string { |
| 242 | pattern := strings.TrimSpace(opts.Pattern) |
no test coverage detected