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-27 03:09:56 +01:00
|
|
|
Ansible ships with a ansible-playbook tool for running playbooks.
|
|
|
|
Playbooks can represent frequent tasks, desired system configurations,
|
|
|
|
or deployment processes.
|
2012-02-27 02:47:22 +01:00
|
|
|
|
|
|
|
|
|
|
|
FORMAT
|
|
|
|
------
|
|
|
|
|
2012-02-27 03:09:56 +01:00
|
|
|
Playbooks are currently writeable in YAML. Other formats (JSON?) may
|
|
|
|
be supported in the future.
|
2012-02-27 02:47:22 +01:00
|
|
|
|
|
|
|
|
|
|
|
EXAMPLE
|
|
|
|
-------
|
|
|
|
|
2012-02-28 05:42:15 +01:00
|
|
|
[source,yaml]
|
|
|
|
----
|
2012-02-27 02:47:22 +01:00
|
|
|
- pattern: '*'
|
|
|
|
hosts: '/etc/ansible/hosts'
|
|
|
|
tasks:
|
2012-02-28 04:48:45 +01:00
|
|
|
- name: configure template & module variables for future template calls
|
2012-02-27 04:31:42 +01:00
|
|
|
action: setup http_port=80 max_clients=200
|
|
|
|
- name: write the apache config file
|
2012-02-28 04:48:45 +01:00
|
|
|
action: template src=/srv/templates/httpd.j2 dest=/etc/httpd/conf
|
2012-02-27 02:47:22 +01:00
|
|
|
notify:
|
|
|
|
- restart apache
|
2012-02-27 04:31:42 +01:00
|
|
|
- name: ensure apache is running
|
2012-02-28 04:48:45 +01:00
|
|
|
action: service name=httpd state=started
|
2012-02-27 02:47:22 +01:00
|
|
|
handlers:
|
2012-02-27 04:31:42 +01:00
|
|
|
- name: restart apache
|
2012-02-28 04:48:45 +01:00
|
|
|
- action: service name=httpd state=restarted
|
2012-02-28 05:42:15 +01:00
|
|
|
----
|
2012-02-27 02:47:22 +01:00
|
|
|
|
|
|
|
|
|
|
|
WHAT THE EXAMPLE MEANS
|
|
|
|
-----------------------
|
|
|
|
|
|
|
|
Here's what the above example will do.
|
|
|
|
|
2012-02-27 03:09:56 +01:00
|
|
|
For all hosts in /etc/ansible/hosts (one host per line) that are named
|
|
|
|
'webserver-anything', first write 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-02-27 03:09:56 +01:00
|
|
|
Next, use a Jinja2 template locally residing at
|
2012-02-28 04:48:45 +01:00
|
|
|
/srv/templates/httpd.j2 to write the Apache config file on each host
|
2012-02-27 02:47:22 +01:00
|
|
|
to the path /etc/httpd/conf, using the previous values.
|
|
|
|
|
2012-02-28 04:48:45 +01:00
|
|
|
We'll ensure that apache is running if stopped.
|
2012-02-27 02:47:22 +01:00
|
|
|
|
2012-02-27 03:09:56 +01:00
|
|
|
If and only if the config file changed, note that we need to restart
|
|
|
|
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-02-27 03:03:18 +01:00
|
|
|
*ansible-playbook*(5) - pending
|
2012-02-27 02:47:22 +01:00
|
|
|
|
|
|
|
Ansible home page: <https://github.com/mpdehaan/ansible/>
|