Automating provisioning Ubuntu 20.04 with Ansible on WSL 2
Uses ansible, in a pipenv, in a WSL 2 Ubuntu instance to provision locally.
Intended to be re-runnable (idempotent) to maintain and update when required.
-
Windows 10
-
WSL 2 (to enable, run the below commands in an elevated powershell prompt)
-
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
-
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
-
Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform -NoRestart
-
wsl --set-default-version 2
-
wsl --shutdown
-
List available wsl distros
wsl --list --online
-
Ubuntu 20.04 installed via cmd
wsl --install -d Ubuntu-20.04
-
Generate an SSH key in your Ubuntu instance and add to Github
-
In PowerShell type
ipconfig
and note/copy the "Default Gateway" ip for "Wireless LAN adapter WiFi:" -
Temp fix DNS
echo "<default gateway ip>" > /etc/resolv.conf
-
Now you can clone this repo!
./scripts/fix_dns.sh -n "192.168.x.x" -h "a-host-name"
(your home router IP)
- Install Make
sudo apt install make
sudo apt-get update
make prep
make env
make shell
ansible-galaxy install -r requirements.yml
ansible-playbook playbook.yml -i inventory --ask-become-pass
cd provision-ubuntu2004-on-wsl2
make shell
make update
- See the playbook.yml task:
Install apt cmd line apps
for apt packages - yarn
- tfenv
- aws vault
- rbenv
- kubectl
- eksctl
- helm
Description | Command |
---|---|
Find all local info | ansible localhost -m setup |
Run only rbenv | ansible-playbook playbook.yml -i inventory --ask-become-pass --tags "rbenv" |
Purge deps | pipenv uninstall --all |
See vars.yml to configure which tasks get run.