Skip to content

Commit

Permalink
Support Roles on OpenStackDataPlaneService
Browse files Browse the repository at this point in the history
Additionally to playbooks, it enables running roles directly with ansible-runner

closes OSPRH-12358

Signed-off-by: Fabricio Aguiar <[email protected]>
  • Loading branch information
fao89 committed Dec 10, 2024
1 parent 559ee7c commit 9eb5ce6
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ spec:
type: string
playbookContents:
type: string
role:
type: string
tlsCerts:
additionalProperties:
properties:
Expand Down
3 changes: 3 additions & 0 deletions apis/dataplane/v1beta1/openstackdataplaneservice_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ type OpenStackDataPlaneServiceSpec struct {
// Playbook is a path to the playbook that ansible will run on this execution
Playbook string `json:"playbook,omitempty"`

// Role is a path to the role that ansible will run on this execution
Role string `json:"role,omitempty"`

// CACerts - Secret containing the CA certificate chain
// +kubebuilder:validation:Optional
// +kubebuilder:validation:MaxLength:=253
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ spec:
type: string
playbookContents:
type: string
role:
type: string
tlsCerts:
additionalProperties:
properties:
Expand Down
3 changes: 3 additions & 0 deletions pkg/dataplane/util/ansible_execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ func (a *EEJob) BuildAeeJobSpec(
if len(service.Spec.Playbook) > 0 {
a.Playbook = service.Spec.Playbook
}
if len(service.Spec.Role) > 0 {
a.Role = service.Spec.Role
}

a.BackoffLimit = deployment.Spec.BackoffLimit
a.PreserveJobs = deployment.Spec.PreserveJobs
Expand Down
19 changes: 13 additions & 6 deletions pkg/dataplane/util/ansibleee.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ type EEJob struct {
PlaybookContents string `json:"playbookContents,omitempty"`
// Playbook is the playbook that ansible will run on this execution, accepts path or FQN from collection
Playbook string `json:"playbook,omitempty"`
// Role is the role that ansible will run on this execution, accepts path or FQN from collection
Role string `json:"role,omitempty"`
// Image is the container image that will execute the ansible command
Image string `json:"image,omitempty"`
// Name is the name of the execution job
Expand Down Expand Up @@ -78,12 +80,17 @@ func (a *EEJob) JobForOpenStackAnsibleEE(h *helper.Helper) (*batchv1.Job, error)

args := a.Args

playbook := a.Playbook
artifact := a.Playbook
param := "-p"
if len(args) == 0 {
if len(playbook) == 0 {
playbook = CustomPlaybook
if len(a.PlaybookContents) > 0 {
artifact = CustomPlaybook
}
args = []string{"ansible-runner", "run", "/runner", "-p", playbook}
if len(a.Role) > 0 {
artifact = a.Role
param = "-r"
}
args = []string{"ansible-runner", "run", "/runner", param, artifact}
}

// ansible runner identifier
Expand Down Expand Up @@ -171,10 +178,10 @@ func (a *EEJob) JobForOpenStackAnsibleEE(h *helper.Helper) (*batchv1.Job, error)

if len(a.PlaybookContents) > 0 {
setRunnerEnvVar(h, "RUNNER_PLAYBOOK", a.PlaybookContents, "playbookContents", job, hashes)
} else if len(playbook) > 0 {
} else if len(a.Playbook) > 0 {
// As we set "playbook.yaml" as default
// we need to ensure that PlaybookContents is empty before adding playbook
setRunnerEnvVar(h, "RUNNER_PLAYBOOK", playbook, "playbooks", job, hashes)
setRunnerEnvVar(h, "RUNNER_PLAYBOOK", a.Playbook, "playbooks", job, hashes)
}

if len(a.CmdLine) > 0 {
Expand Down

0 comments on commit 9eb5ce6

Please sign in to comment.