2012-02-27 02:47:22 +01:00
|
|
|
ansible-modules(5)
|
|
|
|
=================
|
|
|
|
:doctype:manpage
|
|
|
|
:man source: Ansible-playbook
|
|
|
|
:man version: 0.0.1
|
|
|
|
:man manual: System administration commands
|
|
|
|
|
|
|
|
|
|
|
|
NAME
|
|
|
|
----
|
|
|
|
ansible-playbook - format and function of an ansible playbook file
|
|
|
|
|
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
-----------
|
|
|
|
|
2012-02-29 04:10:58 +01:00
|
|
|
Ansible ships with 'ansible-playbook', a tool for running playbooks.
|
2012-02-27 03:09:56 +01:00
|
|
|
Playbooks can represent frequent tasks, desired system configurations,
|
|
|
|
or deployment processes.
|
2012-02-27 02:47:22 +01:00
|
|
|
|
|
|
|
|
|
|
|
FORMAT
|
|
|
|
------
|
|
|
|
|
2012-02-29 04:10:58 +01:00
|
|
|
Playbooks are written in YAML.
|
2012-02-27 02:47:22 +01:00
|
|
|
|
|
|
|
|
|
|
|
EXAMPLE
|
|
|
|
-------
|
|
|
|
|
2012-03-03 20:13:31 +01:00
|
|
|
see
|
|
|
|
|
|
|
|
https://github.com/mpdehaan/ansible/blob/master/examples/playbook.yml
|
|
|
|
|
|
|
|
https://github.com/mpdehaan/ansible/blob/master/examples/base.yml
|
|
|
|
|
|
|
|
https://github.com/mpdehaan/ansible/blob/master/examples/handlers.yml
|
2012-02-27 02:47:22 +01:00
|
|
|
|
|
|
|
WHAT THE EXAMPLE MEANS
|
|
|
|
-----------------------
|
|
|
|
|
2012-03-03 20:13:31 +01:00
|
|
|
Here's what playbook.yml (above) will do.
|
|
|
|
|
|
|
|
The first pattern will select all hosts. The patterns are the same
|
|
|
|
as supported by /usr/bin/ansible.
|
|
|
|
|
|
|
|
First, it will run all the modules specified in base.yml. Includes can
|
|
|
|
be used to implement classes of things, and if you wanted, a playbook
|
|
|
|
could consist of nothing but include files. This is an example of an
|
|
|
|
include.
|
|
|
|
|
|
|
|
After processing base.yml, on each host we'll write for
|
|
|
|
a JSON file into /etc/ansible/setup on each remote system with the
|
|
|
|
values max_clients and http_port.
|
2012-02-27 02:47:22 +01:00
|
|
|
|
2012-03-03 20:13:31 +01:00
|
|
|
Next, we'll use a Jinja2 template locally residing at
|
|
|
|
/srv/templates/httpd.j2 to write the Apache config file on each host,
|
|
|
|
using the previous values in that setup file.
|
2012-02-27 02:47:22 +01:00
|
|
|
|
2012-03-03 20:13:31 +01:00
|
|
|
Next, We'll ensure that apache is running if stopped.
|
2012-02-27 02:47:22 +01:00
|
|
|
|
2012-03-03 20:13:31 +01:00
|
|
|
The template task set up a notifier, which means if the configuration
|
|
|
|
file actually changed, we have a named handler, in this case, 'restart apache'
|
|
|
|
to run. In this case, all the notifiers come from handlers.yml, though it's
|
|
|
|
also ok to express handlers directly in the main yaml file too. Using
|
|
|
|
the include promotes reuse.
|
2012-02-27 02:47:22 +01:00
|
|
|
|
2012-03-03 20:13:31 +01:00
|
|
|
What does the handler say? If and only if the config file changed, note that we need to restart
|
2012-02-27 03:09:56 +01:00
|
|
|
apache at the end of the run, otherwise, don't bother because we
|
|
|
|
already know it is running.
|
2012-02-27 02:47:22 +01:00
|
|
|
|
|
|
|
|
|
|
|
HIGH LEVEL EXPLANATION
|
|
|
|
----------------------
|
|
|
|
|
2012-02-27 03:09:56 +01:00
|
|
|
Playbooks are executed top down and can contain multiple references to
|
|
|
|
patterns. For instance, a playbook could do something to all
|
|
|
|
webservers, then do something to all database servers, then do
|
|
|
|
something different to all webservers again.
|
2012-02-27 02:47:22 +01:00
|
|
|
|
2012-02-27 03:09:56 +01:00
|
|
|
For each pattern, the tasks in the 'tasks' list are executed in order
|
|
|
|
for all hosts in the host file matching the pattern.
|
2012-02-27 02:47:22 +01:00
|
|
|
|
2012-02-27 04:31:42 +01:00
|
|
|
For each task, a name/action pair describes what the task is and what
|
2012-02-27 03:09:56 +01:00
|
|
|
ansible module to use to accomplish the task, along with any
|
2012-02-27 04:31:42 +01:00
|
|
|
arguments. Additional fields like 'comment:' can be added and will
|
2012-02-28 04:48:45 +01:00
|
|
|
be ignored, so feel free to take notes in the file.
|
2012-02-27 02:47:22 +01:00
|
|
|
|
|
|
|
Most modules accept key=value format arguments.
|
|
|
|
|
2012-02-27 03:09:56 +01:00
|
|
|
Handlers are like tasks, but are conditionally executed. If a module
|
2012-02-28 04:48:45 +01:00
|
|
|
reports a 'change', it can notify one or more handler by name. If
|
2012-02-27 03:09:56 +01:00
|
|
|
notified, it will run only for hosts that changed.
|
2012-02-27 02:47:22 +01:00
|
|
|
|
|
|
|
|
2012-02-28 04:48:45 +01:00
|
|
|
ERROR HANDLING
|
|
|
|
--------------
|
2012-02-27 02:47:22 +01:00
|
|
|
|
2012-02-28 04:48:45 +01:00
|
|
|
If a host has a failure, the host will be ignored for the remainder
|
|
|
|
of the playbook execution.
|
2012-02-27 02:47:22 +01:00
|
|
|
|
|
|
|
|
|
|
|
AUTHOR
|
|
|
|
------
|
|
|
|
|
|
|
|
Ansible was originally written by Michael DeHaan. See the AUTHORS file
|
|
|
|
for a complete list of contributors.
|
|
|
|
|
|
|
|
|
|
|
|
SEE ALSO
|
|
|
|
--------
|
|
|
|
|
2012-02-27 03:03:18 +01:00
|
|
|
*ansible*(1)
|
2012-02-27 02:47:22 +01:00
|
|
|
|
2012-03-05 05:08:29 +01:00
|
|
|
*ansible-modules*(5)
|
2012-02-27 02:47:22 +01:00
|
|
|
|
|
|
|
Ansible home page: <https://github.com/mpdehaan/ansible/>
|