vscode-ansible: unable to parse yaml playbooks - ERROR "Ansible-lint is not available. Kindly check the path or disable validation using ansible-lint"

Summary

Fresh installation of Ansible extension for VSCode 1.1.34 (Windows 10). Unable to use the ansible extension to review YAML files for consistency and contextual support.

YAML files are associated with the Ansible extension.

Error shown within Vscode output when opening YAML file;

Path for lint: undefined [Trace - 11:20:15] Received request ‘window/showMessageRequest - (12)’. Params: { “type”: 1, “message”: “Ansible-lint is not available. Kindly check the path or disable validation using ansible-lint”, “actions”: [] }

Extension version

1.1.34

VS Code version

1.74.2

Ansible Version

Not installed locally.

OS / Environment

Windows 10

Relevant log output

[Trace - 11:20:15] Sending notification 'textDocument/didOpen'.
Params: {
    "textDocument": {
        "uri": "file:///c%3A/Users/locadd/GIT/appAutomation/playbooks/playbook.yml",
        "languageId": "ansible",
        "version": 1,
        "text": "---\r\n# copy gitonfig master ansible -m copy -a \"src=../adhoc/.gitconfig dest=~/.gitconfig\" localhost\r\n\r\n- name: ensure gitconfig is applied to device\r\n  hosts: localhost\r\n  tasks:\r\n  - copy: src=../adhoc/.gitconfig dest=~/.gitconfig\r\n#ansible -m homebrew -a \"name=jq state=latest\" localhost\r\n#ansible -m homebrew -a \"name=bat state=latest\" localhost"
    }
}


[Trace - 11:20:15] Sending notification 'update/ansible-metadata'.
Params: [
    [
        "file:///c%3A/Users/locadd/GIT/appAutomation/playbooks/playbook.yml"
    ]
]


[Trace - 11:20:15] Sending request 'textDocument/semanticTokens/full - (9)'.
Params: {
    "textDocument": {
        "uri": "file:///c%3A/Users/locadd/GIT/appAutomation/playbooks/playbook.yml"
    }
}


[Trace - 11:20:15] Received request 'workspace/configuration - (11)'.
Params: {
    "items": [
        {
            "scopeUri": "file:///c%3A/Users/locadd/GIT/appAutomation/playbooks/playbook.yml",
            "section": "ansible"
        }
    ]
}


[Trace - 11:20:15] Sending response 'workspace/configuration - (11)'. Processing request took 1ms
Result: [
    {
        "ansible": {
            "path": "C:\\Users\\locadd\\.vscode\\extensions\\redhat.ansible-1.1.34",
            "useFullyQualifiedCollectionNames": true,
            "reuseTerminal": false
        },
        "python": {
            "interpreterPath": "python3",
            "activationScript": ""
        },
        "ansibleNavigator": {
            "path": "ansible-navigator"
        },
        "completion": {
            "provideRedirectModules": true,
            "provideModuleOptionAliases": true
        },
        "validation": {
            "enabled": true,
            "lint": {
                "enabled": true,
                "path": "ansible-lint",
                "arguments": ""
            }
        },
        "executionEnvironment": {
            "enabled": false,
            "containerEngine": "auto",
            "containerOptions": "",
            "image": "quay.io/ansible/creator-ee:latest",
            "pull": {
                "arguments": "",
                "policy": "missing"
            },
            "volumeMounts": []
        }
    }
]


cmd 'python3 --version' was not executed with the following error: ' Error: spawn C:\WINDOWS\system32\cmd.exe ENOENT
cmd 'ansible-lint --version' was not executed with the following error: ' Error: spawn C:\WINDOWS\system32\cmd.exe ENOENT
[Trace - 11:20:15] Received notification 'update/ansible-metadata'.
Params: [
    [
        {
            "ansible information": {},
            "python information": {},
            "ansible-lint information": {}
        }
    ]
]


Error: spawn C:\WINDOWS\system32\cmd.exe ENOENT
    at ChildProcess._handle.onexit (node:internal/child_process:283:19)
    at onErrorNT (node:internal/child_process:478:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:83:21) {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'spawn C:\\WINDOWS\\system32\\cmd.exe',
  path: 'C:\\WINDOWS\\system32\\cmd.exe',
  spawnargs: [ '/d', '/s', '/c', '"command -v ansible-lint"' ],
  cmd: 'command -v ansible-lint',
  stdout: '',
  stderr: ''
}
[Trace - 11:20:15] Received response 'textDocument/semanticTokens/full - (9)' in 11ms.
Result: {
    "resultId": "1673868015084",
    "data": [
        3,
        2,
        4,
        2,
        0,
        1,
        2,
        5,
        2,
        0,
        1,
        2,
        5,
        2,
        0,
        1,
        4,
        4,
        3,
        1
    ]
}


Error: spawn C:\WINDOWS\system32\cmd.exe ENOENT
    at ChildProcess._handle.onexit (node:internal/child_process:283:19)
    at onErrorNT (node:internal/child_process:478:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:83:21) {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'spawn C:\\WINDOWS\\system32\\cmd.exe',
  path: 'C:\\WINDOWS\\system32\\cmd.exe',
  spawnargs: [ '/d', '/s', '/c', '"whereis ansible-lint"' ],
  cmd: 'whereis ansible-lint',
  stdout: '',
  stderr: ''
}
Path for lint:  undefined
[Trace - 11:20:15] Received request 'window/showMessageRequest - (12)'.
Params: {
    "type": 1,
    "message": "Ansible-lint is not available. Kindly check the path or disable validation using ansible-lint",
    "actions": []
}


[Trace - 11:20:15] Received notification 'window/logMessage'.
Params: {
    "type": 1,
    "message": "An error occurred in 'onDidOpen' handler: [TypeError] Cannot read properties of undefined (reading 'has')\nTypeError: Cannot read properties of undefined (reading 'has')\n    at c:\\Users\\locadd\\.vscode\\extensions\\redhat.ansible-1.1.34\\out\\server\\src\\server.js:2:44852\n    at Generator.next (<anonymous>)\n    at s (c:\\Users\\locadd\\.vscode\\extensions\\redhat.ansible-1.1.34\\out\\server\\src\\server.js:2:42491)\n    at process.processTicksAndRejections (node:internal/process/task_queues:96:5)"
}


[Error - 11:20:15] An error occurred in 'onDidOpen' handler: [TypeError] Cannot read properties of undefined (reading 'has')
TypeError: Cannot read properties of undefined (reading 'has')
    at c:\Users\locadd\.vscode\extensions\redhat.ansible-1.1.34\out\server\src\server.js:2:44852
    at Generator.next (<anonymous>)
    at s (c:\Users\locadd\.vscode\extensions\redhat.ansible-1.1.34\out\server\src\server.js:2:42491)
    at process.processTicksAndRejections (node:internal/process/task_queues:96:5)
[Trace - 11:20:15] Sending response 'window/showMessageRequest - (10)'. Processing request took 189357ms
No result returned.


[Trace - 11:20:15] Sending notification 'update/ansible-metadata'.
Params: [
    [
        "file:///c%3A/Users/locadd/GIT/appAutomation/playbooks/playbook.yml"
    ]
]


cmd 'python3 --version' was not executed with the following error: ' Error: spawn C:\WINDOWS\system32\cmd.exe ENOENT
cmd 'ansible-lint --version' was not executed with the following error: ' Error: spawn C:\WINDOWS\system32\cmd.exe ENOENT
[Trace - 11:20:15] Received notification 'update/ansible-metadata'.
Params: [
    [
        {
            "ansible information": {},
            "python information": {},
            "ansible-lint information": {}
        }
    ]
]


[Trace - 11:23:13] Sending notification 'update/ansible-metadata'.
Params: [
    [
        "file:///c%3A/Users/locadd/GIT/appAutomation/playbooks/playbook.yml"
    ]
]


cmd 'python3 --version' was not executed with the following error: ' Error: spawn C:\WINDOWS\system32\cmd.exe ENOENT
cmd 'ansible-lint --version' was not executed with the following error: ' Error: spawn C:\WINDOWS\system32\cmd.exe ENOENT
[Trace - 11:23:13] Received notification 'update/ansible-metadata'.
Params: [
    [
        {
            "ansible information": {},
            "python information": {},
            "ansible-lint information": {}
        }
    ]
]


[Trace - 11:23:16] Sending notification 'textDocument/didClose'.
Params: {
    "textDocument": {
        "uri": "file:///c%3A/Users/locadd/GIT/appAutomation/playbooks/playbook.yml"
    }
}

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 9
  • Comments: 19

Most upvoted comments

After installing ansible-lint locally and setting up the path within the extension settings, it worked as expected.

To be honest, I expected the extension to install ansible-lint by itself, just like some other extensions install their dependencies by themselves as well.

Mine was a little different.

I was using virtual-environment, where ansible-lint is installed but still I was getting this error.

I had to go to vscode-settings and enable the execution enabled.

This is how it is done:

via settings.json:
"ansible.executionEnvironment.enabled": true,

via settings UI:
image

The default settings expect you to have ansible-lint installed while using the extension for a better diagnostics experience. If you do not have ansible-lint installed, either install it (which is highly recommended), else, you can turn off the usage of ansible-lint from the settings (ansible.validation.lint.enabled: false)

@sumanth-lingappa, the execution environment setting has an entirely different purpose. It pulls the creator-ee image and runs ansible on it. If that was intended, then it’s okay.

But if your sole purpose was to use the ansible-lint from the virtual environment, you can use ansible.python.activationScript setting and set the path to the activate script of your venv. The extension will pick up binaries installed in that venv.

Also, looking at the logs, I can see that you are running the extension on Windows. The vscode-ansible extension is supported only on WSL (if you are using Windows).

Since I’m using Manjaro Linux, I installed ansible-lint via sudo pamac -Sy ansible-lint. Afterwards, ich checked the path where it has been installed to via type -p ansible-lint and edited the extension settings to match the executable path (here as JSON setting): "ansible.ansible.path": "/usr/bin/ansible"

The vscode-ansible extension is supported only on WSL (if you are using Windows).

If you are using Windows, you have to use Windows Subsystem for Linux (WSL) and start developing via WSL Extension and maybe additionally Remote Development. Inside WSL, you can install ansible-lint. This should fix the described behavior.

Further reading: https://code.visualstudio.com/docs/remote/wsl

sudo apt install ansible-lint

In my case, (macOS Sonoma 14.2) Ansible VS Code Extension v2.9.118 + Homebrew installed ansible-lint v6.22.1 doesn’t work.

After installing ansible-lint using pip, it started working properly. pip install ansible-lint (https://ansible.readthedocs.io/projects/lint/installing/)

Detailed version info:

$ ansible-lint --version
ansible-lint 6.22.1 using ansible-core:2.16.2 ansible-compat:4.1.10 ruamel-yaml:0.18.5 ruamel-yaml-clib:0.2.8

Also very confused, I am on Mac OS and have done a brew install Ansible-lint, I can run Ansible-lint --version in my terminal but still VsCode says that It can’t find the path, I don’t understand why? It’s there? Can someone pls explain this to me?

@priyamsahoo It would help each one new to this extension, if you and the team could update the README to guide us:

Either * install ansible-lint for Major OS choices(Win, MacOS, apt-based Linux and Yum-based linux) Or * disable it from the setting.

Even if I read through the issue, I still am hesitated in choosing which way to go, and it seems like brew install ansible and pointing VS code to the right python runtime does not solve the issue for me.

Hi @Xenion1987 I was able to solve it using the links and the resources sent. Thank you.