mirror of https://github.com/ansible/ansible.git
Added examples of how roles work!
parent
892484812e
commit
f308194b9a
@ -0,0 +1,2 @@
|
|||||||
|
This is a file
|
||||||
|
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
- name: blippy
|
||||||
|
shell: echo notifier called, and the value of x is '{{ x }}'
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
- name: template operation
|
||||||
|
template: src=foo.j2 dest=/etc/motd
|
||||||
|
|
||||||
|
- action: shell echo 'hi webserver'
|
||||||
|
notify:
|
||||||
|
- blippy
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
- name: copy operation
|
||||||
|
copy: src=foo.txt dest=/tmp/roles_test1.txt
|
||||||
|
|
||||||
|
- name: template operation
|
||||||
|
template: src=foo.j2 dest=/tmp/roles_test2.txt
|
||||||
|
notify:
|
||||||
|
- blippy
|
||||||
@ -0,0 +1 @@
|
|||||||
|
I am a {{ ansible_os_family }} distribution.
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
---
|
||||||
|
x: '{{ ansible_machine }}'
|
||||||
|
|
||||||
@ -0,0 +1,39 @@
|
|||||||
|
# in Ansible 1.2 and later, roles allow easy best-practices organization of content
|
||||||
|
# and maximize shareability of ansible building blocks.
|
||||||
|
#
|
||||||
|
# suppose a playbook applied to a group of hosts includes two roles, foo and bar.
|
||||||
|
#
|
||||||
|
# what do roles do in this case?
|
||||||
|
#
|
||||||
|
# listing the roles as foo and bar will auto include the following:
|
||||||
|
#
|
||||||
|
# tasks from ./roles/foo/tasks/main.yml, then ./roles/bar/tasks/main.yml
|
||||||
|
# handlers from ./roles/foo/handlers/main.yml, then ./roles/bar/handlers/main.yml
|
||||||
|
# vars from ./roles/foo/vars/main.yml, then ./roles/bar/vars/main.yml
|
||||||
|
#
|
||||||
|
# should any of these files not exist, that is ok, and they will simply not be loaded.
|
||||||
|
#
|
||||||
|
# should the task file in foo/tasks/main.yml want to include subtasks in other files, that
|
||||||
|
# is also permitted.
|
||||||
|
#
|
||||||
|
# templates and copy operations also get smarter about where to look for content when using
|
||||||
|
# roles.
|
||||||
|
#
|
||||||
|
# as an example, a task in foo/tasks/main.yml could copy or template a file by
|
||||||
|
# referencing a "src=foo.j2" rather than having to explicitly path src=roles/foo/templates/foo.j2.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
- hosts: all
|
||||||
|
roles:
|
||||||
|
- foo
|
||||||
|
|
||||||
|
# add as many roles as you like, roles takes a list of roles names
|
||||||
|
# these paths can be qualified, but if bare, it will look from them in
|
||||||
|
# roles/$rolename relative to the playbook
|
||||||
|
#
|
||||||
|
# - bar
|
||||||
|
|
||||||
|
# explicit tasks and handlers can be used, but are not required.
|
||||||
|
# they will run after the roles if present.
|
||||||
|
|
||||||
Loading…
Reference in New Issue