-
Notifications
You must be signed in to change notification settings - Fork 1
/
playbook.yml
executable file
·149 lines (129 loc) · 4.05 KB
/
playbook.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
#########################################################
# DO Community Playbooks: Wordpress on Ubuntu 18.04 LAMP
#########################################################
---
- hosts: all
become: true
vars_files:
- vars/default.yml
tasks:
- name: Install prerequisites
apt: name=aptitude update_cache=yes state=latest force_apt_get=yes
tags: [ system ]
- name: Install LAMP Packages
apt: name={{ item }} update_cache=yes state=latest
loop: [ 'apache2', 'mysql-server', 'python3-pymysql', 'php', 'php-mysql', 'libapache2-mod-php' ]
tags: [ system ]
- name: Install PHP Extensions
apt: name={{ item }} update_cache=yes state=latest
loop: "{{ php_modules }}"
tags: [ system ]
# Apache Configuration
- name: Create document root
file:
path: "/var/www/{{ http_host }}"
state: directory
owner: "www-data"
group: "www-data"
mode: '0755'
tags: [ apache ]
- name: Set up Apache VirtualHost
template:
src: "files/apache.conf.j2"
dest: "/etc/apache2/sites-available/{{ http_conf }}"
notify: Reload Apache
tags: [ apache ]
- name: Enable rewrite module
shell: /usr/sbin/a2enmod rewrite
notify: Reload Apache
tags: [ apache ]
- name: Enable new site
shell: /usr/sbin/a2ensite {{ http_conf }}
notify: Reload Apache
tags: [ apache ]
- name: Disable default Apache site
shell: /usr/sbin/a2dissite 000-default.conf
notify: Restart Apache
tags: [ apache ]
# MySQL Configuration
# - name: Set the root password
# mysql_user:
# name: root
# password: "{{ mysql_root_password }}"
# login_unix_socket: /var/run/mysqld/mysqld.sock
# tags: [ mysql, mysql-root ]
# - name: Remove all anonymous user accounts
# mysql_user:
# name: ""
# host_all: yes
# state: absent
# login_user: root
# login_password: "{{ mysql_root_password }}"
# tags: [ mysql ]
#
# - name: Remove the MySQL test database
# mysql_db:
# name: test
# state: absent
# login_user: root
# login_password: "{{ mysql_root_password }}"
# tags: [ mysql ]
# - name: Creates database for WordPress
# mysql_db:
# name: "{{ mysql_db }}"
# state: present
# login_user: root
# login_password: "{{ mysql_root_password }}"
# tags: [ mysql ]
# - name: Create MySQL user for WordPress
# mysql_user:
# name: "{{ mysql_user }}"
# password: "{{ mysql_password }}"
# priv: "{{ mysql_db }}.*:ALL"
# state: present
# login_user: root
# login_password: "{{ mysql_root_password }}"
# tags: [ mysql ]
# UFW Configuration
- name: "UFW - Allow HTTP on port {{ http_port }}"
ufw:
rule: allow
port: "{{ http_port }}"
proto: tcp
tags: [ system ]
# WordPress Configuration
- name: Download and unpack latest WordPress
unarchive:
src: https://wordpress.org/latest.tar.gz
dest: "/var/www/{{ http_host }}"
remote_src: yes
creates: "/var/www/{{ http_host }}/wordpress"
tags: [ wordpress ]
- name: Set ownership
file:
path: "/var/www/{{ http_host }}"
state: directory
recurse: yes
owner: www-data
group: www-data
tags: [ wordpress ]
- name: Set permissions for directories
shell: "/usr/bin/find /var/www/{{ http_host }}/wordpress/ -type d -exec chmod 750 {} \\;"
tags: [ wordpress ]
- name: Set permissions for files
shell: "/usr/bin/find /var/www/{{ http_host }}/wordpress/ -type f -exec chmod 640 {} \\;"
tags: [ wordpress ]
- name: Set up wp-config
template:
src: "files/wp-config.php.j2"
dest: "/var/www/{{ http_host }}/wordpress/wp-config.php"
tags: [ wordpress ]
handlers:
- name: Reload Apache
service:
name: apache2
state: reloaded
- name: Restart Apache
service:
name: apache2
state: restarted