This repository has been archived by the owner on Aug 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup-wordpress.yml
124 lines (108 loc) · 4.02 KB
/
setup-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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
---
# 建置 wordpress 系統的工作流程
- hosts: "{{ target_host }}"
vars_files:
- ./wordpress-version.yml
- ./vars-credentials.yml
tasks:
# 設定伺服器
- include: ../configure-server/configure-server.yml
# 以下兩步要安裝建置 wordpress 用的 wp-cli
- name: 安裝 wp-cli 到 /usr/local/bin 並設定權限為 755
get_url:
url: https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
dest: /usr/local/bin
mode: 0755
become: yes
become_user: root
- name: 將 wp-cli.phar 改名為 wp
command: mv /usr/local/bin/wp-cli.phar /usr/local/bin/wp
become: yes
become_user: root
# 若需要清空可能已存在的資料,則執行這兩步作業
- name: "清空網站目錄內容 (若有的話)"
file:
path: "{{ project_path }}/{{ host_name }}"
state: absent
become: yes
become_user: root
when: should_clean_up_env_before_setup == true
- name: 重新建立 wordpress 網站資料夾
file:
path: "{{ project_path }}/{{ host_name }}"
state: directory
become: yes
become_user: root
- name: 安裝 wordpress
command: "/usr/local/bin/wp core download --path={{ project_path }}/{{ host_name }} --version={{ wp_version }}"
become: yes
become_user: root
- name: 設定 wordpress (加入 wp-config.php)
command: |
/usr/local/bin/wp config create
--dbname={{ wp_db_name }}
--dbuser={{ mariadb_wp_user }}
--dbpass={{ mariadb_wp_user_pwd }}
--path={{ project_path }}/{{ host_name }}
become: yes
become_user: root
# 接下來兩項作業都是為了確保將來系統能協助更新擴充套件
- name: 開放 apache 存取專案錄的權限以利後續手動更新套件
acl:
path: "{{ project_path }}/{{ host_name }}"
state: present
# 以下這會讓目標目錄「未來增加」的子目錄都繼承目前的 acl 設定
default: yes
# recursive 與 default 的差別在於 recursive 使「目前」的子目錄都繼承目前的 acl 設定
recursive: yes
entity: apache
etype: group
permissions: rwx
become: true
become_user: root
- name: 額外設定 wordpress
command: "/usr/local/bin/wp config set FS_METHOD direct --path={{ project_path }}/{{ host_name }}"
become: yes
become_user: root
# 接下來繼續回來安裝 wordpress
- name: 啟動 httpd
service:
name: httpd
state: started
become: yes
become_user: root
- name: 初始化 wordpress
command: |
/usr/local/bin/wp core install
--path={{ project_path }}/{{ host_name }}
--url={{ host_name }}
--title={{ wp_title }}
--admin_user={{ wp_admin_user }}
--admin_password={{ wp_admin_password }}
--admin_email={{ wp_admin_email }}
become: yes
become_user: root
- name: 安裝 wordpress 擴充套件
command: |
/usr/local/bin/wp plugin install {{ item.name }}
--path={{ project_path }}/{{ host_name }}
--version={{ item.version }}
become: true
become_user: root
loop: "{{ wp_plugins }}"
- name: 設定 wordpress permalink 的格式
# 之所以要做這件事的原因是要讓 wp rest api 以路徑的方式提供服務,而不是用請求參數提供服務
# 詳見: https://developer.wordpress.org/rest-api/#routes-endpoints
command: |
/usr/local/bin/wp option update permalink_structure '/%year%/%monthnum%/%postname%/'
--path={{ project_path }}/{{ host_name }}
become: yes
become_user: root
- name: 重新啟動 httpd
service:
name: httpd
state: restarted
become: yes
become_user: root
# name: 設定按時自動備份 wordpress 的排程
- include: ../setup-wordpress-backup-scedule/setup-wordpress-backup-scedule.yml