1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

update playbook docs with updated syntax / minor edits

This commit is contained in:
Michael DeHaan 2012-02-27 22:48:45 -05:00
parent 302cc37c79
commit 155c3ca89e
3 changed files with 43 additions and 30 deletions

View file

@ -29,24 +29,22 @@ be supported in the future.
EXAMPLE EXAMPLE
------- -------
FIXME: verify this is correct below
[literal] [literal]
--- ---
- pattern: '*' - pattern: '*'
hosts: '/etc/ansible/hosts' hosts: '/etc/ansible/hosts'
tasks: 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 action: setup http_port=80 max_clients=200
- name: write the apache config file - 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: notify:
- restart apache - restart apache
- name: ensure apache is running - name: ensure apache is running
action: service name=httpd ensure=started action: service name=httpd state=started
handlers: handlers:
- name: restart apache - name: restart apache
- action: service name=httpd ensure=restarted - action: service name=httpd state=restarted
WHAT THE EXAMPLE MEANS 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. on each remote system with the values max_clients and http_port.
Next, use a Jinja2 template locally residing at 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. 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 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 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 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 ansible module to use to accomplish the task, along with any
arguments. Additional fields like 'comment:' can be added and will 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. Most modules accept key=value format arguments.
Handlers are like tasks, but are conditionally executed. If a module 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. 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 If a host has a failure, the host will be ignored for the remainder
currently being refined and is subject to change. of the playbook execution.
AUTHOR AUTHOR

View file

@ -1,23 +1,15 @@
--- ---
- pattern: '*' - pattern: '*'
hosts: /etc/ansible/hosts hosts: '/etc/ansible/hosts'
tasks: tasks:
- name: config step - name: configure template & module variables for future template calls
action: setup a=2 b=3 c=4 action: setup http_port=80 max_clients=200
- name: copy comand - name: write the apache config file
action: copy src=/srv/a dest=/srv/b action: template src=/srv/httpd.j2 dest=/etc/httpd/conf
notify: notify:
- restart apache - restart apache
- name: template step - name: ensure apache is running
action: template src=/srv/template.j2 dest=/srv/file.out action: service name=httpd state=started
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: handlers:
- name: restart apache - name: restart apache
action: service name=httpd state=restarted - action: service name=httpd state=restarted

23
examples/playbook2.yml Normal file
View file

@ -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