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

Commit

Permalink
Allow use of templated booleans for become (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea authored May 13, 2022
1 parent d2c176b commit 60ce14c
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 24 deletions.
1 change: 1 addition & 0 deletions .config/dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ fbca
fcba
fileglob
filetree
firewalld
geerlingguy
goss
groupname
Expand Down
16 changes: 8 additions & 8 deletions f/ansible-playbook.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@
"type": "boolean"
},
"become": {
"title": "Become",
"type": "boolean"
"$ref": "#/definitions/templated-boolean",
"title": "Become"
},
"become_exe": {
"title": "Become Exe",
Expand Down Expand Up @@ -256,8 +256,8 @@
"type": "boolean"
},
"become": {
"title": "Become",
"type": "boolean"
"$ref": "#/definitions/templated-boolean",
"title": "Become"
},
"become_exe": {
"title": "Become Exe",
Expand Down Expand Up @@ -510,8 +510,8 @@
"type": "boolean"
},
"become": {
"title": "Become",
"type": "boolean"
"$ref": "#/definitions/templated-boolean",
"title": "Become"
},
"become_exe": {
"title": "Become Exe",
Expand Down Expand Up @@ -685,8 +685,8 @@
"type": "integer"
},
"become": {
"title": "Become",
"type": "boolean"
"$ref": "#/definitions/templated-boolean",
"title": "Become"
},
"become_exe": {
"title": "Become Exe",
Expand Down
16 changes: 8 additions & 8 deletions f/ansible-tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@
"type": "boolean"
},
"become": {
"title": "Become",
"type": "boolean"
"$ref": "#/definitions/templated-boolean",
"title": "Become"
},
"become_exe": {
"title": "Become Exe",
Expand Down Expand Up @@ -256,8 +256,8 @@
"type": "boolean"
},
"become": {
"title": "Become",
"type": "boolean"
"$ref": "#/definitions/templated-boolean",
"title": "Become"
},
"become_exe": {
"title": "Become Exe",
Expand Down Expand Up @@ -510,8 +510,8 @@
"type": "boolean"
},
"become": {
"title": "Become",
"type": "boolean"
"$ref": "#/definitions/templated-boolean",
"title": "Become"
},
"become_exe": {
"title": "Become Exe",
Expand Down Expand Up @@ -685,8 +685,8 @@
"type": "integer"
},
"become": {
"title": "Become",
"type": "boolean"
"$ref": "#/definitions/templated-boolean",
"title": "Become"
},
"become_exe": {
"title": "Become Exe",
Expand Down
16 changes: 8 additions & 8 deletions f/ansible.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@
"type": "boolean"
},
"become": {
"title": "Become",
"type": "boolean"
"$ref": "#/definitions/templated-boolean",
"title": "Become"
},
"become_exe": {
"title": "Become Exe",
Expand Down Expand Up @@ -250,8 +250,8 @@
"type": "boolean"
},
"become": {
"title": "Become",
"type": "boolean"
"$ref": "#/definitions/templated-boolean",
"title": "Become"
},
"become_exe": {
"title": "Become Exe",
Expand Down Expand Up @@ -502,8 +502,8 @@
"type": "boolean"
},
"become": {
"title": "Become",
"type": "boolean"
"$ref": "#/definitions/templated-boolean",
"title": "Become"
},
"become_exe": {
"title": "Become Exe",
Expand Down Expand Up @@ -670,8 +670,8 @@
"type": "integer"
},
"become": {
"title": "Become",
"type": "boolean"
"$ref": "#/definitions/templated-boolean",
"title": "Become"
},
"become_exe": {
"title": "Become Exe",
Expand Down
3 changes: 3 additions & 0 deletions negative_test/playbooks/invalid_become.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
- hosts: localhost
become: yes # <- invalid based on json schema
84 changes: 84 additions & 0 deletions negative_test/playbooks/invalid_become.yml.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# 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": "become"
},
"schemaPath": "#/definitions/ansible.builtin.import_playbook/additionalProperties"
},
{
"instancePath": "/0/become",
"keyword": "type",
"message": "must be boolean",
"params": {
"type": "boolean"
},
"schemaPath": "#/oneOf/0/type"
},
{
"instancePath": "/0/become",
"keyword": "pattern",
"message": "must match pattern \"^\\{\\{.*\\}\\}$\"",
"params": {
"pattern": "^\\{\\{.*\\}\\}$"
},
"schemaPath": "#/definitions/full-jinja/pattern"
},
{
"instancePath": "/0/become",
"keyword": "oneOf",
"message": "must match exactly one schema in oneOf",
"params": {
"passingSchemas": null
},
"schemaPath": "#/oneOf"
},
{
"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/invalid_become.yml::$[0]: {'hosts': 'localhost', 'become': 'yes'} is not valid under any of the given schemas
Underlying errors caused this.
Best Match:
$[0]: Additional properties are not allowed ('become', 'hosts' were unexpected)
```
12 changes: 12 additions & 0 deletions test/playbooks/tasks/templated_become.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
- name: foo
ansible.builtin.debug:
msg: foo!
become: "{{ firewalld_become }}" # <- valid

- name: foo block
become: "{{ firewalld_become }}" # <- valid
block:
- name: foo
ansible.builtin.debug:
msg: foo!
become: "{{ firewalld_become }}" # <- valid
16 changes: 16 additions & 0 deletions test/playbooks/templated_become.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
- hosts: localhost
become: "{{ firewalld_become }}" # <- valid
tasks:
- name: foo
ansible.builtin.debug:
msg: foo!
become: "{{ firewalld_become }}" # <- valid

- name: foo block
become: "{{ firewalld_become }}" # <- valid
block:
- name: foo
ansible.builtin.debug:
msg: foo!
become: "{{ firewalld_become }}" # <- valid
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ description = Run tests
deps =
-r requirements.txt
commands =
python src/update-schemas.py
npm run test

[testenv:deps]
Expand Down

0 comments on commit 60ce14c

Please sign in to comment.