nextcloud/roles/server/tasks/main.yml

145 lines
4.4 KiB
YAML
Raw Normal View History

---
- name: Create nextcloud user
ansible.builtin.user:
name: "{{ nextcloud_user }}"
state: present
system: yes
register: nextcloud_user_info
- name: Map nextcloud socket path if defined
ansible.builtin.set_fact:
nextcloud_paths: "{{ nextcloud_paths + [ socket_dir ] }}"
nextcloud_container_base_volumes: "{{ nextcloud_container_base_volumes + [ socket_map ] }}"
vars:
socket_dir:
path: "{{ nextcloud_socket_path }}"
mode: "0755"
owner: "{{ nextcloud_user_info.uid|default(nextcloud_user) }}"
group: "{{ nextcloud_user_info.uid|default(nextcloud_user) }}"
socket_map: "{{ nextcloud_socket_path }}:{{ nextcloud_container_php_socket_path }}:z"
when: nextcloud_socket_path is defined and nextcloud_socket_path is string
- name: Ensure nextcloud directories exist and have correct permissions
ansible.builtin.file:
path: "{{ item.path }}"
state: directory
mode: "{{ item.mode }}"
owner: "{{ item.owner }}"
group: "{{ item.group }}"
loop: "{{ nextcloud_paths }}"
- name: Ensure docker container image '{{ nextcloud_container_image_ref }}' for nextcloud is pulled
community.docker.docker_image:
name: "{{ nextcloud_container_image_ref }}"
state: present
source: pull
force_source: "{{ nextcloud_container_image_force_source }}"
- name: Template OpCache configuration
ansible.builtin.template:
src: nextcloud-fpm-opcache.ini.j2
dest: "{{ nextcloud_fpm_config_path }}/opcache.ini"
mode: "0640"
owner: "root"
group: "root"
notify:
- reload-nextcloud
- name: Template PHP FPM configuration
ansible.builtin.template:
src: nextcloud-fpm.ini.j2
dest: "{{ nextcloud_fpm_config_path }}/fpm.ini"
mode: "0640"
owner: "root"
group: "root"
notify:
- reload-nextcloud
- name: Template PHP FPM docker-specific configuration
ansible.builtin.template:
src: nextcloud-fpm-docker.ini.j2
dest: "{{ nextcloud_fpm_config_path }}/fpm-docker.ini"
mode: "0640"
owner: "root"
group: "root"
notify:
- reload-nextcloud
- name: Template modified /etc/passwd for nextcloud container
ansible.builtin.template:
src: nextcloud-passwd.j2
dest: "{{ nextcloud_basepath }}/nextcloud-passwd"
mode: "0640"
owner: "root"
group: "root"
notify:
- reload-nextcloud
- name: Template modified /etc/passwd for nextcloud container
ansible.builtin.template:
src: nextcloud-group.j2
dest: "{{ nextcloud_basepath }}/nextcloud-group"
mode: "0640"
owner: "root"
group: "root"
notify:
- reload-nextcloud
- name: Template systemd service for nextcloud's cron job
ansible.builtin.template:
src: systemd-nextcloud-cron.service.j2
dest: /etc/systemd/system/nextcloud-cron.service
mode: "0640"
owner: root
group: root
when: nextcloud_background_job_mode == 'cron'
notify:
- reload-systemd
- name: Template timer for nextcloud's cron job
ansible.builtin.template:
src: systemd-nextcloud-cron.timer.j2
dest: /etc/systemd/system/nextcloud-cron.timer
mode: "0640"
owner: root
group: root
when: nextcloud_background_job_mode == 'cron'
notify:
- reload-systemd
- name: Flush handlers now to ensure systemd can know about the timer before it's enabled
ansible.builtin.meta: flush_handlers
- name: Ensure docker container for nextcloud is running
community.docker.docker_container:
name: "{{ nextcloud_container_name }}"
image: "{{ nextcloud_container_image_ref }}"
volumes: "{{ nextcloud_container_volumes }}"
labels: "{{ nextcloud_container_labels }}"
env: "{{ nextcloud_container_env }}"
etc_hosts: "{{ nextcloud_container_etc_hosts | default(omit, true) }}"
networks: "{{ nextcloud_container_networks | default(omit, true) }}"
restart_policy: "{{ nextcloud_container_restart_policy }}"
state: started
- name: Enable systemd timer for nextcloud cron
ansible.builtin.systemd:
name: "nextcloud-cron.timer"
enabled: yes
when: nextcloud_background_job_mode == 'cron'
- name: Ensure systemd timer for nextcloud cron is started
ansible.builtin.systemd:
name: "nextcloud-cron.timer"
state: started
when: nextcloud_background_job_mode == 'cron'
- name: Configure nextcloud
ansible.builtin.include_tasks:
file: configure-single-setting.yml
vars:
key: "{{ item.key | replace('[', '.') | replace(']', '.') }}"
value: "{{ item.value }}"
loop: "{{ lookup('ansible.utils.to_paths', nextcloud_config ) | dict2items }}"