This repository was archived by the owner on Feb 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathwordpress_installer.cf
257 lines (167 loc) · 6.28 KB
/
wordpress_installer.cf
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
#!/var/cfengine/bin/cf-agent -KIf
#Install WordPress:
# 1. Install Infrastructure:
# 1.1. Install httpd and mod_php and PHP MySQL client.
# 1.2. Install MySQL server.
# 1.2.1. Create WordPress User in MySQL.
# 1.2.2. Create WordPress Database in MySQL.
# 1.3. Make sure httpd and MySQL servers are running.
# 2. Install the PHP application (WordPress)
# 2.1. Download tarball with the latest version of WordPress PHP application.
# 2.2. Extract it into the httpd document root where it can be run by the Web server.
# 2.3. Create WordPress config file wp-config.php from wp-config-sample.php that's shipped with WordPress.
# 2.4. Tweak wp-config.php to put in the data needed to establish database connection (db name, db username and password).
#
body common control
{
bundlesequence => {
"packages_installed",
"services_up",
"wordpress_tarball_is_present",
"wordpress_tarball_is_unrolled",
"configuration_of_mysql_db_for_wordpress",
"wpconfig_exists",
"wpconfig_is_properly_configured",
"allow_http_inbound",
};
inputs => { "cfengine_stdlib.cf" };
}
#############################################
bundle agent packages_installed
{
vars: "desired_package" slist => {
"httpd",
"php",
"php-mysql",
"mysql-server",
};
packages: "$(desired_package)"
package_policy => "add",
package_method => yum,
classes => if_repaired("packages_added");
commands:
packages_added::
"/sbin/service httpd graceful"
comment => "Restarting httpd so it can pick up new modules.";
}
#############################################
bundle agent services_up {
processes:
"^mysqld" restart_class => "start_mysqld";
"^httpd" restart_class => "start_httpd";
commands:
start_mysqld::
"/etc/init.d/mysqld start";
start_httpd::
"/etc/init.d/httpd start";
}
#############################################
bundle agent wordpress_tarball_is_present
{
classes:
"wordpress_tarball_is_present" expression => fileexists("/root/wordpress-latest.tar.gz");
reports:
wordpress_tarball_is_present::
"WordPress tarball is on disk.";
commands:
!wordpress_tarball_is_present::
"/usr/bin/wget -q -O /root/wordpress-latest.tar.gz http://wordpress.org/latest.tar.gz"
comment => "Downloading latest version of WordPress.";
}
#############################################
bundle agent wordpress_tarball_is_unrolled
{
classes:
"wordpress_directory_is_present" expression => fileexists("/var/www/html/wordpress/");
reports:
wordpress_directory_is_present::
"WordPress directory is present.";
commands:
!wordpress_directory_is_present::
"/bin/tar -C /var/www/html -xvzf /root/wordpress-latest.tar.gz"
comment => "Unrolling wordpress tarball to /var/www/html/.";
}
#############################################
bundle agent configuration_of_mysql_db_for_wordpress
{
commands:
"/usr/bin/mysql -u root -e \"
CREATE DATABASE wordpress;
GRANT ALL PRIVILEGES ON wordpress.*
TO 'wordpress'@localhost
IDENTIFIED BY 'lopsa10linux';
FLUSH PRIVILEGES;
\"
";
}
#############################################
bundle agent wpconfig_exists
{
classes:
"wordpress_config_file_exists" expression =>
fileexists("/var/www/html/wordpress/wp-config.php");
reports:
wordpress_config_file_exists::
"WordPress config file /var/www/html/wordpress/wp-config.php is present";
!wordpress_config_file_exists::
"WordPress config file /var/www/html/wordpress/wp-config.php is not present";
commands:
!wordpress_config_file_exists::
"/bin/cp -p /var/www/html/wordpress/wp-config-sample.php \
/var/www/html/wordpress/wp-config.php";
}
#############################################
bundle agent wpconfig_is_properly_configured
{
files:
"/var/www/html/wordpress/wp-config.php"
edit_line => replace_default_wordpress_config_with_ours;
}
bundle edit_line replace_default_wordpress_config_with_ours
{
replace_patterns:
"database_name_here" replace_with => value("wordpress");
replace_patterns:
"username_here" replace_with => value("wordpress");
replace_patterns:
"password_here" replace_with => value("lopsa10linux");
}
#############################################
bundle agent allow_http_inbound
{
files:
redhat:: # tested on RHEL only, file location may vary based on Linux distro or OS
"/etc/sysconfig/iptables"
edit_line => insert_HTTP_allow_rule_before_the_accept_established_tcp_conns_rule,
comment => "insert HTTP allow rule into /etc/sysconfig/iptables",
classes => if_repaired("iptables_edited");
commands:
iptables_edited::
"/sbin/service iptables restart"
comment => "Restarting iptables to load new config";
}
bundle edit_line insert_HTTP_allow_rule_before_the_accept_established_tcp_conns_rule
{
vars:
"http_rule" string => "-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT";
insert_lines: "$(http_rule)",
location => before_the_accept_established_tcp_conns_rule;
}
body location before_the_accept_established_tcp_conns_rule
{
before_after => "before";
first_last => "first";
select_line_matching => "^-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT.*";
}
# Todo:
#
#
# MySQL:
# - submit a patch to the MySQL folks to add a non-interactive version of /usr/bin/mysql_secure_installation
# - secure mysql instance with a non-interactive version of /usr/bin/mysql_secure_installation once it is available
# - change the root password using /usr/bin/mysqladmin -u root password 'new-password'
# - secure mysql instance by: removing the test databases and anonymous user created by default
#
# httpd:
# - instead of hardcoding "/var/www/html", derive httpd document root on the fly from /etc/httpd/conf/httpd.conf
# DocumentRoot using Function readstringlist