2016 Update: If you are using Windows 10 or later, check out my newer instructions for Using Ansible through Windows 10's Subsystem for Linux.
Ansible is a simple and powerful infrastructure and configuration management tool that Server Check.in uses to manage it's infrastructure. Installing and using Ansible on Mac OS X or Linux workstations is incredibly easy, and takes all of 30 seconds to set up.
Running Ansible commands from within Windows is unsupported at the time of this writing. According to the CTO of AnsibleWorks, only windows servers as endpoints (not as hosts for controlling other servers via Ansible) are on the roadmap for future support... That said, if the idea of running a Linux VM on your Windows workstation (with something like the free VirtualBox app) just to run Ansible is unsettling, you can still use Ansible within Windows, if you run it within Cygwin.
Here are steps to getting Ansible (and it's related commands, like
ansible-playbook) running on Windows:
Download and install Cygwin, with at least the following packages selected (you can select the packages during the install process):
- python (2.7.x)
- git (1.7.x)
If you are working behind a proxy (as is the case in many corporate networks), edit the .bash_profile used by Cygwin either using vim (open Cygwin and enter
vim .bash_profile), or with whatever editor you'd like, and add in lines like the following:
- Open Cygwin
- Download PyYAML:
curl -O https://pypi.python.org/packages/source/P/PyYAML/PyYAML-3.10.tar.gz
- Download Jinja2:
curl -O https://pypi.python.org/packages/source/J/Jinja2/Jinja2-2.6.tar.gz
- Untar both downloads:
tar -xvf PyYAML-3.10.tar.gz && tar -xvf Jinja2-2.6.tar.gz
- Change directory into each of the expanded folders and run
python setup.py installto install each package.
- Generate an SSH key for use later:
ssh-keygen, then hit enter to skip adding a password until you get back to the command prompt.
- Clone ansible from its repository on GitHub:
git clone https://github.com/ansible/ansible /opt/ansible
- If you'd like to work from a particular Ansible version (like 2.0.1, current as of this writing), change directory into
/opt/ansibleand checkout the correct tag:
git checkout v2.0.1(some users have also reported success with the tag `v2_final`).
Add the following lines into your Cygwin .bash_profile (like you did the proxy settings—if you're behind one—in step 2):
# Ansible settings<br />
export PATH=$PATH:$ANSIBLE/bin<br />
export PYTHONPATH=$ANSIBLE/lib<br />
export ANSIBLE_LIBRARY=$ANSIBLE/library<br />
At this point, you should be able to run ansible commands via Cygwin (once you restart, or enter
source ~/.bash_profileto pick up the settings you just added). Try
ansible --versionto display Ansible's version.
If you would like to use Ansible as a provisioner for Vagrant, you can try, but after a day's worth of frustration (to the point of trying to add custom .bat files, changing Windows' and Linux' %PATH%/$PATH multiple times, and doing a hundred other things besides), I would recommend using Linux or a Mac to use Vagrant + Ansible together, or you could also use something like my JJG-Ansible-Windows shell provisioning script to run Ansible from within the VM itself.
Note: It may also be possible to run Ansible more easily using a bootstrap like Ansible Babun Bootstrap, but the experience of using Ansible on Windows will still be sub-par (but at least easier!).
I have written much more on how to use Ansible, whether you use Windows, Linux, or Mac OS X, in much greater detail, in Ansible for DevOps!