Skip to content
This repository has been archived by the owner on Dec 2, 2022. It is now read-only.

Commit

Permalink
Allow run_once to use templated booleans (#270)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea authored May 14, 2022
1 parent 5b6c5f1 commit 7db4163
Show file tree
Hide file tree
Showing 7 changed files with 217 additions and 24 deletions.
16 changes: 8 additions & 8 deletions f/ansible-playbook.json
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@
"type": "array"
},
"run_once": {
"title": "Run Once",
"type": "boolean"
"$ref": "#/definitions/templated-boolean",
"title": "Run Once"
},
"tags": {
"anyOf": [
Expand Down Expand Up @@ -455,8 +455,8 @@
"type": "array"
},
"run_once": {
"title": "Run Once",
"type": "boolean"
"$ref": "#/definitions/templated-boolean",
"title": "Run Once"
},
"serial": {
"anyOf": [
Expand Down Expand Up @@ -640,8 +640,8 @@
"type": "string"
},
"run_once": {
"title": "Run Once",
"type": "boolean"
"$ref": "#/definitions/templated-boolean",
"title": "Run Once"
},
"tags": {
"anyOf": [
Expand Down Expand Up @@ -867,8 +867,8 @@
"type": "integer"
},
"run_once": {
"title": "Run Once",
"type": "boolean"
"$ref": "#/definitions/templated-boolean",
"title": "Run Once"
},
"tags": {
"anyOf": [
Expand Down
16 changes: 8 additions & 8 deletions f/ansible-tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@
"type": "array"
},
"run_once": {
"title": "Run Once",
"type": "boolean"
"$ref": "#/definitions/templated-boolean",
"title": "Run Once"
},
"tags": {
"anyOf": [
Expand Down Expand Up @@ -455,8 +455,8 @@
"type": "array"
},
"run_once": {
"title": "Run Once",
"type": "boolean"
"$ref": "#/definitions/templated-boolean",
"title": "Run Once"
},
"serial": {
"anyOf": [
Expand Down Expand Up @@ -640,8 +640,8 @@
"type": "string"
},
"run_once": {
"title": "Run Once",
"type": "boolean"
"$ref": "#/definitions/templated-boolean",
"title": "Run Once"
},
"tags": {
"anyOf": [
Expand Down Expand Up @@ -867,8 +867,8 @@
"type": "integer"
},
"run_once": {
"title": "Run Once",
"type": "boolean"
"$ref": "#/definitions/templated-boolean",
"title": "Run Once"
},
"tags": {
"anyOf": [
Expand Down
16 changes: 8 additions & 8 deletions f/ansible.json
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@
"type": "array"
},
"run_once": {
"title": "Run Once",
"type": "boolean"
"$ref": "#/definitions/templated-boolean",
"title": "Run Once"
},
"tags": {
"anyOf": [
Expand Down Expand Up @@ -441,8 +441,8 @@
"type": "array"
},
"run_once": {
"title": "Run Once",
"type": "boolean"
"$ref": "#/definitions/templated-boolean",
"title": "Run Once"
},
"serial": {
"anyOf": [
Expand Down Expand Up @@ -624,8 +624,8 @@
"type": "string"
},
"run_once": {
"title": "Run Once",
"type": "boolean"
"$ref": "#/definitions/templated-boolean",
"title": "Run Once"
},
"tags": {
"anyOf": [
Expand Down Expand Up @@ -838,8 +838,8 @@
"type": "integer"
},
"run_once": {
"title": "Run Once",
"type": "boolean"
"$ref": "#/definitions/templated-boolean",
"title": "Run Once"
},
"tags": {
"anyOf": [
Expand Down
8 changes: 8 additions & 0 deletions negative_test/playbooks/run_once_list.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
- hosts: localhost
tasks:
- name: foo2
ansible.builtin.debug:
msg: foo!
run_once: # invalid due to schema, also ansible does not allow lists
- "{{ true }}"
- xxx
170 changes: 170 additions & 0 deletions negative_test/playbooks/run_once_list.yml.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
# ajv errors

```json
[
{
"instancePath": "/0",
"keyword": "required",
"message": "must have required property 'ansible.builtin.import_playbook'",
"params": {
"missingProperty": "ansible.builtin.import_playbook"
},
"schemaPath": "#/definitions/ansible.builtin.import_playbook/oneOf/0/required"
},
{
"instancePath": "/0",
"keyword": "required",
"message": "must have required property 'import_playbook'",
"params": {
"missingProperty": "import_playbook"
},
"schemaPath": "#/definitions/ansible.builtin.import_playbook/oneOf/1/required"
},
{
"instancePath": "/0",
"keyword": "oneOf",
"message": "must match exactly one schema in oneOf",
"params": {
"passingSchemas": null
},
"schemaPath": "#/definitions/ansible.builtin.import_playbook/oneOf"
},
{
"instancePath": "/0",
"keyword": "additionalProperties",
"message": "must NOT have additional properties",
"params": {
"additionalProperty": "hosts"
},
"schemaPath": "#/definitions/ansible.builtin.import_playbook/additionalProperties"
},
{
"instancePath": "/0",
"keyword": "additionalProperties",
"message": "must NOT have additional properties",
"params": {
"additionalProperty": "tasks"
},
"schemaPath": "#/definitions/ansible.builtin.import_playbook/additionalProperties"
},
{
"instancePath": "/0/tasks/0/run_once",
"keyword": "type",
"message": "must be boolean",
"params": {
"type": "boolean"
},
"schemaPath": "#/oneOf/0/type"
},
{
"instancePath": "/0/tasks/0/run_once",
"keyword": "type",
"message": "must be string",
"params": {
"type": "string"
},
"schemaPath": "#/oneOf/1/type"
},
{
"instancePath": "/0/tasks/0/run_once",
"keyword": "type",
"message": "must be string",
"params": {
"type": "string"
},
"schemaPath": "#/definitions/full-jinja/type"
},
{
"instancePath": "/0/tasks/0/run_once",
"keyword": "oneOf",
"message": "must match exactly one schema in oneOf",
"params": {
"passingSchemas": null
},
"schemaPath": "#/oneOf"
},
{
"instancePath": "/0/tasks/0",
"keyword": "required",
"message": "must have required property 'block'",
"params": {
"missingProperty": "block"
},
"schemaPath": "#/required"
},
{
"instancePath": "/0/tasks/0/run_once",
"keyword": "type",
"message": "must be boolean",
"params": {
"type": "boolean"
},
"schemaPath": "#/oneOf/0/type"
},
{
"instancePath": "/0/tasks/0/run_once",
"keyword": "type",
"message": "must be string",
"params": {
"type": "string"
},
"schemaPath": "#/oneOf/1/type"
},
{
"instancePath": "/0/tasks/0/run_once",
"keyword": "type",
"message": "must be string",
"params": {
"type": "string"
},
"schemaPath": "#/definitions/full-jinja/type"
},
{
"instancePath": "/0/tasks/0/run_once",
"keyword": "oneOf",
"message": "must match exactly one schema in oneOf",
"params": {
"passingSchemas": null
},
"schemaPath": "#/oneOf"
},
{
"instancePath": "/0/tasks/0",
"keyword": "anyOf",
"message": "must match a schema in anyOf",
"params": {},
"schemaPath": "#/items/anyOf"
},
{
"instancePath": "/0",
"keyword": "oneOf",
"message": "must match exactly one schema in oneOf",
"params": {
"passingSchemas": null
},
"schemaPath": "#/items/oneOf"
}
]
```

# check-jsonschema

stdout:

```json
{
"status": "fail",
"errors": [
{
"filename": "negative_test/playbooks/run_once_list.yml",
"path": "$[0]",
"message": "{'hosts': 'localhost', 'tasks': [{'name': 'foo2', 'ansible.builtin.debug': {'msg': 'foo!'}, 'run_once': ['{{ true }}', 'xxx']}]} is not valid under any of the given schemas",
"has_sub_errors": true,
"best_match": {
"path": "$[0]",
"message": "'hosts', 'tasks' do not match any of the regexes: '^(ansible\\\\.builtin\\\\.)?import_playbook$', 'name', 'vars'"
}
}
]
}
```
6 changes: 6 additions & 0 deletions test/playbooks/run_once.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- hosts: localhost
tasks:
- name: foo2
ansible.builtin.debug:
msg: foo!
run_once: "{{ true }}" # valid
9 changes: 9 additions & 0 deletions test/playbooks/tasks/run_once.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
- name: foo
ansible.builtin.debug:
msg: foo!
run_once: true # valid

- name: foo2
ansible.builtin.debug:
msg: foo!
run_once: "{{ true }}" # valid

0 comments on commit 7db4163

Please sign in to comment.