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 Jan 2, 2025
1 parent 6aafc22 commit 0006c01
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,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 @@ -78,6 +78,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
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,11 @@ spec:
- ansible-runner
- run
- /runner
- -p
- playbook.yaml
- -r
- test role
- -i
- custom-img-svc-edpm-compute-no-nodes-edpm-no-nodes-custom-svc
env:
- name: RUNNER_PLAYBOOK
value: |2+
playbook.yaml
- name: RUNNER_EXTRA_VARS
value: |2+
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,7 @@ metadata:
name: custom-img-svc
spec:
openStackAnsibleEERunnerImage: example.com/repo/runner-image:latest
role:
name: "test role"
hosts: "all"
strategy: "linear"
tasks:
- name: "test task"
import_role:
name: "test role"
role: "test role"
---
apiVersion: dataplane.openstack.org/v1beta1
kind: OpenStackDataPlaneNodeSet
Expand Down

0 comments on commit 0006c01

Please sign in to comment.