-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide a way to set the working directory for the linters #885
Comments
Similarly to @dhoogfr, I've attempted to specify a project directory, including through a ---
project_dir: .
enable_list:
- args
- empty-string-compare
- no-log-password
- no-same-owner
- name[prefix]
- yaml
extra_vars:
vault_password_file: ~/vault-password But like @dhoogfr, the only way I could get the extension to pick up the vault password file was to place an Can we set a per-project environment variable, and override For reference, my project structure is like this (simplified):
I also tried:
Unfortunately I don't think we'll get folder-specific settings from VS Code any time soon, so the best option is for this to be available as a setting within the extension. PS This issue might need the "waiting on author" tag removing? |
@robpomeroy The extension does support multi-root workspace so you can try adding ![]() |
@dhoogfr As mentioned in above comment extension support multi root workspace, so you can add multiple folders at the top level of the workspace. |
Yes, thank you, I had spotted that. 👍 Unfortunately my workspace is large, structured and mature, and I was hoping not to have to rearrange it. It's already multi-root, with Ansible, Docker, Polyglot development, Packer, Terraform and WSL and some others all as separate roots (eight in total). Within the Ansible root, I have 37 separate projects. Ideally I'd prefer a fix that doesn't involve a complete rearrange. 🙂 |
I like the idea however in case of single Ansible root folder workspace the setting needs to be changed based on which project you are working on within the VSCode window. I usually work with separate VSCode windows for different projects and use multi-root workspace for related sub-projects |
I too have found myself in need of this feature, I have a project/repo with a structure like:
Currently, the VSCode Ansible extension only works when opened from I tried setting "terminal.integrated.env.linux": {
"ANSIBLE_CONFIG": "/xxx/services/ansible/ansible.cfg"
} But this did not fix anything. I found that if I set in the console Assuming the issue is detection of
|
Just bumped into this while setting up
When I'm running
It's easy to notice that First I'm tried to add "ansible.validation.lint.arguments": "--project-dir ${PWD}/infra", to For now I take idea from @erichiller and created helper script #!/usr/bin/env bash
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
export ANSIBLE_ROLES_PATH=./infra/roles/:./infra/roles_internal/:./infra/roles_public/:./private/roles/
code "$SCRIPT_DIR" I'm not using From VSCode side of thing it would be nice if environment variables defined for integrated terminal would be passed to command line linters, or alternatively additional configuration section in Ansible extension where environment variables can be defined. |
Problem
The plugin runs ansible-lint / ansible --syntax-check from a working directory that seems to be set to the workspace root directory.
This can cause issues if for example you have the following directory structure
With the vscode workspace root directory set to "./project" and you have an ansible.cfg file under the code directory.
In such a situation, the linter will not pickup this ansible.cfg file.
In my case it causes an error with "ansible-playbook --syntax-check" as the vault-password-file variable is not picked up and it fails to decrypt the vault file:
Solution
The Python plugin provides a configuration parameter to set the working directory for the linter.
A similar option for the Ansible plugin to set a (relative) path would solve the above problems
Alternatives
An alternative would be to have an explicit configuration option to specify the vault password file.
But that would not solve the issue with not reading the ansible.cfg file.
Another alternative could be to instead of using the vscode workspace root as working directory, allow the vscode buildin terminal CWD configuration parameter to override it.
But that could break existing setups
Additional context
No response
The text was updated successfully, but these errors were encountered: