]> git.somenet.org - root/pub/somesible.git/blob - roles/service/mattermost/tasks/main.yml
[roles/util] ----- meta ----- No dependencies
[root/pub/somesible.git] / roles / service / mattermost / tasks / main.yml
1 #####################################
2 ### someone"s ansible provisioner ###
3 #####################################
4 # Part of: https://git.somenet.org/root/pub/somesible.git
5 # 2017-2024 by someone <someone@somenet.org>
6 #
7 # its not supported to run multiple mattestmost instances on one host.
8 #
9 ---
10 - name: create mattermost user
11   user:
12     name: "mattermost"
13     home: "{{mattermost_homedir}}"
14     shell: "/bin/zsh"
15     system: yes
16     state: present
17
18
19 - name: create mattermost homedir
20   file:
21     path: "{{mattermost_homedir}}"
22     state: directory
23     mode: 0710
24     owner: "mattermost"
25     group: "mattermost"
26
27
28 - name: create mattermost data-dir
29   file:
30     path: "{{mattermost_homedir}}/data"
31     state: directory
32     mode: 0750
33     owner: "mattermost"
34     group: "mattermost"
35
36
37 #- name: create postgres-db and user
38 #  include_role:
39 #    name: util/postgres-db-usr
40 #  vars:
41 #    pg_data:
42 #      dbname: "{{mattermost_db_name}}"
43 #      pw: "{{mattermost_db_pw}}"
44 #  when: mattermost_db_create | default('True') | bool
45
46
47 - name: include vars_nginx_vhost_custom
48   include_vars:
49     file: "{{item}}"
50     name: vars_nginx_vhost_custom
51   with_first_found:
52     - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/vars_nginx_vhost_custom.yml"
53     - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/vars_nginx_vhost_custom.yml"
54     - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/vars_nginx_vhost_custom.yml"
55     - "default/vars_nginx_vhost_custom.yml"
56
57
58 - name: configure mattermost vhost
59   include_role:
60     name: server/nginx/vhost-unified
61   vars:
62     vhost_type: "custom"
63     vhost_name: "{{mattermost_domain}}"
64     vhost_awstats_valid_http_codes: "200 304 101"
65     vhost_custom:
66       vhost_custom_pre_server: "{{vars_nginx_vhost_custom.vhost_custom_pre_server}}"
67       vhost_custom: "{{vars_nginx_vhost_custom.vhost_custom}}"
68
69
70 - name: copy mattermost.service to /etc/systemd/system/
71   copy:
72     src: "{{item}}"
73     dest: "/etc/systemd/system/mattermost.service"
74     mode: 0644
75     owner: "root"
76     group: "root"
77   with_first_found:
78     - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/mattermost.service"
79     - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/mattermost.service"
80     - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/mattermost.service"
81     - "default/mattermost.service"
82
83
84 - name: download mattermost release and check checksums
85   get_url:
86     url: "{{mattermost_download_url}}"
87     dest: "{{mattermost_homedir}}/server.tar.gz"
88     mode: 0640
89     owner: "mattermost"
90     group: "mattermost"
91     checksum: "{{mattermost_download_checksum}}"
92     timeout: 30
93   tags: "online"
94   register: download
95
96
97 - name: extract and update/install mattermost
98   block:
99   - name: stop mattermost.service
100     systemd:
101       name: mattermost.service
102       daemon_reload: yes
103       state: stopped
104
105
106   - name: remove old server files
107     file:
108       path: "{{mattermost_homedir}}/server.old"
109       state: absent
110
111
112   - name: limit access to current server files
113     file:
114       path: "{{mattermost_homedir}}/server"
115       state: directory
116       mode: 0700
117       owner: "mattermost"
118       group: "mattermost"
119
120
121   - name: move current server files away
122     command: "mv {{mattermost_homedir}}/server {{mattermost_homedir}}/server.old"
123
124
125   - name: create new server files dir, because unarchive fails to do so
126     file:
127       path: "{{mattermost_homedir}}/server"
128       state: directory
129       mode: 0750
130       owner: "mattermost"
131       group: "mattermost"
132
133
134   - name: extract mattermost files
135     unarchive:
136       src: "{{mattermost_homedir}}/server.tar.gz"
137       dest: "{{mattermost_homedir}}/server"
138       remote_src: yes
139       mode: "u=rwX,g=rX,o-rwx"
140       owner: "mattermost"
141       group: "mattermost"
142       extra_opts:
143         - '--strip-components=1'
144         - '--show-stored-names'
145
146
147   - name: reuse existing config file
148     command: "mv {{mattermost_homedir}}/server.old/config/config.json {{mattermost_homedir}}/server/config/config.json"
149     register: config_copy
150     ignore_errors: yes
151
152
153   - name: template new config.json
154     template:
155       src: "{{item}}"
156       dest: "{{mattermost_homedir}}/server/config/config.json"
157       mode: 0640
158       owner: "mattermost"
159       group: "mattermost"
160     with_first_found:
161       - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/config.json.j2"
162       - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/config.json.j2"
163       - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/config.json.j2"
164       - "default/config.json.j2"
165     when: config_copy.failed
166
167
168   - name: enable and restart mattermost.service
169     include_role: name="base/systemd/enable-and-start"
170     vars:
171       service_name: mattermost.service
172       service_state: restarted
173
174
175   - name: create mattermost admin user
176     become: true
177     become_user: "mattermost"
178     shell: "bin/mattermost user create --system_admin --username {{mattermost_admin_user | quote}} --email {{mattermost_admin_user_email | quote}} --password {{mattermost_admin_user_pw | quote}} || true"
179     args:
180       chdir: "{{mattermost_homedir}}/server"
181     register: script_res
182     changed_when: "'An account with that email already exists' not in script_res.stdout"
183
184   when: download.changed