Install Ansible on Windows Using Cygwin
1. Install Cygwin
Go to https://www.cygwin.com/install.html and download
setup-x86_64.exe Run it
- Select 'Install from Internet'
- Choose root directory (default)
- Choose pacakage directory to store installation files
- Use System Proxy Settings
- Select any mirror site to download
In 'Select Packages'
Categorydropdown and search for
- Go to
All -> Web -> lynx: A text-based Web Browser
- Select latest version
- Click next to complete installation
This is a package manager for cygwin
lynx -source rawgit.com/transcode-open/apt-cyg/master/apt-cyg > apt-cyg
install apt-cyg /bin
3. Install dependencies for ansible
To install altogether
apt-cyg install binutils curl gcc-core gmp libffi-devel libgmp-devel make python python-crypto python-openssl python-setuptools python-devel git nano openssh openssl openssl-devel
You can also install individually by using
apt-cyg installor by using the installation GUI
4. Install Ansible
pip install ansible -vvv
- Here, the
-vvvis used in case the install seems too slow. It will show you if everything is still working.
5. Test ansible
To test installation
- Should receive list of options
Cygwin comes with some strange default settings, particularly if using
set nocompatible set backspace=2
Run a playbook with Ansible
Make a new directory to test ansible with a simple playbook.
Ansible needs some configuration to work on a Windows machine. Our Windows machine is called the 'control' machine. Ansible does not officially support this.
Create an ansible configuration file.
Copy and paste the following into the file.
ssh_args = -o ControlMaster=no
Now we will create our ansible playbook to test.
Copy the following into the file.
- hosts: all sudo: yes tasks: - name: install apache2 apt: name=apache2 update_cache=yes state=latest
Bring up a virtual machine
We need a virtual machine to run this against. For this we will use a Vagrant box. Don't worry if you have not used Vagrant before. It is an easy way of installing virtual boxes on your machine and managing them.
We need a Vagrantfile to bring up our virtual machine.
Copy and paste the following.
Vagrant.configure("2") do | config| config.vm.box = "bento/ubuntu-18.04" config.vm.network "private_network", ip: "192.168.33.10" end
This will bring up a ubuntu virtual machine to run our ansible script against.
To bring up your virtual machine, make sure you are in the same directory as your Vagrantfile and type
Depending on your connection, this may take a little while to boot up.
Once your machine is booted (you can check if it was successfully booted by typing vagrant status), you need to make sure your control / Windows machine can connect to it.
Setup ssh connection
On your Cygwin terminal, generate an ssh -key.
Keep pressing enter until it is finished. Print out the .pub file where it saves the key. For example, mine looks like the following. Yours will be in the .ssh folder also.
Copy the value that is printed out. Now you need to go to your vagrant machine.
Go to the end of the file, go to the next line (by pressing enter) and paste in your key from the id_rsa.pub file
Exit your vagrant machine.
Test your ssh connection with the following.
You should be able to login to the virual machine without any prompt or failure.
Exit the machine once again.
Run your ansible playbook
Make sure you are in the same directory as your ansible script. Ideally, you have your Vagrantfile, playbook.yml and ansible.cfg all in the same directory.
Ensure ansible is ready to go.
Now type the following.
ansible-playbook -i firstname.lastname@example.org, playbook.yml
Your tasks should appear in a list. Once finished, the PLAY RECAP should have ok=2 and changed=1.
Congrats, you have just run your first ansible playbook!