-
Notifications
You must be signed in to change notification settings - Fork 102
/
setup.yml
174 lines (128 loc) · 4.82 KB
/
setup.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
- hosts: all
become: true
vars:
hostname: mywordpress
wordpress_version: 4.6.1
wordpress_parent_path: /usr/share
wordpress_path: "{{ wordpress_parent_path }}/wordpress"
wordpress_owner: www-data
wordpress_group: www-data
mysql_root_password: secretsecret
wordpress_db_name: wordpress
wordpress_db_user: wordpressuser
wordpress_db_password: wordpresspassword
handlers:
- name: restart nginx
service: name=nginx state=restarted
- name: restart php-fpm
service: name=php7.0-fpm state=restarted
tasks:
- name: ==> 0 - add host info
lineinfile: dest=/etc/hosts line="10.0.0.10 {{ hostname }}" state=present
- name: ==> 1 - add PPA of php7 (community)
apt_repository: repo="ppa:ondrej/php"
- debug: msg="==> 2 - add PPA of nginx (official)"
- name: add Nginx stable repository (deb)
apt_repository: >
repo='deb http://nginx.org/packages/ubuntu/ trusty nginx'
state=present
- name: add Nginx stable repository (deb-src)
apt_repository:
repo: 'deb-src http://nginx.org/packages/ubuntu/ trusty nginx'
state: present
- name: add Nginx.org key
apt_key: url=http://nginx.org/keys/nginx_signing.key state=present
- name: ==> 3 - download/update the package lists
apt: update_cache=yes
- name: ==> 4 - install nginx, php-fpm, and php-mysql
apt: name={{ item }} state=present
with_items:
- nginx
- 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
- debug: msg="==> 8 - install mysql"
- name: auto set root password for mysql
debconf:
name: 'mysql-server'
question: "{{ item }}"
vtype: 'password'
value: "{{ mysql_root_password }}"
with_items:
- mysql-server/root_password
- mysql-server/root_password_again
- name: install mysql
apt: name={{ item }} state=present
with_items:
- mysql-server
- mysql-client
- debug: msg="==> 9 - create initial wordpress db"
- name: install prerequisite for Ansible's mysql modules
apt: name=python-mysqldb state=present
- name: create wordpress db
mysql_db:
name: "{{ wordpress_db_name }}"
login_user: root
login_password: "{{ mysql_root_password }}"
state: present
- name: create wordpress user
mysql_user:
name: "{{ wordpress_db_user }}"
password: "{{ wordpress_db_password }}"
priv: "{{ wordpress_db_name }}.*:ALL"
login_user: root
login_password: "{{ mysql_root_password }}"
state: present
- 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
#- debug: msg="==> 11 - restart nginx"
#- name: ==> 12 - automate the '5-minute install' process
# uri:
# url: "{{ wordpress_install_url }}"
# method: POST
# HEADER_Content-Type: "application/x-www-form-urlencoded"
# body: "#weblog_title=ANSIBLE_TEST&user_name=admin&admin_email=foo@gmail.#com&blog_public=true&admin_password=admin&admin_password2=admin"
# status_code: 200