We use [Ansible](https://www.ansible.com/) to configure our infrastructure, including the robots, the development environment and our web/git server. It is a tool that lets you write 'configuration as code' and track it in Git, so you can explicitly define and automate all configuration steps instead of relying on manual installations and configurations. The official [Ansible documentation](http://docs.ansible.com/ansible/index.html) is comprehensive and should be read, this page gives a quick introduction into usage and concepts relative to our use cases.
## Installation
Ansible is a Python package. There is a Ubuntu package, but you should use `pip` to make sure we use the same version. First create a Python virtual environment (read [instructions about virtual environments and installing `virtualenvwrapper` first](http://python-guide.readthedocs.io/en/latest/dev/virtualenvs/)):
mkvirtualenv bhboxes
Next install Ansible according to the requirements in the `boxes` repository:
cd path/to/boxes
pip install -r requirements.txt
## Inventories
With Ansible you can perform commands to be run against all machines
in a so called _inventory_. It does this by SSH-ing into the machines
and run the required commands. To be able to do this smoothly you
should set up password-less SSH for all accounts on all machines which
you want to configure with Ansible.
The inventory of boxes can be a simple text file listing IP-addresses
or host names. For instance:
echo '127.0.0.1' > inventory
One can then run a command for all boxes in `inventory` like:
ansible -i inventory all -m ping
An example is `darwin-inventory` in the `boxes` repository. Finally, you can also just give a comma separated list of hosts as inventory directly, where for a single host you still have to add a final comma:
ansible -i 163.172.138.188, -u root all -m ping
## Playbooks
In Ansible, a collection of commands and tasks can be put together
into _playbooks_, which describe the step-by-step set up and
configuration of a box. These playbooks are formatted in
[YAML](http://yaml.org). Our main playbook for the web/git server for instance is `site.yml`, which includes several other playbooks that link
boxes in the inventory to _roles_ that those boxes play. For instance,
a box can be a webserver, a git repository, a development environment,
et cetera. A box can have more than one role. The actual configuration
tasks and other settings or handlers for a role `role_x` are in
separate YAML files under `roles/role_x`.
A playbook is run with the `ansible-playbook` command: