This repository has been archived by the owner on Oct 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
bestpract-playbook.yaml
56 lines (40 loc) · 1.85 KB
/
bestpract-playbook.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
---
- name: Advanced Playbook Architecture
hosts: ghosthouse ## name of group in inventory
gather_facts: yes # to test try ansible all -m setup -i /path/to/hosts
connection: local ## pick your connection plugin
pre_tasks: #<-- these run first, followed by handler calls
# by default, ansible looks for the rollpath as...
# roles/ in the the relative local directory
# /etc/ansible/roles
# controlled in ansible.cfg
roles:
- bootstrap #<-- this role runs next
- bootstrap #<-- by default this will NOT run a second time
# to 'fix' make an entry in 'roles/bootstrap/meta/main.yml'
# allow_duplicates: true
- webserver #<-- this role runs after the first
tasks: #<-- this runs after roles, followed by handlers
- name: Print to the screen
debug:
msg: "Example of a task within the tasks section"
# default to import_role if you are unsure what to use
# if nothing else, syntax errors in your code will be caught
# when the playbook is run, instead of when the role is called
- import_role: #<-- STATIC(preprocessing) diff between
name: nginx # import and include
# is v poorly described by the concepts
# governing "dynamic" vs "static" imports
- include_role: #<-- DYNAMIC
name: "webserver-db-{{ webserverhostname | lower }}"
post_tasks: #<--- this runs after roles, followed by handlers
handlers: #<--- custom handlers called by pre_tasks, tasks, or post_tasks
# consider new plays as 'isolated' from the previous play
---
- name: A second play
hosts: all
gather_facts: yes
tasks:
- name: Print to the screen
debug:
msg: "This is a separate play, but think of it almost like running an entirely new playbook!"