-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy pathwordpress.yml
107 lines (79 loc) · 2.9 KB
/
wordpress.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
- hosts: all
become: true
roles:
- williamyeh.nginx
vars:
hostname: mywordpress
modify_hostname: true
wordpress_version: 4.6.1
wordpress_parent_path: /usr/share
wordpress_path: "{{ wordpress_parent_path }}/wordpress"
wordpress_owner: www-data
wordpress_group: www-data
wordpress_db_name: wordpress
wordpress_db_user: wordpressuser
wordpress_db_password: wordpresspassword
handlers:
- name: restart php-fpm
service: name=php7.0-fpm state=restarted
tasks:
- name: ==> 1 - add PPA of php7 (community)
apt_repository: repo="ppa:ondrej/php"
- debug: msg="==> 2 - add PPA of nginx (official) -- delegated to roles"
- name: ==> 3 - download/update the package lists
apt: update_cache=yes
- name: ==> 4 - install php-fpm, and php-mysql
apt: name={{ item }} state=present
with_items:
- php7.0-fpm
- php7.0-mysql
- debug: msg="==> 5 - download and extract wordpress"
- name: download wordpress tarball
get_url:
url: "https://tw.wordpress.org/wordpress-{{ wordpress_version }}-zh_TW.tar.gz"
dest: /tmp/
- name: extract wordpress tarball
unarchive:
src: "/tmp/wordpress-{{ wordpress_version }}-zh_TW.tar.gz"
dest: "{{ wordpress_parent_path }}"
owner: "{{ wordpress_owner }}"
group: "{{ wordpress_group }}"
copy: no
- debug: msg="==> 6 - install site conf file for wordpress"
- name: check if "default.conf.bak" target exists
stat: path=/etc/nginx/conf.d/default.conf
register: filecheck
- name: rename to "default.conf.bak", if any
command: mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.bak
when: filecheck.stat.exists
- name: copy wordpress site conf for nginx
template:
src: ./templates/nginx-wordpress.conf.j2
dest: /etc/nginx/conf.d/nginx-wordpress.conf
notify: restart nginx
- debug: msg="==> 7 - change php-fpm unix socket permission to the same as nginx"
- name: fix listen.owner for php-fpm
lineinfile:
dest: /etc/php/7.0/fpm/pool.d/www.conf
regexp: '^listen.owner\s*=.*$'
line: "listen.owner=nginx"
state: present
notify: restart php-fpm
- name: fix listen.group for php-fpm
lineinfile:
dest: /etc/php/7.0/fpm/pool.d/www.conf
regexp: '^listen.group\s*=.*$'
line: "listen.group=nginx"
state: present
notify: restart php-fpm
- name: ==> 8 - install mysql-client (not necessary, just for trouble shooting)
apt: name={{ item }} state=present
with_items:
- mysql-client
- name: ==> 10 - set wordpress config
template:
src: ./templates/wp-config.php.j2
dest: "{{ wordpress_path }}/wp-config.php"
owner: "{{ wordpress_owner }}"
group: "{{ wordpress_group }}"
notify: restart nginx