Getting started with Ansible: local automation of Windows 10 and Ubuntu 20.04 workstations

Artūrs Demiters
Level Up Coding
Published in
2 min readSep 26, 2020

--

Photo by Fotis Fotopoulos on Unsplash

You don’t need to be a seasoned DevOps professional to benefit from Ansible and related automation tools in your personal workspace. I will show an example setup I use to automate my personal Windows 10 and Ubuntu 20.04 workstation configuration (a similar approach would also work for MacOS).

The main goal of this setup is automating software installation, updates and configuration to quickly get my development environment running on both Ubuntu and Windows, so the system can be recreated effortlessly in case of stability issues or when switching to a new machine, taking less than an hour to setup each OS with the essentials to be ready for work. The key tools that will come in handy (besides Ansible) will be Snap (for Linux packages), Mackup (for Linux dotfiles/configuration backup) and Chocolatey (for Windows packages).

I will be installing VSCode, git, Node.js (nvm), Docker, Chromium, Slack and Dropbox on both systems.

Configuring Windows 10

First I run the following script in cmd to setup WinRM for Ansible:
powershell.exe -ExecutionPolicy ByPass -File "windows-host-setup.ps1"

Then, to execute my Ansible playbook on Windows I need a running Ansible control node which requires a Linux environment and the simplest way to get that running on the same machine is Windows Subsystem for Linux (WSL).

Windows Subsystem for Linux

  1. Windows search for Turn Windows features on or off, check Windows Subsystem for Linux, install, reboot;
  2. Install and launch Ubuntu 20.04 from the Windows Store;
  3. Create a user with password;
  4. Install Ansible: sudo apt update && sudo apt install -y ansible
  5. Run the Windows playbook: ansible-playbook windows-playbook.yml -i windows-inventory.yml --ask-pass --verbose

As evident above, I use Chocolatey to install software packages that will then auto-update. Finally, I install VSCode Settings Sync to restore my VSCode settings.

Configuring Ubuntu 20.04

I prefer snap packages (which auto-update and roll back gracefully) over apt packages, when available. The following works on Ubuntu 20.04:

  1. Install Ansible: sudo apt update && sudo apt install -y ansible
  2. Run the Ubuntu playbook: ansible-playbook ubuntu-playbook.yml -i ubuntu-inventory.yml --ask-become-pass --verbose

Then I run Dropbox, wait for it to sync and run mackup restore to restore configuration files previously backed up to Dropbox with mackup backup. Finally, install and run VSCode Settings Sync as before.

That’s it!

Some manual steps will always remain but overall this approach saves a lot of time once it’s part of your toolbelt. Many more parts of system configuration can be automated, see list of Ansible module collections for inspiration and feel free to fork and extend my example gists for your own use! :)

--

--