Skip to content
This repository was archived by the owner on Nov 28, 2024. It is now read-only.

Commit 33d3331

Browse files
committed
Don't require in-line Play text to start with list
This change removes the webhook validation requirement that in-line plays need to be lists. A play in Ansible is a dict, while a playbook is a list of plays. This change ensures we validate on the play format to conform with the terminology in use. For reference, see: https://github.com/ansible/ansible/blob/10f9b8e6554e024e3561170153b8e7fde5e7e4fb/test/units/playbook/test_play.py#L48 Given the terminology we use in the OpenStackDataPlaneService of 'play', we should then validate on the Ansible defined 'play' format, rather than a 'playbook' format. Signed-off-by: Brendan Shephard <[email protected]>
1 parent 75d516d commit 33d3331

File tree

15 files changed

+34
-37
lines changed

15 files changed

+34
-37
lines changed

api/v1beta1/openstackansibleee_webhook.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ func (spec *OpenStackAnsibleEESpec) ValidateCreate() field.ErrorList {
145145
))
146146
}
147147
}
148-
149148
}
150149

151150
for _, value := range spec.Env {
@@ -180,7 +179,7 @@ func (r *OpenStackAnsibleEE) ValidateDelete() (admission.Warnings, error) {
180179
// isPlay checks if the free form document has attributes of ansible play
181180
// Specifically if it is a parsable yaml with list as a root element
182181
func isPlay(document validator.FieldLevel) bool {
183-
var play []map[string]interface{}
182+
var play map[string]interface{}
184183
err := yaml.Unmarshal([]byte(document.Field().String()), &play)
185184
return err == nil
186185
}

examples/openstack-ansibleee-play-runner-extra-vars.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ metadata:
66
spec:
77
image: quay.io/openstack-k8s-operators/openstack-ansibleee-runner:latest
88
play: |
9-
- name: Print hello world
9+
name: Print hello world
1010
hosts: all
1111
tasks:
1212
- name: Using debug statement

examples/openstack-ansibleee-play.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ metadata:
66
spec:
77
image: quay.io/openstack-k8s-operators/openstack-ansibleee-runner:latest
88
play: |
9-
- name: Print hello world
9+
name: Print hello world
1010
hosts: all
1111
tasks:
1212
- name: Using debug statement

examples/openstack-ansibleee-playbook-local.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ metadata:
55
namespace: openstack
66
spec:
77
play: |
8-
- name: Print hello world
8+
name: Print hello world
99
hosts: all
1010
tasks:
1111
- name: Using debug statement

tests/functional/base_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
const (
2929
// This constant must NOT use tabs, as it as raw string passed to the ansible-runner
3030
play = `
31-
- name: Print hello world
31+
name: Print hello world
3232
hosts: all
3333
tasks:
3434
- name: Using debug statement
@@ -77,8 +77,8 @@ func CreateAnsibleee(name types.NamespacedName) client.Object {
7777

7878
func CreateAnsibleeeWithParams(
7979
name types.NamespacedName, playbook string, image string, play string,
80-
cmdline string, extraVars map[string]interface{}, extraMounts []map[string]interface{}) client.Object {
81-
80+
cmdline string, extraVars map[string]interface{}, extraMounts []map[string]interface{},
81+
) client.Object {
8282
raw := map[string]interface{}{
8383
"apiVersion": "ansibleee.openstack.org/v1beta1",
8484
"kind": "OpenStackAnsibleEE",

tests/kuttl/tests/run_failed_playbook/01-assert.yaml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ metadata:
1313
spec:
1414
name: openstackansibleee
1515
play: |
16-
- name: Execution failure
17-
hosts: localhost
18-
tasks:
19-
- name: Copy absent file
20-
ansible.builtin.shell: |
21-
set -euxo pipefail
22-
cp absent failed_op
16+
name: Execution failure
17+
hosts: localhost
18+
tasks:
19+
- name: Copy absent file
20+
ansible.builtin.shell: |
21+
set -euxo pipefail
22+
cp absent failed_op
2323
preserveJobs: true
2424
status:
2525
JobStatus: Failed
@@ -83,13 +83,13 @@ spec:
8383
- name: RUNNER_PLAYBOOK
8484
value: |2+
8585
86-
- name: Execution failure
87-
hosts: localhost
88-
tasks:
89-
- name: Copy absent file
90-
ansible.builtin.shell: |
91-
set -euxo pipefail
92-
cp absent failed_op
86+
name: Execution failure
87+
hosts: localhost
88+
tasks:
89+
- name: Copy absent file
90+
ansible.builtin.shell: |
91+
set -euxo pipefail
92+
cp absent failed_op
9393
9494
9595
- name: RUNNER_EXTRA_VARS

tests/kuttl/tests/run_failed_playbook/01-run-absent-file.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ metadata:
44
name: failed-play
55
spec:
66
play: |
7-
- name: Execution failure
8-
hosts: localhost
9-
tasks:
10-
- name: Copy absent file
11-
ansible.builtin.shell: |
12-
set -euxo pipefail
13-
cp absent failed_op
7+
name: Execution failure
8+
hosts: localhost
9+
tasks:
10+
- name: Copy absent file
11+
ansible.builtin.shell: |
12+
set -euxo pipefail
13+
cp absent failed_op
1414
extraVars:
1515
aaa: 1
1616
ccc: 3

tests/kuttl/tests/run_simple_playbook/01-assert.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ metadata:
1313
spec:
1414
name: openstackansibleee
1515
play: |
16-
- name: Print hello world
16+
name: Print hello world
1717
hosts: localhost
1818
tasks:
1919
- name: Using debug statement

tests/kuttl/tests/run_simple_playbook/01-run-hello-world.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ metadata:
44
name: ansibleee-play
55
spec:
66
play: |
7-
- name: Print hello world
7+
name: Print hello world
88
hosts: localhost
99
tasks:
1010
- name: Using debug statement

tests/kuttl/tests/run_simple_playbook_debug/01-assert.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ metadata:
1313
spec:
1414
name: openstackansibleee
1515
play: |
16-
- name: Print hello world
16+
name: Print hello world
1717
hosts: localhost
1818
tasks:
1919
- name: Using debug statement

tests/kuttl/tests/run_simple_playbook_debug/01-run-debug.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ metadata:
44
name: ansibleee-play-debug
55
spec:
66
play: |
7-
- name: Print hello world
7+
name: Print hello world
88
hosts: localhost
99
tasks:
1010
- name: Using debug statement

tests/kuttl/tests/run_simple_playbook_debug_cmdline/01-assert.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ metadata:
1313
spec:
1414
name: openstackansibleee
1515
play: |
16-
- name: Print hello world
16+
name: Print hello world
1717
hosts: localhost
1818
tasks:
1919
- name: Using debug statement

tests/kuttl/tests/run_simple_playbook_debug_cmdline/01-run-debug.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ metadata:
44
name: ansibleee-play-debug
55
spec:
66
play: |
7-
- name: Print hello world
7+
name: Print hello world
88
hosts: localhost
99
tasks:
1010
- name: Using debug statement

tests/kuttl/tests/run_simple_playbook_extra_vars/01-assert.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ metadata:
1313
spec:
1414
name: openstackansibleee
1515
play: |
16-
- name: Print hello world
1716
hosts: localhost
1817
tasks:
1918
- name: Using debug statement

tests/kuttl/tests/run_simple_playbook_extra_vars/01-run-extra-vars.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ metadata:
44
name: ansibleee-play-extravars
55
spec:
66
play: |
7-
- name: Print hello world
87
hosts: localhost
98
tasks:
109
- name: Using debug statement

0 commit comments

Comments
 (0)