forked from jkupferer/bad-ansible-atos-2020-02-03
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.yml
154 lines (135 loc) · 3.39 KB
/
main.yml
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
---
# Bad ansible! This playbook is an example of poor/bad practices!
# Bad practices may include:
#
# Poor formatting and structure
# Poor use of YAML - but good enough to parse
# Inconsistent style
# Incorrect use of modules
# Poor module choice
# Unclear names
# Hard coding / poor use of variables
# Roles - what are roles?
# Bare variables
# No use of handlers
- name: configuration
hosts: all
gather_facts: true
become: true
tasks:
- name: Process common configuration
include_role:
name: three_tier_common
- name: Configure Frontends
include_role:
name: three_tier_frontend
when: "'frontends' in group_names"
- name: deploy tomcat
hosts: apps
gather_facts: false
become: true
tasks:
- name: install tomcat
package:
name: tomcat
state: latest
- name: enable tomcat at boot
service:
name: tomcat
enabled: yes
- name: create ansible tomcat directory
file:
path: /usr/share/tomcat/webapps/ROOT
state: directory
- name: copy static index.html to tomcat webapps/ansible/index.html
template:
src: index.html.j2
dest: /usr/share/tomcat/webapps/ROOT/index.html
mode: 0644
- name: start tomcat
service:
name: tomcat
state: started
- name: index.html on app 1
hosts: app1
gather_facts: false
become: true
tasks:
- name: create /usr/share/tomcat/webapps/ansible
file:
state: directory
path: /usr/share/tomcat/webapps/ansible
owner: root
group: root
mode: u=rwx,go=rx
- name: copy static index.html to tomcat webapps/ansible/index.html
template:
src: index.html.app1
dest: /usr/share/tomcat/webapps/ansible/index.html
- name: index.html on app 2
hosts: app2
gather_facts: false
become: true
tasks:
- name: create /usr/share/tomcat/webapps/ansible
file:
state: directory
path: /usr/share/tomcat/webapps/ansible
owner: root
group: root
mode: u=rwx,go=rx
- name: copy static index.html to tomcat webapps/ansible/index.html
template:
src: index.html.app2
dest: /usr/share/tomcat/webapps/ansible/index.html
- name: deploy postgres
gather_facts: false
become: true
hosts: appdbs
tasks:
- name: install progress
command: "yum install -y postgresql-server"
#- name: install postgres
# yum:
# name: postgresql-server
# state: latest
- name: enable apache at boot
service:
name: postgresql
enabled: yes
- name: tell user to finish setting up postgres
debug:
msg: "Either uncomment the postgres setup or manually login and initialize"
# only run the next 2 tasks once!
- name: initilize postgres
command: postgresql-setup initdb
register: r_postgres_initdb
failed_when:
- r_postgres_initdb.rc != 0
- r_postgres_initdb.stdout != 'Data directory is not empty!'
changed_when:
- r_postgres_initdb.rc == 0
# - name: initilize postgres some more
# command: chkconfig postgresql on
- name: start postgres
service:
name: postgresql.service
state: started
- name: deploy apache
hosts: apps
gather_facts: false
become: true
hosts: apps
tasks:
- name: install apache
yum:
name: httpd
state: latest
- name: enable apache at boot
service:
name: httpd
enabled: yes
# - name: start apache
# service:
# name: httpd
# state: started