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

Windows in WSL support #8

Open
bartmeuris opened this issue Nov 9, 2017 · 6 comments
Open

Windows in WSL support #8

bartmeuris opened this issue Nov 9, 2017 · 6 comments

Comments

@bartmeuris
Copy link

I use Visual Code on Windows, but run Ansible in VM's or in Window's Linux Subsystem (WSL). With the newer versions, you can launch Linux programs from Windows with the c:\Windows\System32\bash.exe command.

I first tried to set ansibleVault.executable to c:\\Windows\\System32\\bash.exe -lc 'workon ansible2; ansible-vault $*' -- which is a command that works from the cmd.exe windows shell (without the escaped \). Running this however completely hangs all input in Visual Studio, forcing me to restart it.

I've tried quite a few things, including a wrapper shellscript, wrapper batch script, ... all with the same results.

@dhoeric
Copy link
Owner

dhoeric commented Jan 24, 2018

Since I don't have Windows computer, welcome for contributing if anyone wants to help :)

I could provide a setup session for this.

@bartmeuris
Copy link
Author

I don't have any experience with typescript or vscode plugins, but I suspect it would have something to do with how the ansible-vault process is launched.

Briefly looking at the code - I see there are no special options given to child_process.execSync when an encrypt or decrypt is triggered. If I look at the child_process.execSync documentation, the only Windows specific option I see there is the windowsHide option, which by default should show a window from a child process as far as I understand? I however never see a child window, and don't think that would be a desirable behavior anyway, setting this to true wouldn't hurt right?

Another issue is that the command touch ${keypath} && echo "${pass}" > ${keypath} is executed when the user is prompted for a password - which also fails on Windows. Opening the file and writing it yourself without spawning other processes would probably be the more portable/safer way.

@dhoeric
Copy link
Owner

dhoeric commented Feb 11, 2018

We are similar. I am also new to typescript and vscode thingy. This is just my "toy project" to avoid developer directly deal with terminal and remember ansible-vault command in my working space. Therefore you may feel the code is not really clean and organized... sorry 🙇

I have setup the dev env in Windows and it looks like cannot take the correct path in extension runtime.
I would try to define ansibleVault.useWSL for running C:\Windows\System32\bash.exe -lc "..." on every child_process command. But just feeling skeptical if bash.exe could access C:\Users\... paths.

Back to your question,

[child_process.exeSync] setting windowsHide to true wouldn't hurt right?

It's fine for debug purpose, and actually I could get the command output in my development env. Once I could regenerate the error, I could check the message and fix it.

touch ${keypath} && echo "${pass}" > ${keypath}

This command also requires bash.exe with WSL -- once we figure out the right way to make use of bash.exe in WSL, the problem solved.

Thanks again your comments and please let me know if I understand wrongly.

@xpac1985
Copy link

Hey, I checked this, and it should be possible. You already found out that bash.exe -c "some command" can run a command in the bash. All files should be accessible, however the path has to be converted:
A path like C:\Users\youruser\somefile.txt would be /mnt/c/Users/youruser/somefile.txt.
The drive letter has to be a small letter, the : has to be removed, and the \ have to be replaced with / - that's it.

@tvories
Copy link

tvories commented Sep 11, 2018

I'd be happy to set up a session with you @dhoeric if you wanted to get Windows support for this working. I may be able to take a look at the code but I'm not too familiar with Typescript

@derekslenk
Copy link

Hey, I checked this, and it should be possible. You already found out that bash.exe -c "some command" can run a command in the bash. All files should be accessible, however the path has to be converted:
A path like C:\Users\youruser\somefile.txt would be /mnt/c/Users/youruser/somefile.txt.
The drive letter has to be a small letter, the : has to be removed, and the \ have to be replaced with / - that's it.

It does not work as simple as you say, I have just tried.

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

No branches or pull requests

5 participants