I know that the vscode-yaml extension is using schemastore to determine validation syntax but I hoping a solution can occur at this level.
I have been getting really annoying "incorrect type" errors in my Ansible roles when using Jinja placeholders. Here's an example:
---
# Adds an additional disk to a linux system
# Requires the disk to exist first
- name: Create a filesystem
filesystem:
dev: "{{add_disk_device_id}}"
fstype: "{{add_disk_filesystem}}"
force: "{{add_disk_force}}"
opts: "{{add_disk_create_opts}}"
resizefs: "{{add_disk_resize}}"
become: yes
when: linux_add_disk == true
- name: Mount disk
mount:
backup: yes
src: "{{add_disk_device_id}}"
path: "{{add_disk_mount_path}}"
fstype: "{{add_disk_filesystem}}"
opts: "{{add_disk_mount_opts}}"
state: "{{add_disk_mount_state}}"
become: yes
when: linux_add_disk == true
That file throws the following errors:
{
"resource": "/Users/shadow/dev/repos/linux-mac-base/ansible/roles/fileshare/tasks/add_disk.yml",
"owner": "generated_diagnostic_collection_name#0",
"code": "1",
"severity": 8,
"message": "Value is not accepted. Valid values: "btrfs", "ext2", "ext3", "ext4", "ext4dev", "f2fs", "lvm", "ocfs2", "reiserfs", "xfs", "vfat", "swap".",
"startLineNumber": 8,
"startColumn": 13,
"endLineNumber": 8,
"endColumn": 38
}
{
"resource": "/Users/shadow/dev/repos/linux-mac-base/ansible/roles/fileshare/tasks/add_disk.yml",
"owner": "generated_diagnostic_collection_name#0",
"severity": 8,
"message": "Incorrect type. Expected "boolean".",
"startLineNumber": 9,
"startColumn": 12,
"endLineNumber": 9,
"endColumn": 32
}
{
"resource": "/Users/shadow/dev/repos/linux-mac-base/ansible/roles/fileshare/tasks/add_disk.yml",
"owner": "generated_diagnostic_collection_name#0",
"severity": 8,
"message": "Incorrect type. Expected "array".",
"startLineNumber": 10,
"startColumn": 11,
"endLineNumber": 10,
"endColumn": 37
}
{
"resource": "/Users/shadow/dev/repos/linux-mac-base/ansible/roles/fileshare/tasks/add_disk.yml",
"owner": "generated_diagnostic_collection_name#0",
"severity": 8,
"message": "Incorrect type. Expected "boolean".",
"startLineNumber": 11,
"startColumn": 15,
"endLineNumber": 11,
"endColumn": 36
}
{
"resource": "/Users/shadow/dev/repos/linux-mac-base/ansible/roles/fileshare/tasks/add_disk.yml",
"owner": "generated_diagnostic_collection_name#0",
"code": "1",
"severity": 8,
"message": "Value is not accepted. Valid values: "absent", "mounted", "present", "unmounted", "remounted".",
"startLineNumber": 23,
"startColumn": 12,
"endLineNumber": 23,
"endColumn": 38
}
So the easy way to handle this is to ignore an incorrect type error if Jinja syntax is used. Or another possible way is to override specific type errors (but that seems too complicated here, esp. with an autogenerated schema). In all these cases, the Jinja placeholders refer to variables that do contain the correct type or values but the validation occurs without those Jinja expressions being evaluated.
The only way to get around this seems to be disabling YAML validation completely but that seems a bit extreme. Since schemastore is an upstream dependency, I'm hoping a config can be added to vscode-yaml to ignore type errors of the value contains jinja expressions.
I know that the vscode-yaml extension is using schemastore to determine validation syntax but I hoping a solution can occur at this level.
I have been getting really annoying "incorrect type" errors in my Ansible roles when using Jinja placeholders. Here's an example:
That file throws the following errors:
{
"resource": "/Users/shadow/dev/repos/linux-mac-base/ansible/roles/fileshare/tasks/add_disk.yml",
"owner": "generated_diagnostic_collection_name#0",
"code": "1",
"severity": 8,
"message": "Value is not accepted. Valid values: "btrfs", "ext2", "ext3", "ext4", "ext4dev", "f2fs", "lvm", "ocfs2", "reiserfs", "xfs", "vfat", "swap".",
"startLineNumber": 8,
"startColumn": 13,
"endLineNumber": 8,
"endColumn": 38
}
{
"resource": "/Users/shadow/dev/repos/linux-mac-base/ansible/roles/fileshare/tasks/add_disk.yml",
"owner": "generated_diagnostic_collection_name#0",
"severity": 8,
"message": "Incorrect type. Expected "boolean".",
"startLineNumber": 9,
"startColumn": 12,
"endLineNumber": 9,
"endColumn": 32
}
{
"resource": "/Users/shadow/dev/repos/linux-mac-base/ansible/roles/fileshare/tasks/add_disk.yml",
"owner": "generated_diagnostic_collection_name#0",
"severity": 8,
"message": "Incorrect type. Expected "array".",
"startLineNumber": 10,
"startColumn": 11,
"endLineNumber": 10,
"endColumn": 37
}
{
"resource": "/Users/shadow/dev/repos/linux-mac-base/ansible/roles/fileshare/tasks/add_disk.yml",
"owner": "generated_diagnostic_collection_name#0",
"severity": 8,
"message": "Incorrect type. Expected "boolean".",
"startLineNumber": 11,
"startColumn": 15,
"endLineNumber": 11,
"endColumn": 36
}
{
"resource": "/Users/shadow/dev/repos/linux-mac-base/ansible/roles/fileshare/tasks/add_disk.yml",
"owner": "generated_diagnostic_collection_name#0",
"code": "1",
"severity": 8,
"message": "Value is not accepted. Valid values: "absent", "mounted", "present", "unmounted", "remounted".",
"startLineNumber": 23,
"startColumn": 12,
"endLineNumber": 23,
"endColumn": 38
}
So the easy way to handle this is to ignore an incorrect type error if Jinja syntax is used. Or another possible way is to override specific type errors (but that seems too complicated here, esp. with an autogenerated schema). In all these cases, the Jinja placeholders refer to variables that do contain the correct type or values but the validation occurs without those Jinja expressions being evaluated.
The only way to get around this seems to be disabling YAML validation completely but that seems a bit extreme. Since schemastore is an upstream dependency, I'm hoping a config can be added to vscode-yaml to ignore type errors of the value contains jinja expressions.