How to Install Ansible on Windows 10

Know simple way to configure Ansible on Windows 10 using Windows subsystems for Linux such as Debian, Open Suse or Ubuntu. 

Ansible is an open source software available for Linux Based systems such as Debian, Redhat, Ubuntu, Centos and more…  Besides the free product, it also comes in an enterprise version called Ansible Tower. It was acquired by RedHat (2015) and written in Python. It is basically powerful and simple to setup tool that uses for making the automation process. It can help in configuration management, application deployment, and task automation.

This tool is capable of handling complex operations without the need of some agent on the remote machine. It can connect remotely via SSH or Powershell.

Ansible is very much able to handle multiple tasks simultaneously. For example, the user can upgrade some remote server while simultaneously detaching that from any cluster.  Means many complex tasks can be done from a single point on the screen. It also has an extensible architecture which allows users to use Ansible modules to add extra functionality into it. They are mostly standalone and written in language like Python, Perl, Ruby, Bash, etcetera. So, now let’s see how to install the Ansible on Windows 10 without any virtual machine or virtualization software like VirtualBox.

Install Ansible on Windows 10

  • Open the Window’s Turn Windows features on or off section.
  • Select the Windows Subsystem for Linux to activate it.
  • Go to the Microsoft app store.
  • Search for Linux.
  • Multiple Linux system will appear like Debian, Ubuntu, OpenSuse
  • Select the Ubuntu or any other  Linux you want to install the Ansible. Here we are using Ubuntu 18.04
  • Once the Ubuntu installed on Windows 10, it will ask you to create the user.
  • Now add the Ansible PPA repo on Windows 10’s Ubuntu app.
  • Use installation commands to install the Ansible on Windows 10 Linux subsystem.
  • Now you can run Ansible on Windows to perform different management and automation tasks.

Tutorial in Detail with screenshots:

Step 1: Turn Windows features on or off 

Basically, this features already on the Windows 10 and we just need to turn it on from the features option. For that just search for Windows features in the Search box. And when the “Turn Windows features on or off ” appears click on that.

Turns windows features turn on or off

Step 2: Install the Windows SubSystem for Linux

Now a window will open with a bunch of features. Scroll down and check the box of Windows Subsystem for Linux option. And after that click on the OK button.

Windows subsystem for Linux

Step 3: Open the Microsoft Store 

To open the App store of Microsoft for Windows click on the search box and type Microsoft store. The moment it will appear, click on that.

Linux apps for windows

Step 4: Install Ubuntu 18.04 on Windows 10

Now search for the Ubuntu and install the latest version which is 18.04. As soon as it appears, you will see GET button, click on that and install it on your Windows 10. After the installation, you will see a launch button, use that to open the Ubuntu Bash. You can install any other Linux system such as Debian, Kali Linux, and OpenSuSE to install the Ansible.

Ubuntu 18.04 on windows


Step 5: Set the credentials 

When the Ubuntu Bash opens, it will ask you to set the username and password for default user of your Ubuntu on Windows. We can also set the root account password from here. Just type sudo passwd root

Sudo password

Step 6: Install Ansible on Windows

For installing and running Ansible on Windows just use the below-given commands:

sudo apt-get update
sudo apt-get install software-properties-common
sudo apt-add-repository ppa:ansible/ansible
sudo apt-get update
sudo apt-get install ansible

Note: For older Ubuntu versions such as Ubuntu 14.04, 15.04, and 16.04, we need to add the repo of Ansible but the latest version such as Ubuntu 18.04 can get the Ansible installation files directly from via its package management.

Press Y when it asks for…

Install Ansible on Windows

Step 7: Test Ansible on Windows

After the installation of Ansible, we will test it whether it is working or not. So, we create a demo playbook file for it.

Create a file called testbook.yml

nano testbook.yml

Now add the following lines into it and then exit and save the file.

- name: testing ansible
hosts: localhost


tasks:
- name: echo a message
debug: msg="this is working"

Creating demo playbook for Ansible

Step 8: Now run the ansible command to check whether it is working or not.

The command is:

ansible playbook testbook.yml --connection=local

Note: We are pointing the ansible to localhost because we want to test the file present on localhost.

It will prompt a message the mentioned host file is empty. So, in the next, we will also give it some demo inventory file.

Testing ansible on Windows 10

Step 9: Create a demo inventory for Ansible

Create a file with any name you want, we are using ‘inventory’. So, the command is:

nano inventory

Now add the following lines into it… Here we are adding some random non-existing demo domains in a group of localhost in the file for testing purpose.

[testing]
localhost
test.domain.tld
test.domain.tld

inventory

Step 10: Run the Ansible command with inventory

This time again we run the same command above but with inventory file available

ansible playbook -i inventory testbook.yml --connection=local

This time you will see that it will not be going to show any error.

Inventory demo

So, in this way, we can install the Ansible on Windows 10 for testing and other purposes.

Other Useful Resources:

7 thoughts on “How to Install Ansible on Windows 10”

  1. Thanks for the article it was helpful.

    The text “ansible playbook testbook.yml…” in a couple of your steps needs to be “ansible-playbook” which is what is in your screen shots.

    Reply
  2. the typical user will need to sudo apt-get install gpg to get the ansible installed.

    the hyphen between “ansible” and “playbook” is missing in a few spots.

    the spaces are wrong in the testbook.yml. Just make sure they match the screenshot, not the text.

    Finally, for you Windows WSL users (I assume most of us, given the title of this article) you may need to check your shell can find python. Do this by typing “which python”. If nothing returns, then check for ‘python3’ in /usr/bin and create a (symbolic) link to ‘python’ (and make sure, natch, that /usr/bin is in the $PATH string!)

    Thanks for this tutorial. Despite a smattering of small issues (instructive, actually…) it was helpful.

    Reply
  3. I am getting an error as below. Pls can you help ?
    [email protected]:~$ ansible-playbook testbook.yml
    [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match
    ‘all’

    PLAY [testing ansible] *************************************************************************************************
    TASK [Gathering Facts] *************************************************************************************************fatal: [localhost]: UNREACHABLE! => {“changed”: false, “msg”: “Authentication or permission failure. In some cases, you may have been able to authenticate and did not have permissions on the target directory. Consider changing the remote tmp path in ansible.cfg to a path rooted in \”/tmp\”. Failed command was: ( umask 77 && mkdir -p \”` echo /home/asreevas/.ansible/tmp/ansible-tmp-1587796943.5455377-278010171972276 `\” && echo ansible-tmp-1587796943.5455377-278010171972276=\”` echo /home/asreevas/.ansible/tmp/ansible-tmp-1587796943.5455377-278010171972276 `\” ), exited with result 1, stdout output: ansible-tmp-1587796943.5455377-278010171972276=/home/asreevas/.ansible/tmp/ansible-tmp-1587796943.5455377-278010171972276\n”, “unreachable”: true}

    PLAY RECAP *************************************************************************************************************localhost : ok=0 changed=0 unreachable=1 failed=0 skipped=0 rescued=0 ignored=0

    [email protected]:~$ sudo ansible-playbook testbook.yml
    [sudo] password for asreevas:
    [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match
    ‘all’

    PLAY [testing ansible] *************************************************************************************************
    TASK [Gathering Facts] *************************************************************************************************fatal: [localhost]: UNREACHABLE! => {“changed”: false, “msg”: “Authentication or permission failure. In some cases, you may have been able to authenticate and did not have permissions on the target directory. Consider changing the remote tmp path in ansible.cfg to a path rooted in \”/tmp\”. Failed command was: ( umask 77 && mkdir -p \”` echo /root/.ansible/tmp/ansible-tmp-1587796981.4551828-266141934832303 `\” && echo ansible-tmp-1587796981.4551828-266141934832303=\”` echo /root/.ansible/tmp/ansible-tmp-1587796981.4551828-266141934832303 `\” ), exited with result 1, stdout output: ansible-tmp-1587796981.4551828-266141934832303=/root/.ansible/tmp/ansible-tmp-1587796981.4551828-266141934832303\n”, “unreachable”: true}

    PLAY RECAP *************************************************************************************************************localhost : ok=0 changed=0 unreachable=1 failed=0 skipped=0 rescued=0 ignored=0

    [email protected]:~$ nano inventory
    [email protected]:~$ ls
    inventory testbook.yml
    [email protected]:~$ cat inventory
    [testng]
    localhost
    test.domain.tld
    test.domain.tld
    [email protected]:~$ cat testbook.yml
    – name: testing ansible
    hosts: localhost

    tasks:
    – name: echo a message
    debug: msg=”this is working”

    [email protected]:~$ sudo ansible-playbook -i inventory testbook.yml

    PLAY [testing ansible] *************************************************************************************************
    TASK [Gathering Facts] *************************************************************************************************fatal: [localhost]: UNREACHABLE! => {“changed”: false, “msg”: “Failed to connect to the host via ssh: ssh: connect to host localhost port 22: Connection refused”, “unreachable”: true}

    PLAY RECAP *************************************************************************************************************localhost : ok=0 changed=0 unreachable=1 failed=0 skipped=0 rescued=0 ignored=0

    [email protected]:~$ sudo ansible-playbook -i inventory testbook.yml –connection=local

    PLAY [testing ansible] *************************************************************************************************
    TASK [Gathering Facts] *************************************************************************************************fatal: [localhost]: UNREACHABLE! => {“changed”: false, “msg”: “Authentication or permission failure. In some cases, you may have been able to authenticate and did not have permissions on the target directory. Consider changing the remote tmp path in ansible.cfg to a path rooted in \”/tmp\”. Failed command was: ( umask 77 && mkdir -p \”` echo /root/.ansible/tmp/ansible-tmp-1587797207.8548028-244254564403779 `\” && echo ansible-tmp-1587797207.8548028-244254564403779=\”` echo /root/.ansible/tmp/ansible-tmp-1587797207.8548028-244254564403779 `\” ), exited with result 1, stdout output: ansible-tmp-1587797207.8548028-244254564403779=/root/.ansible/tmp/ansible-tmp-1587797207.8548028-244254564403779\n”, “unreachable”: true}

    Reply
    • Hey asree, just saw that you have the same issue as I had. You need to download/install the Ubuntu 18.04 LTS version app instead of the 20.04. With 18.04 LTS it works fine. Just use the Microsoft Store for Ubuntu 18.04 LTS. I think it has something to do with an invalid file at ppa:ansible/ansible in 20.04 – not sure, and had no time to investigate further… just saw an error message. With 18.04. LTS you should be fine for the next years.

      Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.