summaryrefslogtreecommitdiff
path: root/roles/paperless/main.yml
blob: f76d8256a2b7a1986d9c6bbe0ecfa601c916bc8d (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
---
- name: Container Setup

  vars:
    lxc_base: ansible-alpine3.11
    lxc_name: test

  import_playbook: ../common/tasks/lxc.yml

- name: Installing Paperless
  hosts: test

  vars_files:
    - ../variables.yml

  tasks:

  - name: Ensuring group exists
    group:
      name: "{{ paperless_user }}"
      state: present

  - name: Creating user and making home directory
    user:
      system: yes
      state: present
      name: "{{ paperless_user }}"
      groups: "{{ paperless_user }}"
      home: "{{ paperless_home }}"

  - name: Installing the required packages
    apk:
      state: present
      update_cache: yes
      name:
        - sudo
        - git
        - supervisor
        - syncthing
        - optipng
        - unpaper
        - imagemagick
        - tesseract-ocr
        - nginx
        - acl
        - gnupg
        - qpdf
        - libxslt
        - poppler
        - libmagic
        - postgresql-dev
        - gcc
        - g++
        - python3-dev
        - poppler-dev
        - jpeg-dev
        - qpdf-dev
        - libxslt-dev

  - name: Creating /dev/shm as ocrmypdf fails silently without this directory (semlock)
    file:
      path: /dev/shm
      state: directory
      mode: '0777'

  - name: Creating directories
    file:
      path: "{{ item }}"
      state: directory
      owner: "{{ paperless_user }}"
      group: "{{ paperless_user }}"
    with_items:
      - /opt/ocrmypdf

  - block:

    - name: Cloning application source
      git:
        repo: "{{ paperless_repository }}"
        dest: "{{ paperless_home }}"
        version: "{{ paperless_version }}"

    - name: Installing application requirements
      shell: |
        python3 -m venv .
        . bin/activate
        pip install --upgrade pip
        pip install --requirement requirements.txt
      args:
        chdir: "{{ paperless_home }}"
        creates: bin/activate

    - name: Migrating database
      shell: |
        . bin/activate
        src/manage.py migrate
      args:
        chdir: "{{ paperless_home }}"
        creates: data/db.sqlite3

    - name: Generating static assets
      shell: |
        . bin/activate
        src/manage.py collectstatic
      args:
        chdir: "{{ paperless_home }}"
        creates: static

    - name: Installing ocrmypdf
      shell: |
        python3 -m venv .
        . bin/activate
        pip install --upgrade pip
        pip install -Iv ocrmypdf=={{ paperless_ocrmypdf_version }}
      args:
        chdir: /opt/ocrmypdf
        creates: bin/activate

    become: true
    become_user: "{{ paperless_user }}"

  - name: Creating syncthing consumption folder permissions
    file:
      path: "{{ paperless_home }}/consumption"
      state: directory
      owner: "{{ paperless_user }}"
      group: syncthing
      mode: '0774'

  - name: Setting read/write consumption folder access
    acl:
      path: "{{ paperless_home }}/consumption"
      etype: other
      permissions: rw
      default: yes
      state: present

  - name: Placing configuration files
    template:
      src: "{{ item | basename }}.j2"
      dest: "{{ item }}"
    with_items:
      - /etc/hostname
      - /etc/supervisord.conf
      - /etc/paperless.conf
      - /opt/paperless/scripts/pre-consumption.sh
      - /etc/nginx/nginx.conf

  - name: Setting pre consumption script executable
    file:
      path: /opt/paperless/scripts/pre-consumption.sh
      mode: '0755'

  - name: Enabling and starting services
    service:
      name: "{{ item }}"
      state: restarted
      enabled: yes
    with_items:
      - nginx
      - supervisord
      - syncthing
    changed_when: false

  - name: Waiting for supervisor to become active
    wait_for:
      port: 9100

  - name: Ensuring paperless has been started
    supervisorctl:
      name: "{{ item }}"
      state: restarted
    with_items:
      - paperless
      - paperless-consumer
    changed_when: false

  - name: Cleaning up packages
    apk:
      state: absent
      name:
        - postgresql-dev
        - gcc
        - g++
        - python3-dev
        - poppler-dev
        - jpeg-dev
        - qpdf-dev
        - libxslt-dev
    changed_when: false