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

Commit

Permalink
Allow environment to use jinja2 templating (#263)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea authored May 13, 2022
1 parent 60ce14c commit 000c4bb
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 60 deletions.
38 changes: 18 additions & 20 deletions f/ansible-playbook.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,7 @@
"type": "boolean"
},
"environment": {
"additionalProperties": {
"type": "string"
},
"title": "Environment",
"type": "object"
"$ref": "#/definitions/environment"
},
"ignore_errors": {
"$ref": "#/definitions/ignore_errors"
Expand Down Expand Up @@ -229,6 +225,20 @@
],
"type": "object"
},
"environment": {
"anyOf": [
{
"additionalProperties": {
"type": "string"
},
"type": "object"
},
{
"$ref": "#/definitions/full-jinja"
}
],
"title": "Environment"
},
"full-jinja": {
"pattern": "^\\{\\{.*\\}\\}$",
"type": "string"
Expand Down Expand Up @@ -298,11 +308,7 @@
"type": "boolean"
},
"environment": {
"additionalProperties": {
"type": "string"
},
"title": "Environment",
"type": "object"
"$ref": "#/definitions/environment"
},
"fact_path": {
"title": "Fact Path",
Expand Down Expand Up @@ -556,11 +562,7 @@
"type": "boolean"
},
"environment": {
"additionalProperties": {
"type": "string"
},
"title": "Environment",
"type": "object"
"$ref": "#/definitions/environment"
},
"ignore_errors": {
"$ref": "#/definitions/ignore_errors"
Expand Down Expand Up @@ -760,11 +762,7 @@
"type": "boolean"
},
"environment": {
"additionalProperties": {
"type": "string"
},
"title": "Environment",
"type": "object"
"$ref": "#/definitions/environment"
},
"failed_when": {
"title": "Failed When",
Expand Down
38 changes: 18 additions & 20 deletions f/ansible-tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,7 @@
"type": "boolean"
},
"environment": {
"additionalProperties": {
"type": "string"
},
"title": "Environment",
"type": "object"
"$ref": "#/definitions/environment"
},
"ignore_errors": {
"$ref": "#/definitions/ignore_errors"
Expand Down Expand Up @@ -229,6 +225,20 @@
],
"type": "object"
},
"environment": {
"anyOf": [
{
"additionalProperties": {
"type": "string"
},
"type": "object"
},
{
"$ref": "#/definitions/full-jinja"
}
],
"title": "Environment"
},
"full-jinja": {
"pattern": "^\\{\\{.*\\}\\}$",
"type": "string"
Expand Down Expand Up @@ -298,11 +308,7 @@
"type": "boolean"
},
"environment": {
"additionalProperties": {
"type": "string"
},
"title": "Environment",
"type": "object"
"$ref": "#/definitions/environment"
},
"fact_path": {
"title": "Fact Path",
Expand Down Expand Up @@ -556,11 +562,7 @@
"type": "boolean"
},
"environment": {
"additionalProperties": {
"type": "string"
},
"title": "Environment",
"type": "object"
"$ref": "#/definitions/environment"
},
"ignore_errors": {
"$ref": "#/definitions/ignore_errors"
Expand Down Expand Up @@ -760,11 +762,7 @@
"type": "boolean"
},
"environment": {
"additionalProperties": {
"type": "string"
},
"title": "Environment",
"type": "object"
"$ref": "#/definitions/environment"
},
"failed_when": {
"title": "Failed When",
Expand Down
38 changes: 18 additions & 20 deletions f/ansible.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,7 @@
"type": "boolean"
},
"environment": {
"additionalProperties": {
"type": "string"
},
"title": "Environment",
"type": "object"
"$ref": "#/definitions/environment"
},
"ignore_errors": {
"$ref": "#/definitions/ignore_errors"
Expand Down Expand Up @@ -225,6 +221,20 @@
"required": ["block"],
"type": "object"
},
"environment": {
"anyOf": [
{
"additionalProperties": {
"type": "string"
},
"type": "object"
},
{
"$ref": "#/definitions/full-jinja"
}
],
"title": "Environment"
},
"full-jinja": {
"pattern": "^\\{\\{.*\\}\\}$",
"type": "string"
Expand Down Expand Up @@ -292,11 +302,7 @@
"type": "boolean"
},
"environment": {
"additionalProperties": {
"type": "string"
},
"title": "Environment",
"type": "object"
"$ref": "#/definitions/environment"
},
"fact_path": {
"title": "Fact Path",
Expand Down Expand Up @@ -548,11 +554,7 @@
"type": "boolean"
},
"environment": {
"additionalProperties": {
"type": "string"
},
"title": "Environment",
"type": "object"
"$ref": "#/definitions/environment"
},
"ignore_errors": {
"$ref": "#/definitions/ignore_errors"
Expand Down Expand Up @@ -742,11 +744,7 @@
"type": "boolean"
},
"environment": {
"additionalProperties": {
"type": "string"
},
"title": "Environment",
"type": "object"
"$ref": "#/definitions/environment"
},
"failed_when": {
"title": "Failed When",
Expand Down
3 changes: 3 additions & 0 deletions negative_test/playbooks/environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
- hosts: localhost
environment: "{{ foo }}-123" # <- invalid only a full jinja string is allowed, or a list of strings
82 changes: 82 additions & 0 deletions negative_test/playbooks/environment.yml.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# 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/required"
},
{
"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": "environment"
},
"schemaPath": "#/definitions/ansible.builtin.import_playbook/additionalProperties"
},
{
"instancePath": "/0/environment",
"keyword": "type",
"message": "must be object",
"params": {
"type": "object"
},
"schemaPath": "#/anyOf/0/type"
},
{
"instancePath": "/0/environment",
"keyword": "pattern",
"message": "must match pattern \"^\\{\\{.*\\}\\}$\"",
"params": {
"pattern": "^\\{\\{.*\\}\\}$"
},
"schemaPath": "#/definitions/full-jinja/pattern"
},
{
"instancePath": "/0/environment",
"keyword": "anyOf",
"message": "must match a schema in anyOf",
"params": {},
"schemaPath": "#/anyOf"
},
{
"instancePath": "/0",
"keyword": "anyOf",
"message": "must match a schema in anyOf",
"params": {},
"schemaPath": "#/items/anyOf"
}
]
```

# check-jsonschema

stderr:

```
Schema validation errors were encountered.
```

stdout:

```
negative_test/playbooks/environment.yml::$[0]: {'hosts': 'localhost', 'environment': '{{ foo }}-123'} is not valid under any of the given schemas
Underlying errors caused this.
Best Match:
$[0]: Additional properties are not allowed ('environment', 'hosts' were unexpected)
```
7 changes: 7 additions & 0 deletions test/playbooks/environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- hosts: localhost
environment: # <- valid
FOO: BAR

- hosts: localhost
environment: "{{ foo }}" # <- valid

0 comments on commit 000c4bb

Please sign in to comment.