-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathansible:lampstack
More file actions
229 lines (181 loc) · 5.43 KB
/
ansible:lampstack
File metadata and controls
229 lines (181 loc) · 5.43 KB
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
Using Ubuntu 18.04 Bionic
#>>>Make a directory ansible_playbook
#>>>Create a host file
vi hosts
insert the following:
---
[slave]
18.189.11.174
#>>>Create lampstack.yml file
vi lampstack.yml
insert the following:
---
-
name: configuring lamp
hosts: all
become: true
vars_files:
- vars/default.yml
#>>>mkdir roles and change directory to it
mkdir -p roles/apache (this creates an apache directory as well)
cd apache and mkdir handlers
cd handler and create a file main.yml
input the following:
---
-
name: reloading and restarting apache2
hosts: all
become: true
tasks:
- name: Reload Apache
service:
name: apache2
state: reloaded
- name: Restart Apache
service:
name: apache2
state: restarted
#>>>mkdir tasks and cd to tasks TASK
mkdir file in tasks and cd files
create a apache.conf.j2 file
insert the following:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName 18.189.11.174 (localhost_IP for slave)
ServerAlias www.18.189.11.174
DocumentRoot /var/www/18.189.11.174
ErrorLog $/var/log/apache2/error.log
CustomLog $/var/log/apache2/access.log combined
<Directory /var/www/18.189.11.174>
Options -Indexes
</Directory>
<IfModule mod_dir.c>
DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm </IfModule>
</VirtualHost>
#>>>create a file main.yml under the tasks directory
insert the following:
---
-
name: Setting up lamp stack
hosts: all
become: true
tasks:
- name: Install prerequisites
apt: name={{ item }} update_cache=yes state=latest force_apt_get=yes
loop: [ 'aptitude' ]
#Apache Configuration
- name: Install Apache and PHP Packages
apt: name={{ item }} update_cache=yes state=latest
loop: [ 'apache2', 'php', 'php-mysql', 'libapache2-mod-php' ]
- name: Create document root
file:
path: "/var/www/18.189.11.174"
state: directory
owner: "root"
mode: '0755'
- name: Set up Apache virtualhost
template:
src: "files/apache.conf.j2"
dest: "/etc/apache2/sites-available/18.189.11.174.conf"
# - name: Enable new site
#shell: /usr/sbin/18.189.11.174.conf
# - name: Disable default Apache site
#shell: /usr/sbin/18.189.11.174.default.conf
#when: disable_default
#notify: Reload Apache
# UFW Configuration
- name: "UFW - Allow HTTP on port 80"
ufw:
rule: allow
port: "80"
proto: tcp
# PHP Info Page
- name: Sets Up PHP Info Page
template:
src: "/root/ansible_playbook/roles/apache/tasks/templates/files/info.php.j2"
dest: "/var/www/html/info.php"
- name: Reload Apache
service:
name: apache2
state: reloaded
- name: Restart Apache
service:
name: apache2
state: restarted
#>>>create a templates directory under tasks dir in apache
cd templates
mkdir files inside templates dir
cd files
Create a info.php.j2 file
Insert the following:
<?php
phpinfo();
#>>>Back to the ansible_playbook, cd roles
mkdir mariadb and cd into it
mkdir tasks inside mariadb dir
create a main.yml file inside task in mariadb dir
vi main.yml
insert the following
---
-
name: Installing MariaDB server
hosts: all
become: true
tasks:
- name: Install prerequisites
apt: name={{ item }} update_cache=yes state=latest force_apt_get=yes
loop: [ 'aptitude' ]
#Install MariaDB server
- name: Install MariaDB Packages
apt: name={{ item }} update_cache=yes state=latest
loop: [ 'mariadb-server', 'python3-pymysql' ]
# Start MariaDB Service
- name: Start MariaDB service
service:
name: mariadb
state: started
#Install Python MySQLdb Module
- name: Install the Python MySQLB module
apt:
name: python-mysqldb
state: installed
- name: Create the flask database
mysql_db:
name: rootdb
state: present
login_user: root
# MariaDB Configuration
- name: Sets the root password
mysql_user:
name: root
password: "password"
login_unix_socket: /var/run/mysqld/mysqld.sock
- name: Removes all anonymous user accounts
mysql_user:
name: ''
host_all: yes
state: absent
login_user: root
login_password: "password"
- name: Removes the MySQL test database
mysql_db:
name: test
state: absent
login_user: root
login_password: "password"
#>>>Back to the ansible_playbook dir
mkdir vars
create a default.yml file
Insert the following:
---
mysql_root_password: "password"
app_user: "root"
http_host: "18.189.11.174.com" (http_host IP)
http_conf: "18.189.11.174.conf"
http_port: "80"
disable_default: true
#Run:
ansible-playbook main.yml in the tasks dir in apache dir
ansible-playbook main.yml in the tasks dir in mariadb dir
ansible-playbook lampstack.yml in the ansible_playbook main dir
ansible-playbook playbook.yml -l server1 -u sammy