2012-02-23 19:17:24 +00:00
|
|
|
Ansible
|
|
|
|
=======
|
|
|
|
|
2012-02-24 06:13:21 +00:00
|
|
|
Ansible is a extra-simple tool/API for doing 'parallel remote things' over SSH -- whether
|
|
|
|
executing commands, running declarative 'modules', or executing larger 'playbooks' that
|
|
|
|
can serve as a configuration management or deployment system.
|
2012-02-23 19:17:24 +00:00
|
|
|
|
2012-02-24 02:47:31 +00:00
|
|
|
While [Func](http://fedorahosted.org/func), which I co-wrote,
|
|
|
|
aspired to avoid using SSH and have it's own daemon infrastructure,
|
|
|
|
Ansible aspires to be quite different and more minimal, but still able
|
|
|
|
to grow more modularly over time. This is based on talking to a lot of
|
|
|
|
users of various tools and wishing to eliminate problems with connectivity
|
|
|
|
and long running daemons, or not picking tool X because they preferred to
|
|
|
|
code in Y.
|
|
|
|
|
|
|
|
Why use Ansible versus something else? (Fabric, Capistrano, mCollective,
|
|
|
|
Func, SaltStack, etc?) It will have far less code, it will be more correct,
|
|
|
|
and it will be the easiest thing to hack on and use you'll ever see --
|
|
|
|
regardless of your favorite language of choice. Want to only code plugins
|
|
|
|
in bash or clojure? Ansible doesn't care. The docs will fit on one page
|
|
|
|
and the source will be blindingly obvious.
|
|
|
|
|
|
|
|
Design Principles
|
|
|
|
=================
|
2012-02-23 19:17:24 +00:00
|
|
|
|
2012-02-23 19:28:39 +00:00
|
|
|
* Dead simple setup
|
2012-02-23 19:40:17 +00:00
|
|
|
* Super fast & parallel by default
|
2012-02-23 19:28:39 +00:00
|
|
|
* No server or client daemons, uses existing SSHd
|
2012-02-23 19:40:17 +00:00
|
|
|
* No additional software required on client boxes
|
2012-02-24 02:47:31 +00:00
|
|
|
* Everything is self updating on the clients
|
|
|
|
* Plugins can be written in ANY language
|
|
|
|
* API usage is an equal citizen to CLI usage
|
|
|
|
* Can be controlled/installed/used as non-root
|
2012-02-23 19:17:24 +00:00
|
|
|
|
|
|
|
Requirements
|
|
|
|
============
|
|
|
|
|
2012-02-23 19:28:39 +00:00
|
|
|
For the server the tool is running from, *only*:
|
|
|
|
|
2012-02-23 19:40:17 +00:00
|
|
|
* python 2.6 -- or the 2.4/2.5 backport of the multiprocessing module
|
2012-02-24 09:35:51 +00:00
|
|
|
* PyYAML (install on 'overlord' if using playbooks)
|
2012-02-23 19:28:39 +00:00
|
|
|
* paramiko
|
2012-02-23 19:17:24 +00:00
|
|
|
|
2012-02-24 09:35:51 +00:00
|
|
|
Optional -- If you want to push templates, the nodes need:
|
|
|
|
|
|
|
|
* python-jinja2
|
|
|
|
|
2012-02-23 19:17:24 +00:00
|
|
|
Inventory file
|
|
|
|
==============
|
|
|
|
|
2012-02-27 03:51:23 +00:00
|
|
|
To use ansible you must have a list of hosts somewhere.
|
2012-02-23 19:40:17 +00:00
|
|
|
|
2012-02-24 02:47:31 +00:00
|
|
|
The default inventory file (-H) is /etc/ansible/hosts and is a list
|
2012-02-27 03:51:23 +00:00
|
|
|
of all hostnames to manage with ansible, one per line. These
|
2012-02-23 19:28:39 +00:00
|
|
|
can be hostnames or IPs
|
2012-02-23 19:17:24 +00:00
|
|
|
|
2012-02-23 21:07:10 +00:00
|
|
|
Example:
|
|
|
|
|
|
|
|
abc.example.com
|
|
|
|
def.example.com
|
|
|
|
192.168.10.50
|
|
|
|
192.168.10.51
|
|
|
|
|
2012-02-23 19:17:24 +00:00
|
|
|
This list is further filtered by the pattern wildcard (-P) to target
|
2012-02-23 21:07:10 +00:00
|
|
|
specific hosts. This is covered below.
|
2012-02-23 19:17:24 +00:00
|
|
|
|
2012-02-23 21:32:58 +00:00
|
|
|
You can organize groups of systems by having multiple inventory
|
|
|
|
files (i.e. keeping webservers different from dbservers, etc)
|
|
|
|
|
2012-02-27 03:51:23 +00:00
|
|
|
Massive Parallelism, Pattern Matching, and a Usage Example
|
|
|
|
==========================================================
|
2012-02-23 19:17:24 +00:00
|
|
|
|
2012-02-27 03:51:23 +00:00
|
|
|
Reboot all web servers in Atlanta, 10 at a time:
|
2012-02-23 19:40:17 +00:00
|
|
|
|
|
|
|
* ssh-agent bash
|
|
|
|
* ssh-add ~/.ssh/id_rsa.pub
|
2012-02-27 03:51:23 +00:00
|
|
|
* ansible -p "atlanta-web*" -f 10 -n command -a "/sbin/reboot"
|
2012-02-23 19:17:24 +00:00
|
|
|
|
2012-02-27 03:51:23 +00:00
|
|
|
File Transfer
|
|
|
|
=============
|
2012-02-25 06:00:37 +00:00
|
|
|
|
2012-02-27 03:51:23 +00:00
|
|
|
Ansible can SCP lots of files to lots of places in parallel.
|
2012-02-23 19:17:24 +00:00
|
|
|
|
2012-02-27 03:51:23 +00:00
|
|
|
* ansible -p "web-*.acme.net" -f 10 -n copy -a "/etc/hosts /tmp/hosts"
|
2012-02-23 19:17:24 +00:00
|
|
|
|
2012-02-27 03:51:23 +00:00
|
|
|
Templating
|
|
|
|
==========
|
2012-02-24 03:47:03 +00:00
|
|
|
|
2012-02-27 03:51:23 +00:00
|
|
|
JSON files can be placed for template metadata using Jinja2. Variables
|
|
|
|
placed by 'setup' can be reused between ansible runs.
|
2012-02-23 19:17:24 +00:00
|
|
|
|
2012-02-27 03:51:23 +00:00
|
|
|
* ansible -p "*" -n setup -a "ntp_server=192.168.1.1"
|
|
|
|
* ansible -p "*" -n template /srv/motd.j2 /etc/motd
|
|
|
|
* ansible -p "*" -n template /srv/foo.j2 /etc/foo
|
2012-02-23 21:07:10 +00:00
|
|
|
|
2012-02-27 03:51:23 +00:00
|
|
|
Git Deployments
|
|
|
|
===============
|
2012-02-23 21:07:10 +00:00
|
|
|
|
2012-02-27 03:51:23 +00:00
|
|
|
Deploy your webapp straight from git
|
2012-02-23 21:07:10 +00:00
|
|
|
|
2012-02-27 03:51:23 +00:00
|
|
|
* ansible -p "web*" -n git -a "repo=git://foo dest=/srv/myapp version=HEAD"
|
2012-02-23 19:17:24 +00:00
|
|
|
|
2012-02-27 03:51:23 +00:00
|
|
|
Take Inventory
|
|
|
|
==============
|
2012-02-23 19:17:24 +00:00
|
|
|
|
2012-02-27 03:51:23 +00:00
|
|
|
Run popular open-source data discovery tools across a wide number of hosts.
|
|
|
|
This is best used from API scripts.
|
2012-02-23 19:17:24 +00:00
|
|
|
|
2012-02-27 03:51:23 +00:00
|
|
|
* ansible -p "dbserver*" -n facter
|
|
|
|
* ansible -p "dbserver"" -n ohai
|
2012-02-23 19:28:39 +00:00
|
|
|
|
2012-02-27 03:51:23 +00:00
|
|
|
Other Modules
|
2012-02-23 21:07:10 +00:00
|
|
|
=============
|
|
|
|
|
2012-02-27 03:51:23 +00:00
|
|
|
See the library directory for lots of extras. There's also a manpage,
|
|
|
|
ansible-modules(5).
|
2012-02-23 21:32:58 +00:00
|
|
|
|
2012-02-24 04:26:16 +00:00
|
|
|
Playbooks
|
|
|
|
=========
|
|
|
|
|
2012-02-25 22:31:23 +00:00
|
|
|
Playbooks are particularly awesome. Playbooks can batch ansible commands
|
2012-02-27 03:51:23 +00:00
|
|
|
together, and can even fire off triggers when certain commands report changes.
|
|
|
|
They are the basis for a really simple configuration management system, unlike
|
|
|
|
any that already exist. Powerful, concise, but dead simple.
|
2012-02-25 22:31:23 +00:00
|
|
|
|
|
|
|
See examples/playbook.yml for what the syntax looks like.
|
|
|
|
|
|
|
|
To run a playbook:
|
|
|
|
|
|
|
|
ansible -r playbook.yml
|
|
|
|
|
2012-02-27 03:51:23 +00:00
|
|
|
Read ansible-playbook(5) for more details.
|
2012-02-24 04:26:16 +00:00
|
|
|
|
2012-02-23 19:17:24 +00:00
|
|
|
Future plans
|
|
|
|
============
|
|
|
|
|
2012-02-25 22:31:23 +00:00
|
|
|
* see github's issue tracker for what we're thinking about
|
2012-02-23 21:32:58 +00:00
|
|
|
|
|
|
|
License
|
|
|
|
=======
|
|
|
|
|
|
|
|
* MIT
|
2012-02-23 19:17:24 +00:00
|
|
|
|
2012-02-25 14:39:03 +00:00
|
|
|
Mailing List
|
|
|
|
============
|
|
|
|
|
2012-02-27 03:51:23 +00:00
|
|
|
* Join the mailing list to talk about Ansible!
|
2012-02-25 14:41:30 +00:00
|
|
|
* [ansible-project](http://groups.google.com/group/ansible-project)
|
2012-02-25 14:39:03 +00:00
|
|
|
|
2012-02-23 19:17:24 +00:00
|
|
|
Author
|
|
|
|
======
|
|
|
|
|
2012-02-24 02:47:31 +00:00
|
|
|
Michael DeHaan -- michael.dehaan@gmail.com
|
2012-02-23 19:28:39 +00:00
|
|
|
|
2012-02-24 02:47:31 +00:00
|
|
|
[http://michaeldehaan.net](http://michaeldehaan.net/)
|
2012-02-23 19:28:39 +00:00
|
|
|
|
|
|
|
|