|
1 | 1 | package ansible |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "os" |
| 5 | + "path" |
| 6 | + |
4 | 7 | console "github.com/pluralsh/console-client-go" |
| 8 | + "github.com/samber/lo" |
| 9 | + "k8s.io/klog/v2" |
5 | 10 |
|
| 11 | + "github.com/pluralsh/deployment-operator/internal/helpers" |
6 | 12 | v1 "github.com/pluralsh/deployment-operator/pkg/harness/tool/v1" |
| 13 | + "github.com/pluralsh/deployment-operator/pkg/log" |
7 | 14 | ) |
8 | 15 |
|
| 16 | +// Plan implements [v1.Tool] interface. |
9 | 17 | func (in *Ansible) Plan() (*console.StackStateAttributes, error) { |
10 | | - // TODO implement me |
11 | | - panic("implement me") |
| 18 | + output, err := os.ReadFile(in.planFilePath) |
| 19 | + if err != nil { |
| 20 | + return nil, err |
| 21 | + } |
| 22 | + |
| 23 | + klog.V(log.LogLevelTrace).InfoS("ansible plan file read successfully", "file", in.planFilePath, "output", string(output)) |
| 24 | + return &console.StackStateAttributes{ |
| 25 | + Plan: lo.ToPtr(string(output)), |
| 26 | + }, nil |
12 | 27 | } |
13 | 28 |
|
14 | | -func (in *Ansible) State() (*console.StackStateAttributes, error) { |
15 | | - // TODO implement me |
16 | | - panic("implement me") |
17 | | -} |
| 29 | +// Modifier implements [v1.Tool] interface. |
| 30 | +func (in *Ansible) Modifier(stage console.StepStage) v1.Modifier { |
| 31 | + globalEnvModifier := NewGlobalEnvModifier(in.workDir) |
18 | 32 |
|
19 | | -func (in *Ansible) Output() ([]*console.StackOutputAttributes, error) { |
20 | | - // TODO implement me |
21 | | - panic("implement me") |
22 | | -} |
| 33 | + if stage == console.StepStagePlan { |
| 34 | + return v1.NewMultiModifier(NewPassthroughModifier(in.planFilePath), globalEnvModifier) |
| 35 | + } |
23 | 36 |
|
24 | | -func (in *Ansible) Modifier(stage console.StepStage) v1.Modifier { |
25 | | - // TODO implement me |
26 | | - panic("implement me") |
| 37 | + return globalEnvModifier |
27 | 38 | } |
28 | 39 |
|
29 | | -func (in *Ansible) ConfigureStateBackend(actor, deployToken string, urls *console.StackRunBaseFragment_StateUrls) error { |
30 | | - // TODO implement me |
31 | | - panic("implement me") |
| 40 | +func (in *Ansible) init() *Ansible { |
| 41 | + in.planFileName = "ansible.plan" |
| 42 | + in.planFilePath = path.Join(in.execDir, in.planFileName) |
| 43 | + helpers.EnsureFileOrDie(in.planFilePath) |
| 44 | + |
| 45 | + return in |
32 | 46 | } |
33 | 47 |
|
34 | | -func New(dir string) *Ansible { |
35 | | - return &Ansible{dir: dir} |
| 48 | +// New creates an Ansible structure that implements v1.Tool interface. |
| 49 | +func New(workDir, execDir string) *Ansible { |
| 50 | + return (&Ansible{workDir: workDir, execDir: execDir}).init() |
36 | 51 | } |
0 commit comments