If you are using a 64 bit version of Windows 10 and a version later than Build 1607, you can install the Linux Subsystem and use Ansible from it.
Check if it’s 64 bit:
run msinfo from a command prompt and check the below details:
Recommendation is to install all the windows updates prior to the installation of Linux Subsystem.
Installation of Linux Subsystem for Windows:
Control Panel – Programs and Features – Turn Windows features on or off
Check Windows Subsystem for Linux
Reboot after installation
You can also enable WSL using Powershell:
1 |
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux |
After Reboot download the Ubuntu distro for WSL, Open a CMD prompt and type:
1 2 3 4 5 |
C:\Users\dimos>curl.exe -L -o ubuntu-1604.appx https://aka.ms/wsl-ubuntu-1604 % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 100 192M 100 192M 0 0 8955k 0 0:00:22 0:00:22 --:--:-- 12.6M |
Locate the downloaded package and double click
Install the Package
When Installed, open a command prompt and type bash:
1 2 |
C:\Users\dimos>bash root@wsl01:/mnt/c/Users/dimos# |
It is not recommended to use the root password, therefore I created a normal user account with sudo rights.
So let’s install the prerequisites:
1 |
dimos@wsl01:/mnt/c/Users/dimos$ sudo apt-get -y install python-pip python-virtualenv libyaml-dev libffi-dev libssl-dev |
Check python is installed and version is 2.7.12:
1 2 3 4 5 6 |
dimos@wsl01:/mnt/c/Users/dimos$ python Python 2.7.12 (default, Nov 12 2018, 14:36:49) [GCC 5.4.0 20160609] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> dimos@wsl01:/mnt/c/Users/dimos$ |
Lets create a Virtual Environment and Activate it:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
dimos@wsl01:/mnt/c/Users/dimos$ sudo virtualenv venv27 [sudo] password for dimos: Running virtualenv with interpreter /usr/bin/python2 New python executable in /mnt/c/Users/dimos/venv27/bin/python2 Also creating executable in /mnt/c/Users/dimos/venv27/bin/python Installing setuptools, pkg_resources, pip, wheel...done. dimos@wsl01:/mnt/c/Users/dimos$ source venv27/bin/activate (venv27) dimos@wsl01:/mnt/c/Users/dimos$ (venv27) dimos@wsl01:/mnt/c/Users/dimos$ (venv27) dimos@wsl01:/mnt/c/Users/dimos$ which python /mnt/c/Users/dimos/venv27/bin/python (venv27) dimos@wsl01:/mnt/c/Users/dimos$ dimos@wsl01:/mnt/c/Users/dimos$ source venv27/bin/activate (venv27) dimos@wsl01:/mnt/c/Users/dimos$ (venv27) dimos@wsl01:/mnt/c/Users/dimos$ (venv27) dimos@wsl01:/mnt/c/Users/dimos$ which python /mnt/c/Users/dimos/venv27/bin/python (venv27) dimos@wsl01:/mnt/c/Users/dimos$ (venv27) dimos@wsl01:/mnt/c/Users/dimos$ which pip /mnt/c/Users/dimos/venv27/bin/pip (venv27) dimos@wsl01:/mnt/c/Users/dimos$ |
Let’s install git as we will need it to install Ansible from github:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
(venv27) dimos@wsl01:/mnt/c/Users/dimos$ sudo apt-get install git Reading package lists... Done Building dependency tree Reading state information... Done Suggested packages: git-daemon-run | git-daemon-sysvinit git-doc git-el git-email git-gui gitk gitweb git-arch git-cvs git-mediawiki git-svn The following packages will be upgraded: git 1 upgraded, 0 newly installed, 0 to remove and 190 not upgraded. Need to get 3,176 kB of archives. After this operation, 61.4 kB of additional disk space will be used. Get:1 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 git amd64 1:2.7.4-0ubuntu1.6 [3,176 kB] Fetched 3,176 kB in 1s (2,433 kB/s) (Reading database ... 33725 files and directories currently installed.) Preparing to unpack .../git_1%3a2.7.4-0ubuntu1.6_amd64.deb ... Unpacking git (1:2.7.4-0ubuntu1.6) over (1:2.7.4-0ubuntu1.1) ... Setting up git (1:2.7.4-0ubuntu1.6) ... |
and now let’s install Ansible from github repository:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
(venv27) dimos@wsl01:/mnt/c/Users/dimos$ pip install git+https://github.com/ansible/ansible Collecting git+https://github.com/ansible/ansible Cloning https://github.com/ansible/ansible to /tmp/pip-Wl3yn4-build Collecting jinja2 (from ansible===2.8.0.dev0) Downloading https://files.pythonhosted.org/packages/7f/ff/ae64bacdfc95f27a016a7bed8e8686763ba4d277a78ca76f32659220a731/Jinja2-2.10-py2.py3-none-any.whl (126kB) 100% |████████████████████████████████| 133kB 1.4MB/s Collecting PyYAML (from ansible===2.8.0.dev0) Collecting paramiko (from ansible===2.8.0.dev0) Downloading https://files.pythonhosted.org/packages/cf/ae/94e70d49044ccc234bfdba20114fa947d7ba6eb68a2e452d89b920e62227/paramiko-2.4.2-py2.py3-none-any.whl (193kB) 100% |████████████████████████████████| 194kB 2.8MB/s Collecting cryptography (from ansible===2.8.0.dev0) Downloading https://files.pythonhosted.org/packages/c3/c1/cf8665c955c9393e9ff0872ba6cd3dc6f46ef915e94afcf6e0410508ca69/cryptography-2.6.1-cp27-cp27mu-manylinux1_x86_64.whl (2.3MB) 100% |████████████████████████████████| 2.3MB 296kB/s Collecting MarkupSafe>=0.23 (from jinja2->ansible===2.8.0.dev0) Downloading https://files.pythonhosted.org/packages/fb/40/f3adb7cf24a8012813c5edb20329eb22d5d8e2a0ecf73d21d6b85865da11/MarkupSafe-1.1.1-cp27-cp27mu-manylinux1_x86_64.whl Collecting pyasn1>=0.1.7 (from paramiko->ansible===2.8.0.dev0) Downloading https://files.pythonhosted.org/packages/7b/7c/c9386b82a25115cccf1903441bba3cbadcfae7b678a20167347fa8ded34c/pyasn1-0.4.5-py2.py3-none-any.whl (73kB) 100% |████████████████████████████████| 81kB 2.3MB/s Collecting bcrypt>=3.1.3 (from paramiko->ansible===2.8.0.dev0) Downloading https://files.pythonhosted.org/packages/50/d8/95f7cb04344033bf9d1a12c5a7969a15999b6a710fbe1969c517333d9a62/bcrypt-3.1.6-cp27-cp27mu-manylinux1_x86_64.whl (59kB) 100% |████████████████████████████████| 61kB 1.9MB/s Collecting pynacl>=1.0.1 (from paramiko->ansible===2.8.0.dev0) Downloading https://files.pythonhosted.org/packages/b3/25/e605574f24948a8a53b497744e93f061eb1dbe7c44b6465fc1c172d591aa/PyNaCl-1.3.0-cp27-cp27mu-manylinux1_x86_64.whl (762kB) 100% |████████████████████████████████| 768kB 1.1MB/s Collecting enum34; python_version < "3" (from cryptography->ansible===2.8.0.dev0) Downloading https://files.pythonhosted.org/packages/c5/db/e56e6b4bbac7c4a06de1c50de6fe1ef3810018ae11732a50f15f62c7d050/enum34-1.1.6-py2-none-any.whl Collecting cffi!=1.11.3,>=1.8 (from cryptography->ansible===2.8.0.dev0) Downloading https://files.pythonhosted.org/packages/9d/6f/aea9f5559fb593da07ff34e67513bd62483b45715b4a5f5fae6a0a5792ea/cffi-1.12.2-cp27-cp27mu-manylinux1_x86_64.whl (413kB) 100% |████████████████████████████████| 419kB 1.6MB/s Collecting six>=1.4.1 (from cryptography->ansible===2.8.0.dev0) Downloading https://files.pythonhosted.org/packages/73/fb/00a976f728d0d1fecfe898238ce23f502a721c0ac0ecfedb80e0d88c64e9/six-1.12.0-py2.py3-none-any.whl Collecting asn1crypto>=0.21.0 (from cryptography->ansible===2.8.0.dev0) Downloading https://files.pythonhosted.org/packages/ea/cd/35485615f45f30a510576f1a56d1e0a7ad7bd8ab5ed7cdc600ef7cd06222/asn1crypto-0.24.0-py2.py3-none-any.whl (101kB) 100% |████████████████████████████████| 102kB 2.4MB/s Collecting ipaddress; python_version < "3" (from cryptography->ansible===2.8.0.dev0) Downloading https://files.pythonhosted.org/packages/fc/d0/7fc3a811e011d4b388be48a0e381db8d990042df54aa4ef4599a31d39853/ipaddress-1.0.22-py2.py3-none-any.whl Collecting pycparser (from cffi!=1.11.3,>=1.8->cryptography->ansible===2.8.0.dev0) Installing collected packages: MarkupSafe, jinja2, PyYAML, pyasn1, six, pycparser, cffi, bcrypt, enum34, asn1crypto, ipaddress, cryptography, pynacl, paramiko, ansible Running setup.py install for ansible ... done Successfully installed MarkupSafe-1.1.1 PyYAML-3.13 ansible-2.8.0.dev0 asn1crypto-0.24.0 bcrypt-3.1.6 cffi-1.12.2 cryptography-2.6.1 enum34-1.1.6 ipaddress-1.0.22 jinja2-2.10 paramiko-2.4.2 pyasn1-0.4.5 pycparser-2.19 pynacl-1.3.0 six-1.12.0 You are using pip version 8.1.1, however version 19.0.3 is available. You should consider upgrading via the 'pip install --upgrade pip' command. |
Ansible is now installed and we can test:
1 2 3 4 5 6 7 8 9 |
(venv27) dimoswsl@wsl01:/mnt/c/Users/dimos$ ansible all -i localhost, -c local -m ping localhost | SUCCESS => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": false, "ping": "pong" } |