2012-02-27 03:09:56 +01:00
|
|
|
---
|
2012-03-13 23:55:04 +01:00
|
|
|
# this is an annotated example of some features available in playbooks
|
|
|
|
# it shows how to make sure packages are updated, how to make sure
|
|
|
|
# services are running, and how to template files. It also demos
|
|
|
|
# change handlers that can restart things (or trigger other actions)
|
|
|
|
# when resources change. For more advanced examples, see example2.yml
|
|
|
|
|
|
|
|
# on all hosts, run as the user root...
|
|
|
|
|
2012-04-27 06:08:06 +02:00
|
|
|
- name: example play
|
|
|
|
hosts: all
|
2012-03-03 17:02:14 +01:00
|
|
|
user: root
|
2012-03-13 23:55:04 +01:00
|
|
|
|
2012-03-30 04:58:10 +02:00
|
|
|
# could have also have done:
|
|
|
|
# user: mdehaan
|
2012-12-14 11:56:53 +01:00
|
|
|
# sudo: yes
|
2012-03-30 04:58:10 +02:00
|
|
|
|
2012-03-13 23:55:04 +01:00
|
|
|
# make these variables available inside of templates
|
|
|
|
# for when we use the 'template' action/module later on...
|
|
|
|
|
2012-03-06 02:09:03 +01:00
|
|
|
vars:
|
|
|
|
http_port: 80
|
|
|
|
max_clients: 200
|
2012-03-13 23:55:04 +01:00
|
|
|
|
|
|
|
# define the tasks that are part of this play...
|
|
|
|
|
2012-02-24 05:54:16 +01:00
|
|
|
tasks:
|
2012-03-13 23:55:04 +01:00
|
|
|
|
|
|
|
# task #1 is to run an arbitrary command
|
|
|
|
# we'll simulate a long running task, wait for up to 45 seconds, poll every 5
|
|
|
|
# obviously this does nothing useful but you get the idea
|
|
|
|
|
|
|
|
- name: longrunner
|
2012-03-13 01:53:10 +01:00
|
|
|
action: command /bin/sleep 15
|
|
|
|
async: 45
|
|
|
|
poll: 5
|
2012-03-13 23:55:04 +01:00
|
|
|
|
|
|
|
# let's demo file operations.
|
|
|
|
#
|
|
|
|
# We can 'copy' files or 'template' them instead, using jinja2
|
2012-08-07 02:00:31 +02:00
|
|
|
# as the templating engine. This is done using the variables
|
|
|
|
# from the vars section above mixed in with variables bubbled up
|
|
|
|
# automatically from tools like facter and ohai. 'copy'
|
2012-03-13 23:55:04 +01:00
|
|
|
# works just like 'template' but does not do variable subsitution.
|
|
|
|
#
|
|
|
|
# If and only if the file changes, restart apache at the very
|
|
|
|
# end of the playbook run
|
|
|
|
|
|
|
|
- name: write some_random_foo configuration
|
2012-03-14 00:27:13 +01:00
|
|
|
action: template src=templates/foo.j2 dest=/etc/some_random_foo.conf
|
2012-02-25 20:42:41 +01:00
|
|
|
notify:
|
|
|
|
- restart apache
|
2012-03-13 23:55:04 +01:00
|
|
|
|
|
|
|
# make sure httpd is installed at the latest version
|
|
|
|
|
|
|
|
- name: install httpd
|
|
|
|
action: yum pkg=httpd state=latest
|
|
|
|
|
|
|
|
# make sure httpd is running
|
|
|
|
|
|
|
|
- name: httpd start
|
2012-03-16 04:10:03 +01:00
|
|
|
action: service name=httpd state=running
|
2012-03-13 23:55:04 +01:00
|
|
|
|
|
|
|
# handlers are only run when things change, at the very end of each
|
|
|
|
# play. Let's define some. The names are significant and must
|
|
|
|
# match the 'notify' sections above
|
|
|
|
|
2012-02-25 20:42:41 +01:00
|
|
|
handlers:
|
2012-03-13 23:55:04 +01:00
|
|
|
|
|
|
|
# this particular handler is run when some_random_foo.conf
|
|
|
|
# is changed, and only then
|
|
|
|
|
|
|
|
- name: restart apache
|
2012-03-14 00:27:13 +01:00
|
|
|
action: service name=httpd state=restarted
|
2012-03-13 23:55:04 +01:00
|
|
|
|
|
|
|
|