Creating a node on WSL fails in disable-swap.yml
sirredbeard opened this issue · 2 comments
Provisioning a node on WSL fails when attempting to disable swap in the pf9-express playbook:
- name: Disable swap
command: swapoff -a
when: ansible_swaptotal_mb > 0
Results in:
TASK [disable-swap : Disable swap] *************************************************************************************
Tuesday 05 January 2021 11:32:54 -0500 (0:00:00.223) 0:00:04.179 *******
fatal: [localhost]: FAILED! => {"changed": true, "cmd": ["swapoff", "-a"], "delta": "0:00:00.001871", "end": "2021-01-05 11:32:54.833778", "msg": "non-zero return code", "rc": 255, "start": "2021-01-05 11:32:54.831907", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
This is because running sudo swapoff -a $?
results in:
$ sudo swapoff -a $?
swapoff: 255: swapoff failed: No such file or directory
This is because even though there is no swap mounted in /etc/fstab:
$ cat /etc/fstab
LABEL=cloudimg-rootfs / ext4 defaults 0 0
Swap is provided by the WSL2 VM shared between all running WSL distros:
$ cat /proc/swaps
Filename Type Size Used Priority
/swap/file file 7340032 0 -2
The official way to disable swap on WSL2 is to set swap=off
in %USERPROFILE%/.wslconfig.
The workaround for now is to simply comment out that step in the disable-swap role.
As discussed in #111 it can be tricky to detect if you are running in WSL, but it is possible.
There is a use case for being able to run a node on WSL for dev training purposes so it still may be worth addressing.
My first idea is to use a block here in the playbook to execute sudo swapoff -a
with a rescue: that if cat /proc/version | grep -q 'microsoft'
it will still then pass.
@sirredbeard Using sudo swapoff -a
with a rescue to set .wslconfig
file works for now. We can do this to unblock WSL installs for now. Let me know if you plan to open up a PR for the same.
Disabling swap in .wslconfig will disable swap for all WSL containers, not just the one being attached as a node. I would suggest, if conditions are met (swapoff -a fails but WSL is true):
- A prompt notifying the user that this change is being made to .wslconfig, confirming they want to make the change, and advising they will need to restart WSL with
wsl.exe --shutdown
before provisioning their node - In addition to making the change, make a backup of their original .wslconfig for the user as %USERPROFILE%\wslconfig.bak
If this sounds okay, I will work on it soon.
We can do this to unblock WSL installs for now.
Note that running pf9ctl on WSL still requires a systemd script for now.