vscode-ansible-vault
vscode-ansible-vault copied to clipboard
Cannot find ansible.cfg when using multi-root workspaces
The plugin always tries to use the first folder declared in the workspace list, so if the vault file isn't in the first folder then the plugin will not find the ansible.cfg file or worse, uses the ansible.cfg of the first workspace folder, that can have an unrelated configuration.
A possible fix is to check the current folder, then the parent ones until it finds the ansible.cfg file (stopping at the root of the current workspace), then checking the user and system locations..
In my understanding ansible reads the config file in following order, from ansible doc:
* ANSIBLE_CONFIG (an environment variable)
* ansible.cfg (in the current directory)
* .ansible.cfg (in the home directory)
* /etc/ansible/ansible.cfg
And right now the extension should check the ansible.cfg in the project directory (in step 2). I would opt to follow the convention from ansible.
Yes, you are right, it should only read from those 3 locations. A proper fix is to remove the usage of vscode.workspace.rootPath (already deprecated) and migrate to multi-root workspace API.
For now i am using a workaround of editing my workspace file and putting the project that i am currently working on as the first entry.
Note: Vaulty can find the correct ansible.cfg, but i stick to your extension since Vaulty doens't encrypt back and shows a read-only yml.
I also encountered this. I personally would love to have Vaulty's approach of finding the working directory by checking all parent paths.
https://github.com/codeflows/vaulty/blob/master/src/vault.ts#L8
I leave it up to you if you can integrate this with the default ansible configuration order.
Thanks for comment @codestation @Dutchy- , just realized this feature and would be nice to be included in the extension :)
I will try to understand a bit and make it happen 👍
@codestation @Dutchy- Although I have added the support of multi-root workspace, is there any use cases of reading ansible.cfg from all parent paths?
Because of opening the workspace in sub-directory of Ansible playbooks or any?
TBH I am no longer using ansible-vault in my working place, your comments would be valuable :)
My preferred setup is $workspace/ansibleprojects/project1/ansible.cfg, so one extra level. It would be great if you can add support for that but I can work around it by opening the folders in the workspace directly.