CHAPTER 1 ■ GETTING STARTED
3
At the time of this writing, Ansible 2.1 has been released, and 2.2 is under active
development. The developers of Ansible have maintained backward compatibility
between version 1 and version 2 while adding some very useful functionality, such as
blocks (a way to catch errors during execution using try / catch ). Ansible 2.0 also supports
new playbook execution strategies, including standard linear execution and one that runs
a playbook as fast as possible.
Ansible uses YAML files as its main source of information at run time. YAML is a data
representation language that is commonly used for configuration. If you haven’t used
YAML, don’t worry. YAML files are really simple to write, and by the time you’ve created
one or two, you’ll have the hang of it. If you’ve ever used JSON or XML, you should feel right
at home; however, while JSON and XML aren’t very human friendly, YAML is very easy to
read and use. It does come with some quirks though, such as being whitespace sensitive.
Nonetheless, if you’ve ever written any Python code, this shouldn’t be an issue for you.
Which brings me to my next point — Ansible is written entirely in Python. The main
runner and all of the modules are Python 2.6 compatible, which means that they’ll work
with any version of Python2 above version 2.6. DeHaan choose Python for Ansible as it
meant that there would be no additional dependencies on the machines that you need to
manage. At this point in time, most other common configuration management systems
require you to install Ruby.
Not only are there no additional language dependencies for your machines, but also
there are no additional dependencies at all. Ansible works by running commands via
SSH, so there’s no need to install any server software. This is a huge plus for two reasons :
1 . Your machines run your application without any CPU or
memory-hungry daemons running in the background.
2 . You get everything that SSH provides for free. You can use
advanced features, such as ControlPersist, Kerberos, and
jump hosts. In addition, there is no need to roll your own
authentication mechanism — you can let SSH take care
of it for you!
Puppet, Chef, and Other Configuration Management
Tools
CFEngine was the original configuration management system. However, most people
nowadays compare Ansible to tools such as Puppet and Chef , which are most commonly
used today. Puppet and Chef are more similar to each other than they are to Ansible, but they
can perform the same functions. While Puppet and Chef each use a central server to store
the desired state of machines and any metadata associated with them, Ansible doesn’t have
any central server at all (making it agentless). This is important, as when using tools such as
Puppet and Chef each server will check in periodically with the central server to see if there
are any updates. Ansible relies entirely on the end user pushing out the changes themselves.
Ansible more closely resembles a tool called SaltStack (Salt), which also uses YAML
files for configuration and is also written in Python. Both Ansible and Salt are built primarily
as execution engines, where your system definition is just a list of commands to run,
abstracted behind reusable modules that provide an idempotent interface to your servers.
Thanks to most of Ansible’s modules and Salt’s state modules being idempotent, both tools
can be used to define the state of a machine before the tool will run and enforce that state.