Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Roles on OpenStackDataPlaneService #1227

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading