summaryrefslogtreecommitdiff
path: root/roles/nextcloud/tasks/main.yml
blob: fe65d62bf19ccc3a4542778b7aca82e1d4f1fd28 (plain) (blame)
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
---
- name: create zfs datasets
  when: nextcloud_zfs is defined
  block:
  - name: create zfs base dataset
    zfs:
      name: "{{ nextcloud_zfs.pool }}/{{ nextcloud_zfs.name }}"
      state: present
      extra_zfs_properties:
        quota: "{{ nextcloud_zfs.size }}"

  - name: create zfs volumes for instances
    loop: "{{ nextcloud_instances | dict2items }}"
    loop_control:
      label: "{{ item.key }} ({{ item.value.quota }})"
    zfs:
      name: "{{ nextcloud_zfs.pool }}/{{ nextcloud_zfs.name }}/{{ item.key }}"
      state: present
      extra_zfs_properties:
        quota: "{{ item.value.quota }}"

  - name: configure nextcloud base bath
    set_fact:
      nextcloud_base_path: "{{ zfs_zpools[nextcloud_zfs.pool].mountpoint }}/{{ nextcloud_zfs.name }}"


- name: create instance subdirectories
  when: nextcloud_zfs is not defined
  loop: "{{ nextcloud_instances | list }}"
  file:
    path: "{{ nextcloud_base_path }}/{{ item }}"
    state: directory



- name: add group for nextcloud app
  group:
    name: nc-app
    gid: "{{ nextcloud_app_gid }}"

- name: add user for nextcloud app
  user:
    name: nc-app
    uid: "{{ nextcloud_app_uid }}"
    group: nc-app
    password: "!"

- name: create nextcloud app subdirectory
  loop: "{{ nextcloud_instances | list }}"
  loop_control:
    label: "{{ item }}"
  file:
    path: "{{ nextcloud_base_path }}/{{ item }}/nextcloud"
    owner: "{{ nextcloud_app_uid }}"
    group: "{{ nextcloud_app_gid }}"
    state: directory


- name: add group for nextcloud db
  group:
    name: nc-db
    gid: "{{ nextcloud_db_gid }}"

- name: add user for nextcloud db
  user:
    name: nc-db
    uid: "{{ nextcloud_db_uid }}"
    group: nc-db
    password: "!"

- name: create nextcloud database subdirectory
  loop: "{{ nextcloud_instances | dict2items}}"
  loop_control:
    label: "{{ item.key }} ({{ item.value.database.type }})"
  file:
    path: "{{ nextcloud_base_path }}/{{ item.key }}/{{ item.value.database.type }}"
    owner: "{{ nextcloud_db_uid }}"
    group: "{{ nextcloud_db_gid }}"
    state: directory


- name: create image config dir
  loop: "{{ nextcloud_instances | list }}"
  loop_control:
    label: "{{ item }}"
  file:
    path: "{{ nextcloud_base_path }}/{{ item }}/config"
    state: directory

- name: create apache vhost config
  loop: "{{ nextcloud_instances | list }}"
  loop_control:
    label: "{{ item }}"
  copy:
    content: |
      <VirtualHost *:8080>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

        # SetEnv HTTPS on
        # SetEnvIfNoCase X-Forwarded-Proto https HTTPS=on

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
      </VirtualHost>
    dest: "{{ nextcloud_base_path }}/{{ item }}/config/apache-site.conf"

- name: configure apache to run on port 8080 only
  loop: "{{ nextcloud_instances | list }}"
  loop_control:
    label: "{{ item }}"
  copy:
    content: |
      Listen 8080
    dest: "{{ nextcloud_base_path }}/{{ item }}/config/ports.conf"



- name: generate pod manifests
  loop: "{{ nextcloud_instances | dict2items }}"
  loop_control:
    label: "{{ item.key }}"
  template:
    src: "pod-with-{{ item.value.database.type }}.yml.j2"
    dest: "/etc/kubernetes/manifests/{{ item.key }}.yml"
    mode: 0600