Skip to content
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

Cannot find ansible.cfg when using multi-root workspaces #12

Open
codestation opened this issue Feb 10, 2018 · 6 comments
Open

Cannot find ansible.cfg when using multi-root workspaces #12

codestation opened this issue Feb 10, 2018 · 6 comments
Labels

Comments

@codestation
Copy link

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 codestation changed the title Cannot find ansible.cfg when using workspaces Cannot find ansible.cfg when using multi-root workspaces Feb 10, 2018
@dhoeric
Copy link
Owner

dhoeric commented Feb 11, 2018

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.

@codestation
Copy link
Author

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.

@Dutchy-
Copy link

Dutchy- commented Feb 12, 2018

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.

@dhoeric
Copy link
Owner

dhoeric commented Feb 13, 2018

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
Copy link
Owner

dhoeric commented Feb 18, 2018

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

@Dutchy-
Copy link

Dutchy- commented Feb 18, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants