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

Port CVEX to Windows #13

Open
olegbck opened this issue Nov 28, 2024 · 0 comments
Open

Port CVEX to Windows #13

olegbck opened this issue Nov 28, 2024 · 0 comments

Comments

@olegbck
Copy link
Collaborator

olegbck commented Nov 28, 2024

Windows is the second popular OS among our users:

image

It won't be possible to run CVEX straight on Windows, because Ansible doesn't support Windows, however Ansible can run on WSL. I made some research and this is so far I came up with. Dumping my notes:

+Install VirtualBox on Windows:
+https://download.virtualbox.org/virtualbox/7.0.22/VirtualBox-7.0.22-165102-Win.exe
+
+Install WSL on Windows:
+wsl --install
+Reboot Windows and then wait for Ubuntu installation. Open the Ubuntu WSL prompt and then perform the actions below.
+Install Vagrant on Windows:
+https://releases.hashicorp.com/vagrant/2.4.1/vagrant_2.4.1_windows_amd64.msi
+
+Install Vagrant in WSL:
+```
+wget https://releases.hashicorp.com/vagrant/2.4.1/vagrant-2.4.1-1.x86_64.rpm
+sudo apt install alien
+sudo alien -i vagrant-2.4.1-1.x86_64.rpm
+vagrant plugin install virtualbox_WSL2
+echo 'export VAGRANT_WSL_ENABLE_WINDOWS_ACCESS="1"' >> ~/.bashrc
+echo 'export PATH="$PATH:/mnt/c/Program Files/Oracle/VirtualBox"' >> ~/.bashrc
+source ~/.bashrc
+```
+++ b/src/cvex/consts.py
@@ -1,6 +1,6 @@
 from pathlib import Path

-CVEX_ROOT = Path.home() / ".cvex"
+CVEX_ROOT = Path("/mnt/c/Users/John Snow/.cvex")

In linuxvm.py:
@@ -46,11 +47,16 @@ class LinuxVM(VM):
         inventory = Path(self.destination, "inventory.ini")
         with open(inventory, "w") as f:
             self.log.info("Retrieving SSH configuration of %s...", self.vm_name)
+            vagrant_keyfile = self.vag.keyfile()
+            keyfile = f"/tmp/{self.vm_name}.key"
+            self.log.debug("Copying %s to %s", vagrant_keyfile, keyfile)
+            shutil.copyfile(vagrant_keyfile, keyfile)
+            os.chmod(keyfile, 0o600)
             data = (f"{self.vm_name} "
                     f"ansible_host={self.vag.hostname()} "
                     f"ansible_port={self.vag.port()} "
                     f"ansible_user={self.vag.user()} "
-                    f"ansible_ssh_private_key_file={self.vag.keyfile()} "
+                    f"ansible_ssh_private_key_file={keyfile} "
                     f"ansible_ssh_common_args='-o StrictHostKeyChecking=no'")
             f.write(data)
         return inventory


@@ -63,7 +63,7 @@ class WindowsVM(VM):
             data = (f"{self.vm_name} "
                     f"ansible_connection=winrm "
                     f"ansible_winrm_scheme=http "
-                    f"ansible_host={config['host']} "
+                    f"ansible_host={self.ip} "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant