Newer
Older
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
---
# https://nextcloud.com/install/#instructions-server
# https://docs.nextcloud.com/server/12/admin_manual/maintenance/upgrade.html
- include_role:
name: _app_log_inventory
- name: "create temporary download directory"
tempfile:
state: directory
suffix: "_nextcloud_new"
register: _tmp_new_nextcloud
changed_when: False
- name: "retrieving nextcloud version {{ app_version }} in {{ _tmp_new_nextcloud.path }}"
unarchive:
src: "https://download.nextcloud.com/server/releases/nextcloud-{{ app_version }}.tar.bz2"
dest: "{{ _tmp_new_nextcloud.path }}"
remote_src: True
group: "www-data"
owner: "www-data"
- name: "disable site for {{ app_domain }}"
file:
state: absent
path: "/etc/{{ rev_proxy }}/sites-enabled/{{ app_instance_id }}.conf"
- name: "reload {{ rev_proxy }}"
service: name={{ rev_proxy }} state=reloaded
- name: "create dir for backup current version {{ backup_version_dir | mandatory }}/{{ app_instance_id | mandatory }}/{{ app_oldversion | mandatory }}"
file:
path: "{{ backup_version_dir }}/{{ app_instance_id }}/{{ app_oldversion }}"
state: directory
mode: 0777
- name: "create {{ rev_proxy }} dir for backup current version {{ backup_version_dir | mandatory }}/{{ app_instance_id | mandatory }}/{{ app_oldversion | mandatory }}"
file:
path: "{{ backup_version_dir }}/{{ app_instance_id }}/{{ app_oldversion }}/{{ rev_proxy }}"
state: directory
mode: 0777
- name: "create app dir for backup current version {{ backup_version_dir | mandatory }}/{{ app_instance_id | mandatory }}/{{ app_oldversion | mandatory }}"
file:
path: "{{ backup_version_dir }}/{{ app_instance_id }}/{{ app_oldversion }}/app"
state: directory
mode: 0777
- name: "create sql dir for backup current version {{ backup_version_dir | mandatory }}/{{ app_instance_id | mandatory }}/{{ app_oldversion | mandatory }}"
file:
path: "{{ backup_version_dir }}/{{ app_instance_id }}/{{ app_oldversion }}/sql"
state: directory
mode: 0777
- name: "backup {{ rev_proxy }} config"
command: "cp /etc/{{ rev_proxy }}/sites-available/{{ app_instance_id }}.conf {{ backup_version_dir }}/{{ app_instance_id }}/{{ app_oldversion }}/{{ rev_proxy }}"
args:
creates: "{{ backup_version_dir }}/{{ app_instance_id }}/{{ app_oldversion }}/{{ rev_proxy }}/{{ app_instance_id }}.conf"
- name: "backup app"
command: "rsync -aAx --del {{ www_root }}/{{ app_instance_id}} {{ backup_version_dir }}/{{ app_instance_id }}/{{ app_oldversion }}/app"
args:
creates: "{{ backup_version_dir }}/{{ app_instance_id }}/{{ app_oldversion }}/app/{{ app_instance_id }}"
- name: "backup database"
shell: "/usr/bin/pg_dump {{ database_name }} > {{ backup_version_dir }}/{{ app_instance_id }}/{{ app_oldversion }}/sql/{{ database_name }}.sql"
become_user: "postgres"
vars:
ansible_ssh_pipelining: true
args:
creates: "{{ backup_version_dir }}/{{ app_instance_id }}/{{ app_oldversion }}/sql/{{ database_name }}.sql"
- name: "backup app configuration"
shell: "php {{ www_root }}/{{ app_instance_id}}/occ config:list > {{ backup_version_dir }}/{{ app_instance_id }}/{{ app_oldversion }}/config.list"
become_user: "www-data"
vars:
ansible_ssh_pipelining: true
args:
creates: "{{ backup_version_dir }}/{{ app_instance_id }}/{{ app_oldversion }}/config.list"
- name: "remove {{ www_root }}/{{ app_instance_id }}"
file:
path: "{{ www_root }}/{{ app_instance_id }}"
state: absent
- name: "Move {{ _tmp_new_nextcloud.path }}/nextcloud to {{ www_root }}/{{ app_instance_id }}"
command: "/bin/mv {{ _tmp_new_nextcloud.path }}/nextcloud {{ www_root }}/{{ app_instance_id }}"
args:
creates: "{{ www_root }}/{{ app_instance_id }}"
- name: "remove {{ _tmp_new_nextcloud.path }}"
file:
path: "{{ _tmp_new_nextcloud.path }}"
state: absent
changed_when: False
- name: "restore config.php"
copy:
src: "{{ backup_version_dir }}/{{ app_instance_id }}/{{ app_oldversion }}/app/{{ app_instance_id}}/config/config.php"
dest: "{{ www_root }}/{{ app_instance_id }}/config/config.php"
remote_src: yes
backup: yes
# cron task or something ? may log while migrating
- name: "remove default data directory"
file:
state: absent
path: "{{ www_root }}/{{ app_instance_id }}/data"
- name: "link to data directory"
file:
state: link
src: "{{ www_root }}/{{ app_instance_id }}.data"
path: "{{ www_root }}/{{ app_instance_id }}/data"
- name: "www-data owner of {{ www_root }}/{{ app_instance_id }}"
file:
state: directory
path: "{{ www_root }}/{{ app_instance_id }}"
recurse: yes
owner: "www-data"
group: "www-data"
- name: "chmod 750 for directories"
command: "find {{ www_root }}/{{ app_instance_id }}/ -type d -exec chmod 750 {} \\;"
- name: "chmod 640 for files"
command: "find {{ www_root }}/{{ app_instance_id }}/ -type f -exec chmod 640 {} \\;"
- name: "perform nextcloud upgrade"
command: "php {{ www_root }}/{{ app_instance_id }}/occ upgrade"
become_user: "www-data"
vars:
ansible_ssh_pipelining: true
- name: "enable site for {{ app_domain }}"
file:
state: link
path: "/etc/{{ rev_proxy }}/sites-enabled/{{ app_instance_id }}.conf"
src: "/etc/{{ rev_proxy }}/sites-available/{{ app_instance_id }}.conf"
- name: "reload {{ rev_proxy }}"
service: name={{ rev_proxy }} state=reloaded