164 lines
4.8 KiB
YAML
164 lines
4.8 KiB
YAML
---
|
|
# Nextcloud Cloud Storage Role - Main Tasks
|
|
# Self-contained deployment with FPM, PostgreSQL, and Valkey via Unix sockets
|
|
|
|
- name: Validate infrastructure facts are available
|
|
assert:
|
|
that:
|
|
- postgresql_client_group_gid is defined
|
|
- valkey_client_group_gid is defined
|
|
fail_msg: |
|
|
Required infrastructure facts are not available.
|
|
Ensure PostgreSQL and Valkey roles have run and exported client group GIDs.
|
|
tags: [validation]
|
|
|
|
- name: Setup nextcloud user and container namespaces
|
|
include_tasks: user.yml
|
|
tags: [user, setup]
|
|
|
|
- name: Setup database access and permissions
|
|
include_tasks: database.yml
|
|
tags: [database, setup]
|
|
|
|
- name: Setup cache access and permissions
|
|
include_tasks: cache.yml
|
|
tags: [cache, setup]
|
|
|
|
- name: Pull nextcloud container image
|
|
containers.podman.podman_image:
|
|
name: "{{ nextcloud_image }}:{{ nextcloud_version }}"
|
|
state: present
|
|
tags: [containers, image-pull]
|
|
|
|
- name: Create nextcloud application directories (container manages ownership)
|
|
file:
|
|
path: "{{ item }}"
|
|
state: directory
|
|
# Note: No owner/group/mode specified - let container entrypoint manage ownership
|
|
# The official Nextcloud container expects to chown these to www-data (UID:33)
|
|
loop:
|
|
- "{{ nextcloud_html_dir }}"
|
|
- "{{ nextcloud_data_dir }}"
|
|
- "{{ nextcloud_config_dir }}"
|
|
- "{{ nextcloud_custom_apps_dir }}"
|
|
tags: [setup, directories]
|
|
|
|
- name: Deploy environment configuration
|
|
template:
|
|
src: nextcloud.env.j2
|
|
dest: "{{ nextcloud_home }}/.env"
|
|
mode: '0600'
|
|
backup: true
|
|
notify: restart nextcloud
|
|
tags: [config]
|
|
|
|
# NOTE: Custom Redis config is deployed AFTER installation completes (see below)
|
|
# to avoid interfering with the container's first-time initialization process
|
|
|
|
# NOTE: redis-session-override.ini is NOT deployed because we use file-based sessions
|
|
# (not Redis sessions). If you enable REDIS_HOST in the future, you'll need to add
|
|
# proper session lock configuration.
|
|
|
|
- name: Create Quadlet systemd directory (system scope)
|
|
file:
|
|
path: /etc/containers/systemd
|
|
state: directory
|
|
mode: '0755'
|
|
|
|
- name: Deploy Quadlet container file (system scope)
|
|
template:
|
|
src: nextcloud.container
|
|
dest: /etc/containers/systemd/nextcloud.container
|
|
mode: '0644'
|
|
notify:
|
|
- reload systemd
|
|
- restart nextcloud
|
|
tags: [containers, deployment]
|
|
|
|
- name: Deploy Caddy configuration
|
|
template:
|
|
src: nextcloud.caddy.j2
|
|
dest: "{{ caddy_sites_enabled_dir }}/nextcloud.caddy"
|
|
owner: root
|
|
group: "{{ caddy_user }}"
|
|
mode: '0644'
|
|
backup: true
|
|
notify: reload caddy
|
|
tags: [caddy, reverse-proxy]
|
|
|
|
- name: Ensure system dependencies are running
|
|
systemd:
|
|
name: "{{ item }}"
|
|
state: started
|
|
loop:
|
|
- postgresql
|
|
- valkey
|
|
|
|
- name: Wait for PostgreSQL socket to be ready
|
|
wait_for:
|
|
path: "{{ postgresql_unix_socket_directories }}/.s.PGSQL.{{ postgresql_port }}"
|
|
timeout: 30
|
|
|
|
- name: Wait for Valkey socket to be ready
|
|
wait_for:
|
|
path: "{{ valkey_unix_socket_path }}"
|
|
timeout: 30
|
|
|
|
- name: Enable and start Nextcloud service (system scope)
|
|
systemd:
|
|
name: nextcloud
|
|
enabled: "{{ nextcloud_service_enabled }}"
|
|
state: "{{ nextcloud_service_state }}"
|
|
daemon_reload: true
|
|
tags: [containers, service]
|
|
|
|
- name: Wait for Nextcloud FPM to be ready
|
|
wait_for:
|
|
host: 127.0.0.1
|
|
port: "{{ nextcloud_fpm_port }}"
|
|
timeout: 60
|
|
retries: 5
|
|
delay: 10
|
|
tags: [verification]
|
|
|
|
- name: Wait for Nextcloud installation to complete
|
|
shell: podman exec nextcloud php occ status --output=json 2>/dev/null || echo '{"installed":false}'
|
|
register: nc_status
|
|
until: (nc_status.stdout | from_json).installed | default(false) == true
|
|
retries: 60
|
|
delay: 5
|
|
changed_when: false
|
|
tags: [verification]
|
|
|
|
- name: Deploy custom Redis caching configuration (post-installation)
|
|
template:
|
|
src: redis.config.php.j2
|
|
dest: "{{ nextcloud_config_dir }}/redis.config.php"
|
|
mode: '0644'
|
|
notify: restart nextcloud
|
|
tags: [config, redis]
|
|
|
|
- name: Display Nextcloud deployment status
|
|
debug:
|
|
msg: |
|
|
✅ Nextcloud Cloud Storage deployed successfully!
|
|
|
|
🌐 Domain: {{ nextcloud_domain }}
|
|
🗄️ Database: {{ nextcloud_db_name }} (PostgreSQL via Unix socket)
|
|
🗄️ Cache: Valkey DB {{ nextcloud_valkey_db }} (Redis-compatible via Unix socket)
|
|
🐳 Container: FPM via Podman Quadlet
|
|
🔒 Admin: {{ nextcloud_admin_user }}
|
|
|
|
⚙️ Configuration:
|
|
- Redis caching enabled (application-level cache & file locking)
|
|
- PHP sessions use file-based storage (not Redis)
|
|
- Custom redis.config.php deployed post-installation
|
|
|
|
🚀 Ready for file storage and collaboration!
|
|
|
|
📋 Next Steps:
|
|
- Access https://{{ nextcloud_domain }} to log in
|
|
- Install desired Nextcloud apps
|
|
- Configure user accounts and storage quotas
|
|
tags: [verification]
|