Skip to content

Commit

Permalink
+ add wsl2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
BacLuc committed Jul 21, 2023
1 parent e314a8f commit 3da9513
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 1 deletion.
9 changes: 9 additions & 0 deletions ansible/playbook.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
- hosts: all

pre_tasks:
- name: Check if running in wsl 2
ansible.builtin.shell: wsl.exe -- ls
ignore_errors: true
changed_when: true
register: wsl_is_wsl_command
- name: Set facts if running in wsl
ansible.builtin.set_fact:
wsl_is_wsl: '{{ true if (wsl_is_wsl_command.rc == 0) else false }}'
- ansible.builtin.include_tasks: tasks/ubuntu_apt.yml
- ansible.builtin.include_tasks: tasks/ubuntu_desktop.yml
- ansible.builtin.include_tasks: tasks/virtualbox_additions.yml
- ansible.builtin.include_tasks: tasks/virtualbox_additions.yml
- ansible.builtin.include_tasks: tasks/basicsetup.yml
- ansible.builtin.include_tasks: tasks/buildtools.yml
- ansible.builtin.include_tasks: tasks/java.yml
Expand Down
7 changes: 6 additions & 1 deletion ansible/tasks/ubuntu_desktop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,34 @@
ansible.builtin.apt:
name: python3-software-properties
state: absent
when: ubuntu_desktop.rc == 1
when: (ubuntu_desktop.rc == 1) and (not wsl_is_wsl)

- name: Install Ubuntu Desktop
become: true
ansible.builtin.apt:
name: ubuntu-desktop
when: not wsl_is_wsl

- name: Install Ubuntu Desktop missing dependencies (needed for vbox guest additions)
become: true
ansible.builtin.apt:
name: linux-image-generic
when: not wsl_is_wsl

- name: Install psutil that is needed for dconf module below
become: true
ansible.builtin.apt:
name: python3-psutil
when: not wsl_is_wsl

- name: Define all gnome favorite apps
community.general.dconf:
key: "/org/gnome/shell/favorite-apps"
value: "['org.gnome.Nautilus.desktop', 'firefox.desktop', 'org.gnome.Terminal.desktop', 'jetbrains-clion.desktop', 'jetbrains-idea-ce.desktop', 'code.desktop']"
when: not wsl_is_wsl

- name: Add german keyboard layouts
community.general.dconf:
key: "/org/gnome/desktop/input-sources/sources"
value: "[('xkb', 'ch'), ('xkb', 'us')]"
when: not wsl_is_wsl
5 changes: 5 additions & 0 deletions ansible/tasks/virtualbox_additions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
become: true
ansible.builtin.package:
name: virtualbox-guest-additions-iso
when: not wsl_is_wsl

- name: Create virtualbox additions mount point
become: true
ansible.builtin.file:
dest: /media/vbadd
mode: "u+rw"
state: directory
when: not wsl_is_wsl

- name: Install virtualbox additions # noqa command-instead-of-module
become: true
Expand All @@ -18,15 +20,18 @@
umount /media/vbadd/
args:
creates: /usr/sbin/VBoxService
when: not wsl_is_wsl

- name: Create group vboxsf
become: true
ansible.builtin.group:
name: vboxsf
when: not wsl_is_wsl

- name: Add user to vboxsf group to have access to bind mounts
become: true
ansible.builtin.user:
name: "{{ ansible_env.USER }}"
append: true
groups: vboxsf
when: not wsl_is_wsl
40 changes: 40 additions & 0 deletions docs/wsl2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
WSL 2
=======

WSL 2 bietet die Möglichkeit, einen Linux-Kernel parallel zu Windows auszuführen.
Der Zugriff auf das Windows-Dateisystem ist möglich, jedoch etwas langsam.
Deshalb sollte man seine Dateien im WSL 2 Filesystem bearbeiten.
Mit den neuesten Versionen von Windows 10 und Windows 11 können auch
GUI-Anwendungen ausgeführt werden.
Es wird empfohlen, eine separate Ubuntu WSL 2 Instanz für den Start zu erstellen,
um mögliche Probleme mit anderen Projekten zu vermeiden,
falls du WSL2 bereits verwendest.

!!! Achtung !!!
------------

Falls in einem Projekt schon eine VirtualBox VM verwendet wird,
kann dies zu Problemen führen.
In diesem Fall die Variante [VirtualBox](../virtualbox.md)
verwenden.


Installation
------------

1. WSL 2 über Windows Store installieren: [WSL 2 in Windows Store](https://www.microsoft.com/store/productId/9P9TQF7MRM4R)
2. \
a. Falls noch keine WSL 2 Instanz da ist: Ubuntu über Windows Store installieren: [Ubuntu 22.04 in Windows Store](https://www.microsoft.com/store/productId/9PN20MSR04DW)\
b. Sonst: Eine zusätzliche WSL 2 Instanz mit ubuntu 22 erstellen: <https://endjin.com/blog/2021/11/setting-up-multiple-wsl-distribution-instances>\
3. `git clone https://github.com/scs/jumpstart-vm.git`
4. `cd jumpstart-vm`
5. `./provision.sh`. Achtung: Dieser Schritt installiert sehr viele Pakete in der VM
und dauert entsprechend sehr lange.
6. Sicherstellen, dass systemd aktiviert ist:
```bash
cat << 'EOF' | sudo tee /etc/wsl.conf
[boot]
systemd=true
EOF
```

0 comments on commit 3da9513

Please sign in to comment.