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

Windows in WSL support

Open bartmeuris opened this issue 7 years ago • 6 comments

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.

bartmeuris avatar Nov 09 '17 16:11 bartmeuris

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

I could provide a setup session for this.

dhoeric avatar Jan 24 '18 17:01 dhoeric

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.

bartmeuris avatar Feb 02 '18 10:02 bartmeuris

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.

dhoeric avatar Feb 11 '18 16:02 dhoeric

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.

xpac1985 avatar May 20 '18 22:05 xpac1985

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

tvories avatar Sep 11 '18 17:09 tvories

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.

derekslenk avatar Apr 22 '19 17:04 derekslenk