Here is a machine translation of the above Japanese text. Apologies for any mistakes.
This is an Ansible playbook for setting up Fedora as a WSL distribution. It handles the setup within the distribution after importing a container-based rootfs with wsl --import ...
.
This playbook performs the following major configurations:
- Initial Setup (Role: initial_setup)
- Configure
man
- Install packages
- Enable systemd for WSL
- Configure
- General User Setup (Role: user_setup)
- Create and register the user as the default for WSL
- Mount Box Drive
- Customize
bashrc
and.gitconfig
(including Windows SSH Agent integration) - Install tools outside of DNF
- Post-Systemd Startup Setup (Role: after_started_systemd)
- Configure locale and timezone
- Enable services
For details, refer to the main.yml
of each role.
-
Import the rootfs of Fedora using
wsl --import xxx yyy
. -
Install the packages required to execute the playbook:
dnf install git ansible python3-passlib python3-libdnf5
-
Clone this repository:
git clone https://github.com/peter-777/fedora-wsl-setup-playbook.git && \ cd ./fedora-wsl-setup-playbook
-
Execute the playbook. Details of the command parameters are provided below.
ansible-playbook -l <environment> playbook.yml -e @private.yml --ask-vault-pass
-
Shut down WSL using
wsl --shutdown
, restart the distribution, and then execute the following as the root user:ansible-playbook -l fedora playbook.yml --tags after-started-systemd -e @private.yml --ask-vault-pass
Parameter | Description |
---|---|
-l | fedora or testcontainer fedora : Execute the playbook on the running WSL distribution.testcontainer : Start a Fedora container with Podman and execute the playbook. |
-e @private.yml | Load parameters from the Vault file (private.yml ). Details are provided below.While not mandatory, it is recommended. |
--ask-vault-pass | Prompts for the Vault password. Use this if the Vault is encrypted. |
When specifying -l testcontainer
, Podman automatically starts a Fedora container, but if a container named testcontainer
already exists, it will be reused.
To test in a fresh environment or remove the playground, use the following commands to delete the container:
podman stop testcontainer
podman rm testcontainer
When running the playbook, some parameters (such as the username and password to create) need to be provided at runtime. It is convenient to use ansible-vault
to save these parameters in a file.
Create the following YAML file, replacing the username and password with your own:
user_name: user
user_password: password
user_salt: saltstring
user_git_name: User Name
user_git_email: [email protected]
box_drive_path: C:/Users/UserName/Box
Optionally, encrypt the Vault file. The example below assumes the Vault file is named private.yml
:
ansible-vault encrypt private.yml
To customize the default user's .bashrc
, edit the roles/user_setup/files/append-bashrc.sh
file.
To modify the packages that are installed, edit the roles/initial_setup/vars/main.yml
file.
Running this playbook allows you to use the SSH Agent from Windows within WSL, which is especially beneficial for users who manage their private keys with tools like 1Password.
Previously, this was achieved using Npiperelay
and a socket service, but it is now done by invoking Windows executables directly from WSL.
However, this method does not use the distribution's native SSH command, which has its pros and cons. Therefore, the tasks for installing Npiperelay
are left as comments.
Feel free to customize any other aspects as you prefer:
- Install additional tools besides the Quarkus CLI
- Exclude the Box Drive mount task if you are not a Box Drive user
- And so on...