2012-03-13 23:27:13 +00:00
|
|
|
---
|
2012-03-20 02:42:31 +00:00
|
|
|
# this is a demo of conditional imports. This is a powerful concept
|
|
|
|
# and can be used to use the same recipe for different types of hosts,
|
|
|
|
# based on variables that bubble up from the hosts from tools such
|
|
|
|
# as ohai or facter.
|
|
|
|
#
|
|
|
|
# Here's an example use case:
|
|
|
|
#
|
|
|
|
# what to do if the service for apache is named 'httpd' on CentOS
|
|
|
|
# but is named 'apache' on Debian?
|
|
|
|
|
|
|
|
|
|
|
|
# there is only one play in this playbook, it runs on all hosts
|
|
|
|
# as root
|
2012-03-13 23:27:13 +00:00
|
|
|
|
|
|
|
- hosts: all
|
|
|
|
user: root
|
2012-03-20 02:42:31 +00:00
|
|
|
|
|
|
|
# we have a common list of variables stored in /vars/external_vars.yml
|
|
|
|
# that we will always import
|
|
|
|
|
|
|
|
# next, we want to import files that are different per operating system
|
|
|
|
# and if no per operating system file is found, load a defaults file.
|
|
|
|
# for instance, if the OS was "CentOS", we'd try to load vars/CentOS.yml.
|
|
|
|
# if that was found, we would immediately stop. However if that wasn't
|
|
|
|
# present, we'd try to load vars/defaults.yml. If that in turn was not
|
|
|
|
# found, we would fail immediately, because we had gotten to the end of
|
|
|
|
# the list without importing anything.
|
|
|
|
|
|
|
|
vars_files:
|
|
|
|
|
|
|
|
|
|
|
|
- "vars/external_vars.yml"
|
|
|
|
|
|
|
|
- [ "vars/$facter_operatingsystem.yml", "vars/defaults.yml" ]
|
|
|
|
|
|
|
|
# and this is just a regular task line from a playbook, as we're used to.
|
|
|
|
# but with variables in it that come from above. Note that the variables
|
|
|
|
# from above are *also* available in templates
|
2012-08-07 00:00:31 +00:00
|
|
|
|
2012-03-13 23:27:13 +00:00
|
|
|
tasks:
|
2012-03-20 02:42:31 +00:00
|
|
|
|
|
|
|
- name: ensure apache is latest
|
|
|
|
action: $packager pkg=$apache state=latest
|
2012-03-13 23:27:13 +00:00
|
|
|
- name: ensure apache is running
|
2012-03-20 02:42:31 +00:00
|
|
|
action: service name=$apache state=running
|
2012-03-21 02:29:21 +00:00
|
|
|
- name: fail
|
|
|
|
action: command /bin/false
|
|
|
|
|
2012-08-07 00:00:31 +00:00
|
|
|
|
2012-03-20 02:42:31 +00:00
|
|
|
|