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

Cannot find ansible.cfg when using multi-root workspaces

Open codestation opened this issue 7 years ago • 6 comments

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..

codestation avatar Feb 10 '18 03:02 codestation

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.

dhoeric avatar Feb 11 '18 16:02 dhoeric

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.

codestation avatar Feb 11 '18 21:02 codestation

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.

Dutchy- avatar Feb 12 '18 10:02 Dutchy-

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 👍

dhoeric avatar Feb 13 '18 14:02 dhoeric

@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 :)

dhoeric avatar Feb 18 '18 16:02 dhoeric

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.

Dutchy- avatar Feb 18 '18 18:02 Dutchy-