vscode-ansible icon indicating copy to clipboard operation
vscode-ansible copied to clipboard

The top element in the inventory is highlighted with an error

Open Alecton4 opened this issue 2 years ago • 2 comments

Sanity check

  • [X] I certify that the redhat.ansible extension is in use and the language of the document in this bug report shows up as Ansible

Summary

I encountered almost the same issue as this one. The project can be found here. The Ansible project directory is DetectionLab/ESXi/ansible.

image

I am not sure why this inventory.yml file is not recognized as an inventory file. Is it because I add the entire DetectionLab folder to a multi-root workspace in VSCode? My workspace is as follows. The yellow ones are the root folders in this multi-root workspace.

image

Also, I have the following settings in the workspace scope.

"files.associations": {
	"**/*ansible*/**/*.yml": "ansible",
},

Extension version

0.10.0

VS Code version

1.69.0

Ansible Version

$ ansible --version  
/usr/lib/python3/dist-packages/paramiko/transport.py:219: CryptographyDeprecationWarning: Blowfish has been deprecated
  "class": algorithms.Blowfish,
ansible [core 2.13.1]
  config file = /home/az/workspace/eWalker/TestLab/ESXi/ansible/ansible.cfg
  configured module search path = ['/home/az/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/az/.local/lib/python3.8/site-packages/ansible
  ansible collection location = /home/az/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.8.10 (default, Mar 15 2022, 12:22:08) [GCC 9.4.0]
  jinja version = 3.1.2
  libyaml = True

OS / Environment

local host: Windows 10 using remote SSH. remote host: Ubuntu 20.04 (in VMware Workstation 16 installed on local host). ansible-lint 6.3.0.

Relevant log output

Path for lint:  /home/az/.local/bin/ansible-lint
Validating using ansible-lint
Path for lint:  /home/az/.local/bin/ansible-lint
Validating using ansible-lint
Path for lint:  /home/az/.local/bin/ansible-lint
Validating using ansible-lint
Path for lint:  /home/az/.local/bin/ansible-lint
Validating using ansible-lint
Path for lint:  /home/az/.local/bin/ansible-lint
Validating using ansible-lint
Path for lint:  /home/az/.local/bin/ansible-lint
Validating using ansible-lint
Path for lint:  /home/az/.local/bin/ansible-lint
Validating using ansible-lint
Path for lint:  /home/az/.local/bin/ansible-lint
Validating using ansible-lint
Path for lint:  /home/az/.local/bin/ansible-lint
Validating using ansible-lint
Path for lint:  /home/az/.local/bin/ansible-lint
Validating using ansible-lint
Path for lint:  /home/az/.local/bin/ansible-lint
Validating using ansible-lint

Alecton4 avatar Jul 14 '22 03:07 Alecton4

I tested with your repository and the file is correctly identified as an inventory file if you do not alter the file associations.

@priyamsahoo WDYT? I do know why this happens as this forces use of ALS for an inventory file. When not assigned it will use YAML LS with inventory schema, which is just fine. Somehow I have the impression that many users could end-up doing a similar kind of configuration mistake.

That path is wrong because it will force use of ALS even on templates/ and files/ within ansible/ folder but that bit with inventory seems something that we could be able to recognize.

ssbarnea avatar Aug 02 '22 10:08 ssbarnea

@Alecton4 For the moment remove your custom association pattern or change it to avoid including files that are not playbooks or tasks files as "ansible" language server knows only about these. The other file-types related to Ansible are taken care of YAML extension by default.

We are looking for a way to improve this, but it will take time as it is a real technical challange.

ssbarnea avatar Aug 02 '22 11:08 ssbarnea

remove your custom association pattern or change it to avoid including files that are not playbooks or tasks files

@ssbarnea Thanks for your reply. I changed my file association as below and it works.

"files.associations": {
	"**/*ansible*/inventory.yml": "yaml",
	"**/*ansible*/**/*.yml": "ansible",
	// "**/playbooks/**/*.yml": "ansible",
	// "**/roles/**/*.yml": "ansible"
},

BTW, I saw this commit made ansible-lint able to recognize inventory files. Thus I configured all the yml files in the project folder to be ansible type, expecting ansible-lint would be able to identify the inventory file.

Alecton4 avatar Aug 22 '22 06:08 Alecton4

After the recently updated version of the extension, which has the capability for detecting non-playbook files and doing linting, I believe this issue is resolved. Kindly check and feel free to open it up if not sorted.

priyamsahoo avatar Oct 01 '22 17:10 priyamsahoo