-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathuclalib_craftcms_env_sync.yml
161 lines (130 loc) · 5.34 KB
/
uclalib_craftcms_env_sync.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
---
- name: uclalib_craftcms_env_sync.yml
become: yes
become_method: sudo
hosts: "{{ craft_dest_host | default('s-w-craftcms01.library.ucla.edu') }}"
environment:
PATH: /opt/rh/rh-php73/root/usr/bin:/opt/rh/rh-php73/root/usr/sbin:{{ ansible_env.PATH }}
tasks:
- name: Get PHP executable path
command: >
which php
register: php_exec_path
- name: Set play variables
set_fact:
craft_dir: "{{ craftcms_work_dir | default('/var/www/craftcms') }}"
craft_src_backup_dir: "{{ craftcms_src_backup | default('/craftcmsbackupprod') }}"
craft_src_backup_nfs: "{{ craftcms_src_backup_nfs | default('devsupport.in.library.ucla.edu:/LX/craftprod_backups') }}"
craft_assets_src_dir: "{{ craftcms_src_assets | default('/mnt/craft_assets_prod') }}"
craft_assets_src_nfs: "{{ craftcms_src_assets_nfs | default ('webcontent.in.library.ucla.edu:/craft_assets/prod') }}"
craft_assets_dest_dir: "{{ craftcms_sync_assets | default('/mnt/craft_assets') }}"
craft_user: "{{ craftcms_user | default('craftcms') }}"
craft_src_host: "{{ craftcms_source_host | default('p-w-craftcms01.library.ucla.edu') }}"
php_exec: "{{ php_exec_path.stdout }}"
## Prerequiste Tasks ################################
- name: Mount source craft backup volume on destination host
mount:
path: "{{ craft_src_backup_dir }}"
src: "{{ craft_src_backup_nfs }}"
fstype: "nfs"
opts: "ro"
state: "mounted"
- name: Mount source craft assets volume on destination host
mount:
path: "{{ craft_assets_src_dir }}"
src: "{{ craft_assets_src_nfs }}"
fstype: "nfs"
opts: "ro"
state: "mounted"
- name: Stop Apache HTTPD
service:
name: "httpd"
state: "stopped"
- name: Stop PHP-FPM
service:
name: "rh-php73-php-fpm"
state: "stopped"
- name: Get most recent source backup directory name
shell: >
ls -tr | tail -1
args:
chdir: "{{ craft_src_backup_dir }}"
changed_when: "false"
register: backup_dir_name
##################################################################################
## Restore source craft file system backup to destination craft ##################
- name: Preserve destination craft .env file
copy:
src: "{{ craft_dir }}/.env"
dest: "/home/craftcms/.env_local_backup"
owner: "craftcms"
group: "craftcms"
mode: "0660"
remote_src: "yes"
- name: Remove existing destination craft directory
file:
path: "{{ craft_dir }}"
state: "absent"
- name: Restore source craft file system backup to destination craft
unarchive:
src: "{{ craft_src_backup_dir }}/{{ backup_dir_name.stdout }}/craftcms_fs_{{ backup_dir_name.stdout }}.tar.gz"
dest: "/var/www/"
remote_src: "yes"
- name: Restore destination craft .env file
copy:
src: "/home/craftcms/.env_local_backup"
dest: "{{ craft_dir }}/.env"
owner: "craftcms"
group: "craftcms"
mode: "0660"
remote_src: "yes"
##################################################################################
## Restore source craft database backup to destination craft #####################
- name: Restore source craft database backup to destination craft
become_user: "{{ craft_user }}"
command: >
{{ php_exec }} craft db/restore {{ craft_src_backup_dir }}/{{ backup_dir_name.stdout }}/craftcms_sqldump_{{ backup_dir_name.stdout }}.sql --interactive 0
args:
chdir: "{{ craft_dir }}"
##################################################################################
## Synchronize source craft assets with destination craft assets #################
- name: Synchronize source craft assets with destination craft assets
become_user: "{{ craft_user }}"
synchronize:
src: "{{ craft_assets_src_dir }}/"
dest: "{{ craft_assets_dest_dir }}"
rsync_opts:
- "--delete"
- "--exclude=.snapshot"
delegate_to: "{{ inventory_hostname }}"
##################################################################################
## Clean-up Tasks ################################################################
- name: Unmount source craft backup volume on destination host
mount:
path: "{{ craft_src_backup_dir }}"
state: "absent"
- name: Unmount source craft assets volume on destination host
mount:
path: "{{ craft_assets_src_dir }}"
state: "absent"
- name: Start Apache HTTPD
service:
name: "httpd"
state: "started"
- name: Start PHP-FPM
service:
name: "rh-php73-php-fpm"
state: "started"
- name: Set destination craft environment to online
become_user: "{{ craft_user }}"
command: >
{{ php_exec }} craft on --interactive 0
args:
chdir: "{{ craft_dir }}"
- name: Clear all craft caches
become_user: "{{ craft_user }}"
command: >
{{ php_exec }} craft clear-caches/all --interactive 0
args:
chdir: "{{ craft_dir }}"
##################################################################################