Skip to content

Creating a node on WSL fails in disable-swap.yml #112

Description

@sirredbeard

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.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions