/
/
/
Ansible role that provisions my storage server.
1---
2# Storage Services - Nextcloud Cloud Storage
3
4- name: Create Nextcloud base directories
5 file:
6 path: "{{ item }}"
7 state: directory
8 owner: "{{ storage_user }}"
9 group: "{{ storage_group }}"
10 mode: '2775'
11 loop:
12 - "{{ nextcloud_config_dir }}"
13
14- name: Create Nextcloud app directories (www-data uid 33)
15 file:
16 path: "{{ item }}"
17 state: directory
18 owner: "33"
19 group: "33"
20 mode: '0755'
21 loop:
22 - "{{ nextcloud_config_dir }}/html"
23 - "{{ nextcloud_data_dir }}"
24
25- name: Create MariaDB data directory (mysql uid 999)
26 file:
27 path: "{{ nextcloud_mariadb_config_dir }}"
28 state: directory
29 owner: "999"
30 group: "999"
31 mode: '0755'
32
33- name: Create Redis data directory
34 file:
35 path: "{{ nextcloud_redis_config_dir }}"
36 state: directory
37 owner: "999"
38 group: "1000"
39 mode: '0755'
40
41- name: Create Elasticsearch data directory (uid 1000)
42 file:
43 path: "{{ nextcloud_elasticsearch_config_dir }}"
44 state: directory
45 owner: "1000"
46 group: "1000"
47 mode: '0755'
48
49- name: Create Collabora config directory
50 file:
51 path: "{{ nextcloud_collabora_config_dir }}"
52 state: directory
53 owner: "{{ storage_user }}"
54 group: "{{ storage_group }}"
55 mode: '2775'
56
57- name: Generate Nextcloud environment file
58 template:
59 src: nextcloud.env.j2
60 dest: "{{ nextcloud_config_dir }}/.env"
61 owner: "{{ storage_user }}"
62 group: "{{ storage_group }}"
63 mode: '0660'
64 notify: restart nextcloud
65
66- name: Deploy Nextcloud Docker Compose file
67 template:
68 src: nextcloud-compose.yml.j2
69 dest: "{{ nextcloud_config_dir }}/docker-compose.yml"
70 owner: "{{ storage_user }}"
71 group: "{{ storage_group }}"
72 mode: '0664'
73 notify: restart nextcloud
74
75- name: Check if Nextcloud directory exists
76 stat:
77 path: "{{ nextcloud_config_dir }}"
78 register: nextcloud_dir_stat
79 changed_when: false
80
81- name: Start Nextcloud services
82 community.docker.docker_compose_v2:
83 project_src: "{{ nextcloud_config_dir }}"
84 state: present
85 register: nextcloud_start_result
86 check_mode: no
87 when: nextcloud_dir_stat.stat.exists
88
89- name: Wait for Nextcloud to be healthy
90 uri:
91 url: "http://localhost:{{ nextcloud_host_port }}/status.php"
92 method: GET
93 status_code: [200, 302, 400]
94 register: nextcloud_health
95 until: nextcloud_health.status in [200, 302, 400]
96 retries: 15
97 delay: 10
98 when: nextcloud_start_result is changed
99 check_mode: no
100
101- name: Configure Collabora WOPI URL
102 command: >
103 docker exec nextcloud php occ config:app:set richdocuments
104 wopi_url --value="{{ nextcloud_collabora_public_url }}"
105 changed_when: false
106 when: nextcloud_start_result is changed
107
108- name: Display Nextcloud deployment summary
109 debug:
110 msg: |
111 Nextcloud Deployment:
112 - Status: {{ 'Started' if nextcloud_start_result is changed else 'Already running' }}
113 - Web UI: http://{{ ansible_default_ipv4.address }}:{{ nextcloud_host_port }}
114
115 Services:
116 - Nextcloud: http://{{ ansible_default_ipv4.address }}:{{ nextcloud_host_port }}
117 - MariaDB: internal (nextcloud-db)
118 - Redis: internal (nextcloud-redis)
119 - Elasticsearch: internal (nextcloud-elasticsearch)
120 - Collabora: internal (nextcloud-collabora)
121 - Imaginary: internal (nextcloud-imaginary)
122
123 Directories:
124 - Configuration: {{ nextcloud_config_dir }}
125 - User Data: {{ nextcloud_data_dir }}
126