2012-02-28 03:48:45 +00:00
|
|
|
---
|
2013-02-21 08:40:42 +00:00
|
|
|
# see intro_example.yml first!
|
2012-08-07 00:00:31 +00:00
|
|
|
# This file explains some more advanced features of playbooks.
|
2012-03-13 23:19:54 +00:00
|
|
|
# because of the comments it's less concise than it normally is. But feel
|
|
|
|
# free to comment your playbooks if you like.
|
|
|
|
|
2012-05-26 04:37:34 +00:00
|
|
|
- hosts: all
|
2012-03-13 23:19:54 +00:00
|
|
|
|
|
|
|
# we can define variables the normal way...
|
|
|
|
|
2012-03-06 01:09:03 +00:00
|
|
|
vars:
|
2012-03-13 23:19:54 +00:00
|
|
|
release: 2.0
|
|
|
|
|
|
|
|
# but they can also come from other files. This can be a relative
|
|
|
|
# or absolute path. This is a good way to store 'secret' variable
|
|
|
|
# files but still keep the playbook in public source control
|
|
|
|
|
|
|
|
vars_files:
|
2012-03-13 23:27:13 +00:00
|
|
|
- vars/external_vars.yml
|
2012-03-13 23:19:54 +00:00
|
|
|
|
|
|
|
# as with before, every play has a list of tasks in it
|
|
|
|
|
2012-02-28 03:48:45 +00:00
|
|
|
tasks:
|
2012-03-13 23:19:54 +00:00
|
|
|
|
|
|
|
# tasks can be written the normal way...
|
|
|
|
|
|
|
|
- name: arbitrary command
|
2012-02-28 03:48:45 +00:00
|
|
|
action: command /bin/true
|
2012-03-13 23:19:54 +00:00
|
|
|
|
|
|
|
# or we can promote reuse and simplicity by including tasks
|
|
|
|
# from other files, for instance, to reuse common tasks
|
|
|
|
|
2012-03-13 23:27:13 +00:00
|
|
|
- include: tasks/base.yml
|
2012-03-13 23:19:54 +00:00
|
|
|
|
|
|
|
# we could also have done something like:
|
|
|
|
# - include: wordpress.yml user=timmy
|
2012-08-07 00:00:31 +00:00
|
|
|
# and had access to the template variable $user in the
|
2012-03-13 23:19:54 +00:00
|
|
|
# included file, if we wanted to. Variables from vars
|
|
|
|
# and vars_files are also available inside include files
|
|
|
|
|
2012-02-28 03:48:45 +00:00
|
|
|
handlers:
|
2012-08-07 00:00:31 +00:00
|
|
|
|
2012-03-13 23:19:54 +00:00
|
|
|
# handlers can also be included from files, to promote reuse
|
|
|
|
# and simpler recipes, you may wish to only have one
|
2012-10-12 22:12:22 +00:00
|
|
|
# handler file for all your plays and playbooks. This example really
|
|
|
|
# doesn't notify any handlers, it is just showing you how they would
|
|
|
|
# be included (see intro_example for usage).
|
2012-03-13 23:19:54 +00:00
|
|
|
|
2012-03-13 23:27:13 +00:00
|
|
|
- include: handlers/handlers.yml
|
2012-03-13 23:19:54 +00:00
|
|
|
|
|
|
|
# you can mix things that are directly in the file with things
|
|
|
|
# that are included. Order is executed as written, but only
|
|
|
|
# handlers that have been notified get executed
|
|
|
|
|
|
|
|
- name: restart foo
|
|
|
|
action: service name=foo state=restarted
|
|
|
|
|
|
|
|
# ===============================================================
|
|
|
|
|
|
|
|
# Here's a second play in the same playbook. This will be run
|
|
|
|
# after the first playbook completes on all hosts. You may want
|
|
|
|
# a different play for each class of systems, or may want a different
|
|
|
|
# play for each stage in a complex multi-node deployment push
|
|
|
|
# process. How you use them are up to you.
|
|
|
|
|
|
|
|
# any play in a playbook can be executed by a user other than root
|
|
|
|
# if you want. sudo support is coming too.
|
|
|
|
|
|
|
|
- hosts: webservers
|
|
|
|
user: mdehaan
|
|
|
|
|
|
|
|
# vars must be specified again for the next play in the playbook
|
|
|
|
# but can be reused by including from vars_files if you want
|
|
|
|
# you can use vars, vars_files, or both. vars_files overrides
|
2012-08-07 00:00:31 +00:00
|
|
|
# those set in vars.
|
2012-03-13 23:19:54 +00:00
|
|
|
|
|
|
|
vars:
|
|
|
|
release: 2.0
|
|
|
|
vars_files:
|
2012-03-13 23:27:13 +00:00
|
|
|
- vars/external_vars.yml
|
2012-03-13 23:19:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
# these all runs as the user 'mdehaan'. If there were any handlers
|
|
|
|
# they would as well.
|
|
|
|
|
|
|
|
tasks:
|
|
|
|
|
|
|
|
- name: some random command
|
|
|
|
action: command /bin/true
|
|
|
|
|
|
|
|
|