aboutsummaryrefslogtreecommitdiff
path: root/roles/seafile_non_docker/tasks/main.yaml
blob: 597c389940e285148ab5f6431cd8cada4a017fa2 (plain)
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# https://seafile.readthedocs.io/en/latest/config/seafile/seadav/#seafdav-configuration
# https://manual.seafile.com/deploy/using_sqlite/
# https://manual.seafile.com/deploy/using_sqlite/#setup-in-non-interactive-way
# https://manual.seafile.com/deploy/deploy_with_nginx
# https://manual.seafile.com/deploy/deploy_seahub_at_non-root_domain/
# https://seafile.readthedocs.io/en/latest/installation/seafile/#enable-seafile-server-autostart-systemd
---

- name: 'install required apt packages'
  apt:
    name:
      - 'libmemcached-dev'
      - 'memcached'
      - 'pwgen'
      - 'python3'
      - 'python3-setuptools'
      - 'python3-pip'
      - 'sqlite3'
      - 'libopenjp2-7'
      - 'libtiff5'
    state: 'present'
    update_cache: true

- name: 'install required pip packages'
  become_user: '{{ seafile_user_grp }}'
  pip:
    name:
      - 'captcha'
      - 'django==2.2.*'
      - 'django-pylibmc'
      - 'django-simple-captcha'
      - 'future'
      - 'jinja2'
      - 'Pillow'
      - 'psd-tools'
      - 'pylibmc'
      - 'pexpect'
    state: 'present'

- name: 'create seafile installation and data directories'
  file:
    path: '{{ item.path }}'
    state: 'directory'
    owner: '{{ item.owner }}'
    group: '{{ item.group }}'
    mode: '{{ item.mode }}'
  loop:
    - {path: '{{ seafile_install_dir }}/installed', owner: '{{ seafile_user_grp }}', group: '{{ seafile_user_grp }}', mode: '775'}
    - {path: '{{ seafile_data_dir }}', owner: '{{ ansible_user }}', group: '{{ ansible_user }}', mode: '755'}

- name: 'download seafile package to local folder'
  become_user: '{{ seafile_user_grp }}'
  get_url:
    url: '{{ seafile_download_url }}'
    dest: '{{ seafile_install_dir }}/installed/seafile-{{ seafile_version }}.tar.gz'
    mode: '644'
  register: '_download_archive'
  until: '_download_archive is succeeded'
  retries: 5
  delay: 2
  check_mode: false

- name: 'unpack seafile binaries'
  become_user: '{{ seafile_user_grp }}'
  unarchive:
    src: '{{ seafile_install_dir }}/installed/seafile-{{ seafile_version }}.tar.gz'
    dest: '{{ seafile_install_dir }}'
    remote_src: true
    creates: '{{ seafile_install_dir }}/seafile-server-{{ seafile_version }}'
  check_mode: false

# this hack is needed for this version only
- name: 'Remove old PIL dir'
  become_user: '{{ seafile_user_grp }}'
  file:
    path: '{{ seafile_install_dir }}/seafile-server-{{ seafile_version }}/seahub/thirdpart/PIL'
    state: 'absent'
  when: '"buster" in seafile_download_url'

# RUN NON-INTERACTIVELY
- name: 'Run setup script'  # noqa no-changed-when command-instead-of-shell
  become_user: '{{ seafile_user_grp }}'
  shell: './setup-seafile.sh auto -n "{{ inventory_hostname }}" -i "0.0.0.0"'
  args:
    executable: '/bin/bash'
    chdir: '{{ seafile_install_dir }}/seafile-server-{{ seafile_version }}'
    creates: '{{ seafile_install_dir }}/conf/ccnet.conf'

- name: 'Get stats of the data object'
  stat:
    path: '{{ seafile_install_dir }}/seafile-data'
  register: sym

- block:
    - name: 'Ensure Seafile is not running yet'  # noqa command-instead-of-shell
      become_user: '{{ seafile_user_grp }}'
      shell: './seafile.sh stop'
      args:
        executable: '/bin/bash'
        chdir: '{{ seafile_install_dir }}/seafile-server-{{ seafile_version }}'

    - name: 'Move old data to new data'   # noqa risky-file-permissions
      become_user: '{{ seafile_user_grp }}'
      copy:
        src: '{{ seafile_install_dir }}/seafile-data/'
        dest: '{{ seafile_data_dir }}'
        remote_src: true

    - name: 'Delete old data dir'
      become_user: '{{ seafile_user_grp }}'
      file:
        path: '{{ seafile_install_dir }}/seafile-data'
        state: 'absent'

    - name: 'Create symlink to new data dir'
      become_user: '{{ seafile_user_grp }}'
      file:
        src: '{{ seafile_data_dir }}'
        dest: '{{ seafile_install_dir }}/seafile-data'
        state: 'link'
  when: sym.stat.islnk is defined and (not sym.stat.islnk)  # => first time setup

- name: 'Copy conf files'
  become_user: '{{ seafile_user_grp }}'
  template:
    src: '{{ item }}.j2'
    dest: '{{ seafile_install_dir }}/conf/{{ item }}'
    mode: '644'
  loop:
    - 'ccnet.conf'
    - 'seafdav.conf'
  notify:
    - 'seafile restart'
    - 'seahub restart'

- name: 'Update gunicorn conf'
  lineinfile:
    path: '{{ seafile_install_dir }}/conf/gunicorn.conf.py'
    regexp: '^bind'
    line: 'bind = "127.0.0.1:8000"'
  notify:
    - 'seahub restart'

# some stuff needed for nginx based install
- name: 'Update seahub_settings.py'
  become_user: '{{ seafile_user_grp }}'
  blockinfile:
    path: '{{ seafile_install_dir }}/conf/seahub_settings.py'
    insertafter: '^SECRET_KEY'
    block: |
      DEBUG = False
      FILE_SERVER_ROOT = 'https://{{ seafile_domain }}/seafhttp'
      SERVE_STATIC = False
      MEDIA_URL = '/seafmedia/'
      COMPRESS_URL = MEDIA_URL
      STATIC_URL = MEDIA_URL + 'assets/'
      SITE_ROOT = '/files/'
      LOGIN_URL = '/files/accounts/login/'
  notify:
    - 'seahub restart'

- block:
    - name: 'Run Seafile start script'  # noqa command-instead-of-shell
      become_user: '{{ seafile_user_grp }}'
      shell: './seafile.sh start'
      args:
        executable: '/bin/bash'
        chdir: '{{ seafile_install_dir }}/seafile-server-{{ seafile_version }}'

    - name: 'Init Seahub with a user'
      become_user: '{{ seafile_user_grp }}'
      expect:
        command: './seahub.sh start'
        chdir: '{{ seafile_install_dir }}/seafile-server-{{ seafile_version }}'
        responses:
          (?i)email: "{{ seafile_user_email }}"
          (?i)password: "{{ seafile_user_password }}"

  when: sym.stat.islnk is defined and (not sym.stat.islnk)  # => first time setup

- name: 'Create systemd services'
  template:
    src: '{{ item }}.j2'
    dest: '/etc/systemd/system/{{ item }}'
    mode: '644'
  loop:
    - 'seafile.service'
    - 'seahub.service'
  notify:
    - 'seafile restart'
    - 'seahub restart'

- name: 'Reload systemd units'
  systemd:
    daemon_reload: true

- block:
    - name: 'Run Seahub start script'  # noqa command-instead-of-shell
      become_user: '{{ seafile_user_grp }}'
      shell: './seahub.sh stop'
      args:
        executable: '/bin/bash'
        chdir: '{{ seafile_install_dir }}/seafile-server-{{ seafile_version }}'

    - name: 'Run Seafile stop script'  # noqa command-instead-of-shell
      become_user: '{{ seafile_user_grp }}'
      shell: './seafile.sh stop'
      args:
        executable: '/bin/bash'
        chdir: '{{ seafile_install_dir }}/seafile-server-{{ seafile_version }}'
  when: sym.stat.islnk is defined and (not sym.stat.islnk)  # => first time setup

- name: 'Start Seafile and Seahub'
  systemd:
    name: '{{ item }}'
    state: 'started'
    enabled: true
  loop:
    - 'seafile'
    - 'seahub'