Jump to content
Sign in to follow this  
  • Blog

Running Ansible within Windows



With the very recent release of Windows Anniversary Update you can now run ansible on your windows machine.

Once you have Ansible installed, you can start automating everything.  If you need to, you can generate an SSH key for use connecting to servers, use ssh to directly connect to servers, etc. It's basically a full Ubuntu LTS install running inside Windows!

What do you need?

To run ansible on your Windows machine you need two things

  1. bash installed
  2. ansible installed

Below we will walk you through both

Installing Bash on Windows 10

To run ansible you need BASH installed on Windows. For your reference, here are the official instructions from Microsoft: Bash on Ubuntu on Windows - Installation Guide

Before installing the Linux Subsystem, you have to have:

  • Windows 10 (Anniversary update or later version)
  • 64-bit installation (can't run on 32-bit systems)

Once you verify your system is 64-bit and up to date, you have to do a few manual steps to enable the 'Windows Subsystem for Linux':

  1. Open 'Settings' (the cog in the start menu)
  2. Click 'Update & Security', then click the 'For developers' option on the left.
  3. Toggle the 'Developer mode' option, and accept any warnings Windows pops up.


Wait a minute for Windows to install a few things in the background (it will eventually let you know a restart may be required for changes to take effect—ignore that for now).


Note: Starting with the Fall Creators Update, you no longer have to enable Developer Mode in the Settings app to use this feature. You just need to install it from the Windows Features window.

Next, to install the actual Linux Subsystem, you have to jump over to 'Control Panel' (why is this separate from 'Settings'?), and do the following:

  1. Click on 'Programs'
  2. Click on 'Turn Windows features on or off'
  3. Scroll down and check 'Windows Subsystem for Linux (Beta)', and then click OK.


The subsystem will be installed, then Windows will require a reboot. Reboot

After your computer restarts, open the Microsoft Store from the Start menu, and search for “Linux” in the store. Click “Get the apps” which will filter the results to some Linux Distributions. For this we are going to use Ubuntu but you can use whatever you like that is displayed.


Once you click on Ubuntu (or whatever distro you decided on), click Get to begin the install process


Finally have Ubuntu running on your Windows laptop, somewhat integrated with Windows. You can also install multiple Linux distributions and they’ll each get their own unique shortcuts. You can even run multiple different Linux distributions at a time in different windows.

STRONG recommendation is to also install the font. It makes the experience so much better. Download the Ubuntu Font Family from Ubuntu’s website. Open the downloaded .zip file and locate the “UbuntuMono-R.ttf” file. It’s the only font in the zip that you need to install.  Double-click on the file and click Install (now its installed in Windows), now you need to add it to bash by editing your Registry.. no worries, its easy

Open a registry editor by pressing Windows+R on your keyboard, typing regedit , and then pressing Enter.

Navigate to the following key or copy and paste it into the Registry Editor’s address bar: 

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Console\TrueTypeFont


Right-click in the right pane and select New > String Value. Name the new value 000 .

Double-click the “000” string you just created, and then enter Ubuntu Mono as its value data.


Launch an Ubuntu window, right-click the title bar, and then select the “Properties”.


Click the “Font” tab, and then select “Ubuntu Mono” in the font list.


Installing Ansible

To install Ansible, since we're basically in an Ubuntu environment, it's as simple as installing pip, then installing Ansible:

  1. Open a bash prompt (from start menu, type 'bash' and hit enter).
  2. Install Pip: sudo apt-get -y install python-pip python-dev libffi-dev libssl-dev
  3. Install Ansible: pip install ansible --user (--user installs packages local to the user account instead of globally to avoid permissions issues with Pip and the Linux Subsystem)
  4. Since the ansible* commands are installed under ~/.local/bin, we need to add that to the $PATH, so run the command: echo 'PATH=$HOME/.local/bin:$PATH' >> ~/.bashrc
  5. Either exit out of the bash prompt and start it again from the Windows menu, or run source .bashrc to update your $PATH to include Ansible.

Note the use of --user for the pip install command; due to some peculiarities of the way the Linux subsystem works, Pip can't easily install packages globally, so we install packages just for the user account we set up for bash.

Using Ansible

At this point, which ansible should show the path to Ansible, ansible --version should show you Ansible's version, and you should be able to use ansible and the rest of the command-line tools (e.g. ansible-playbookansible-galaxy, etc.) as you would on any common environment.

If you get the error message ImportError: No module named markupsafe, try installing markupsafe manually with pip install markupsafe --user. See this GitHub issue for more detail.

If you want to run a playbook that's stored in your Windows user account's Documents folder (e.g. C:\Users\dennis\Documents), you can do so by navigating to /mnt/c/Users/dennis/Documents (where dennis is your username). Windows drives are mounted in the Subsystem inside the /mnt directory. Let's create a test playbook and see if it works!

  1. Open a bash prompt, and cd into your Windows user's Documents directory: cd /mnt/c/Users/jgeerling/Documents.
  2. Create a new test playbook: touch test.yml
  3. User nano or some other editor to add the following contents:
    •   ---
        - hosts: localhost
            - debug: msg="Ansible is working!"


  4. Run the playbook with the command ansible-playbook test.yml --connection=local

Ansible should run the command and print out the debug message. Ansible might warn about no inventory file being present, but since you're using --connection=local, the localhost host should automatically work.


Recommended Comments

There are no comments to display.

Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...