From 155c3ca89e87ed29f81ad19aa7148011e9d2f54a Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Mon, 27 Feb 2012 22:48:45 -0500 Subject: [PATCH] update playbook docs with updated syntax / minor edits --- docs/man/man5/ansible-playbook.5.asciidoc | 26 +++++++++++------------ examples/playbook.yml | 24 +++++++-------------- examples/playbook2.yml | 23 ++++++++++++++++++++ 3 files changed, 43 insertions(+), 30 deletions(-) create mode 100644 examples/playbook2.yml diff --git a/docs/man/man5/ansible-playbook.5.asciidoc b/docs/man/man5/ansible-playbook.5.asciidoc index 6509dfd6c7..7804bd659a 100644 --- a/docs/man/man5/ansible-playbook.5.asciidoc +++ b/docs/man/man5/ansible-playbook.5.asciidoc @@ -29,24 +29,22 @@ be supported in the future. EXAMPLE ------- -FIXME: verify this is correct below - [literal] --- - pattern: '*' hosts: '/etc/ansible/hosts' tasks: - - name:configure template & module variables for future template calls + - name: configure template & module variables for future template calls action: setup http_port=80 max_clients=200 - name: write the apache config file - action: template src=/srv/mytemplates/httpd.j2 dest=/etc/httpd/conf + action: template src=/srv/templates/httpd.j2 dest=/etc/httpd/conf notify: - restart apache - name: ensure apache is running - action: service name=httpd ensure=started + action: service name=httpd state=started handlers: - name: restart apache - - action: service name=httpd ensure=restarted + - action: service name=httpd state=restarted WHAT THE EXAMPLE MEANS @@ -59,10 +57,10 @@ For all hosts in /etc/ansible/hosts (one host per line) that are named on each remote system with the values max_clients and http_port. Next, use a Jinja2 template locally residing at -/srv/mytemplates/httpd.j2 to write the Apache config file on each host +/srv/templates/httpd.j2 to write the Apache config file on each host to the path /etc/httpd/conf, using the previous values. -Ensure that apache is running if stopped. +We'll ensure that apache is running if stopped. 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 @@ -83,20 +81,20 @@ for all hosts in the host file matching the pattern. For each task, a name/action pair describes what the task is and what ansible module to use to accomplish the task, along with any arguments. Additional fields like 'comment:' can be added and will -be ignored. +be ignored, so feel free to take notes in the file. Most modules accept key=value format arguments. Handlers are like tasks, but are conditionally executed. If a module -reports a 'change', it can choose to notify a handler by name. If +reports a 'change', it can notify one or more handler by name. If notified, it will run only for hosts that changed. -FUTURE BEHAVIOR ---------------- +ERROR HANDLING +-------------- -What the playbook run does with a host when an error is detected is -currently being refined and is subject to change. +If a host has a failure, the host will be ignored for the remainder +of the playbook execution. AUTHOR diff --git a/examples/playbook.yml b/examples/playbook.yml index daf91a028b..f4a05e7778 100644 --- a/examples/playbook.yml +++ b/examples/playbook.yml @@ -1,23 +1,15 @@ --- - pattern: '*' - hosts: /etc/ansible/hosts + hosts: '/etc/ansible/hosts' tasks: - - name: config step - action: setup a=2 b=3 c=4 - - name: copy comand - action: copy src=/srv/a dest=/srv/b - notify: - - restart apache - - name: template step - action: template src=/srv/template.j2 dest=/srv/file.out + - name: configure template & module variables for future template calls + action: setup http_port=80 max_clients=200 + - name: write the apache config file + action: template src=/srv/httpd.j2 dest=/etc/httpd/conf notify: - restart apache - - name: execute bin false - comment: call something that will fail just to demo failure counts and such - action: command /bin/false - - name: execute bin true - comment: this will never be executed because previous will fail - action: command /bin/true + - name: ensure apache is running + action: service name=httpd state=started handlers: - name: restart apache - action: service name=httpd state=restarted + - action: service name=httpd state=restarted diff --git a/examples/playbook2.yml b/examples/playbook2.yml new file mode 100644 index 0000000000..daf91a028b --- /dev/null +++ b/examples/playbook2.yml @@ -0,0 +1,23 @@ +--- +- pattern: '*' + hosts: /etc/ansible/hosts + tasks: + - name: config step + action: setup a=2 b=3 c=4 + - name: copy comand + action: copy src=/srv/a dest=/srv/b + notify: + - restart apache + - name: template step + action: template src=/srv/template.j2 dest=/srv/file.out + notify: + - restart apache + - name: execute bin false + comment: call something that will fail just to demo failure counts and such + action: command /bin/false + - name: execute bin true + comment: this will never be executed because previous will fail + action: command /bin/true + handlers: + - name: restart apache + action: service name=httpd state=restarted