diff --git a/apis/bases/dataplane.openstack.org_openstackdataplaneservices.yaml b/apis/bases/dataplane.openstack.org_openstackdataplaneservices.yaml index f4eb7e6ca..6b11a8309 100644 --- a/apis/bases/dataplane.openstack.org_openstackdataplaneservices.yaml +++ b/apis/bases/dataplane.openstack.org_openstackdataplaneservices.yaml @@ -79,6 +79,8 @@ spec: type: string playbookContents: type: string + role: + type: string tlsCerts: additionalProperties: properties: diff --git a/apis/dataplane/v1beta1/openstackdataplaneservice_types.go b/apis/dataplane/v1beta1/openstackdataplaneservice_types.go index 475446b37..8c90a9776 100644 --- a/apis/dataplane/v1beta1/openstackdataplaneservice_types.go +++ b/apis/dataplane/v1beta1/openstackdataplaneservice_types.go @@ -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 diff --git a/config/crd/bases/dataplane.openstack.org_openstackdataplaneservices.yaml b/config/crd/bases/dataplane.openstack.org_openstackdataplaneservices.yaml index f4eb7e6ca..6b11a8309 100644 --- a/config/crd/bases/dataplane.openstack.org_openstackdataplaneservices.yaml +++ b/config/crd/bases/dataplane.openstack.org_openstackdataplaneservices.yaml @@ -79,6 +79,8 @@ spec: type: string playbookContents: type: string + role: + type: string tlsCerts: additionalProperties: properties: diff --git a/pkg/dataplane/util/ansible_execution.go b/pkg/dataplane/util/ansible_execution.go index e86b6d6d7..fb79174c8 100644 --- a/pkg/dataplane/util/ansible_execution.go +++ b/pkg/dataplane/util/ansible_execution.go @@ -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 diff --git a/pkg/dataplane/util/ansibleee.go b/pkg/dataplane/util/ansibleee.go index 0dff7b072..669a807bf 100644 --- a/pkg/dataplane/util/ansibleee.go +++ b/pkg/dataplane/util/ansibleee.go @@ -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 @@ -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 @@ -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 {