146 lines
		
	
	
	
		
			5.1 KiB
		
	
	
	
		
			YAML
		
	
	
	
	
	
			
		
		
	
	
			146 lines
		
	
	
	
		
			5.1 KiB
		
	
	
	
		
			YAML
		
	
	
	
	
	
---
 | 
						|
# tasks file for nextcloud
 | 
						|
- name: Ensure nextcloud config directory exists
 | 
						|
  file:
 | 
						|
    path: "{{ nextcloud_install_path }}/nextcloud"
 | 
						|
    state: directory
 | 
						|
    owner: '{{ nextcloud_install_user }}'
 | 
						|
    group: '{{ nextcloud_install_user }}'
 | 
						|
 | 
						|
- name: Provide docker-compose.yml
 | 
						|
  template:
 | 
						|
    src: templates/docker-compose.nextcloud.yml.j2
 | 
						|
    dest: "{{ nextcloud_install_path }}/nextcloud/docker-compose.yml"
 | 
						|
    owner: "{{ nextcloud_install_user }}"
 | 
						|
    group: "{{ nextcloud_install_user }}"
 | 
						|
    mode: '0644'
 | 
						|
 | 
						|
- name: Output docker-compose.yml
 | 
						|
  shell: cat {{ nextcloud_install_path }}/nextcloud/docker-compose.yml
 | 
						|
  register: output
 | 
						|
 | 
						|
- debug:
 | 
						|
    var: output
 | 
						|
 | 
						|
- name: Provide database env vars
 | 
						|
  copy:
 | 
						|
    dest: "{{ nextcloud_install_path }}/nextcloud/db.env"
 | 
						|
    owner: "{{ nextcloud_install_user }}"
 | 
						|
    group: "{{ nextcloud_install_user }}"
 | 
						|
    mode: '0640'
 | 
						|
    content: |
 | 
						|
      # See https://github.com/docker-library/mariadb/issues/262
 | 
						|
      MYSQL_INITDB_SKIP_TZINFO=1
 | 
						|
      MYSQL_ROOT_PASSWORD={{ nextcloud_mariadb_root_password }}
 | 
						|
      MYSQL_DATABASE={{ nextcloud_mysql_database }}
 | 
						|
      MYSQL_PASSWORD={{ nextcloud_mariadb_password }}
 | 
						|
      MYSQL_USER={{ nextcloud_mariadb_user }}
 | 
						|
 | 
						|
- name: Provide Nextcloud env vars
 | 
						|
  copy:
 | 
						|
    dest: "{{ nextcloud_install_path }}/nextcloud/nextcloud.env"
 | 
						|
    owner: "{{ nextcloud_install_user }}"
 | 
						|
    group: "{{ nextcloud_install_user }}"
 | 
						|
    mode: '0640'
 | 
						|
    content: |
 | 
						|
      VIRTUAL_HOST={{ nextcloud_virtual_host }}
 | 
						|
      LETSENCRYPT_HOST={{ nextcloud_letsencrypt_host }}
 | 
						|
      LETSENCRYPT_EMAIL={{ nextcloud_letsencrypt_email }}
 | 
						|
      MYSQL_HOST={{ nextcloud_mysql_host }}
 | 
						|
      MYSQL_DATABASE={{ nextcloud_mysql_database }}
 | 
						|
      MYSQL_PASSWORD={{ nextcloud_mariadb_password }}
 | 
						|
      MYSQL_USER={{ nextcloud_mariadb_user }}
 | 
						|
      NEXTCLOUD_ADMIN_USER={{ nextcloud_admin_user }}
 | 
						|
      NEXTCLOUD_ADMIN_PASSWORD={{ nextcloud_admin_password }}
 | 
						|
      NEXTCLOUD_TRUSTED_DOMAINS={{ nextcloud_trusted_domains }}
 | 
						|
      SMTP_HOST={{ nextcloud_smtp_host }}
 | 
						|
      SMTP_SECURE={{ nextcloud_smtp_secure }}
 | 
						|
      SMTP_PORT={{ nextcloud_smtp_port }}
 | 
						|
      SMTP_AUTHTYPE={{ nextcloud_smtp_authtype }}
 | 
						|
      SMTP_NAME={{ nextcloud_smtp_name }}
 | 
						|
      SMTP_PASSWORD={{ nextcloud_smtp_password }}
 | 
						|
      MAIL_FROM_ADDRESS={{ nextcloud_mail_from_address }}
 | 
						|
      MAIL_DOMAIN={{ nextcloud_mail_domain }}
 | 
						|
 | 
						|
- name: Provide restic-compose-backup env vars
 | 
						|
  copy:
 | 
						|
    dest: "{{ nextcloud_install_path }}/nextcloud/restic-compose-backup.env"
 | 
						|
    owner: "{{ nextcloud_install_user }}"
 | 
						|
    group: "{{ nextcloud_install_user }}"
 | 
						|
    mode: '0640'
 | 
						|
    content: |
 | 
						|
      AWS_ACCESS_KEY_ID={{ nextcloud_restic_aws_access_key_id }}
 | 
						|
      AWS_SECRET_ACCESS_KEY={{ nextcloud_restic_aws_secret_access_key }}
 | 
						|
      RESTIC_REPOSITORY={{ nextcloud_restic_repository }}
 | 
						|
      RESTIC_PASSWORD={{ nextcloud_restic_password }}
 | 
						|
      # snapshot prune rules
 | 
						|
      RESTIC_KEEP_DAILY={{ nextcloud_restic_keep_daily}}
 | 
						|
      RESTIC_KEEP_WEEKLY={{ nextcloud_restic_keep_weekly }}
 | 
						|
      RESTIC_KEEP_MONTHLY={{ nextcloud_restic_keep_monthly }}
 | 
						|
      RESTIC_KEEP_YEARLY={{ nextcloud_restic_keep_yearly }}
 | 
						|
      # Cron schedule. Run every day at 1am
 | 
						|
      CRON_SCHEDULE="{{ nextcloud_restic_cron_schedule }}"
 | 
						|
  when: nextcloud_enable_restic_compose_backup == true
 | 
						|
 | 
						|
- name: "docker-compose: Teardown existing Nextcloud service"
 | 
						|
  docker_compose:
 | 
						|
    project_src: "{{ nextcloud_install_path }}/nextcloud/"
 | 
						|
    state: absent
 | 
						|
  tags: ['never', 'teardown']
 | 
						|
 | 
						|
- name: "docker-compose: Start Nextcloud service"
 | 
						|
  docker_compose:
 | 
						|
    project_src: "{{ nextcloud_install_path }}/nextcloud/"
 | 
						|
  register: output
 | 
						|
  tags: service_start
 | 
						|
 | 
						|
- debug:
 | 
						|
    var: output
 | 
						|
 | 
						|
- assert:
 | 
						|
    that:
 | 
						|
      - "output.ansible_facts['nextcloud-app']['nextcloud-app'].state.running"
 | 
						|
 | 
						|
- name: Get container IP
 | 
						|
  set_fact:
 | 
						|
    nextcloud_ip: "{{ output.ansible_facts['nextcloud-app']['nextcloud-app'].networks.nextcloud_default.IPAddress }}"
 | 
						|
 | 
						|
- name: "Waiting for Nextcloud container to become available"
 | 
						|
  become: false
 | 
						|
  wait_for:
 | 
						|
    host: "{{ nextcloud_ip }}"
 | 
						|
    port: 80
 | 
						|
 | 
						|
- name: "docker-compose: Set overwriteprotocol using occ"
 | 
						|
  shell:
 | 
						|
    chdir: "{{ nextcloud_install_path }}/nextcloud/"
 | 
						|
    cmd: docker-compose exec -T -u www-data nextcloud-app /bin/bash -c './occ config:system:set overwriteprotocol --value="{{ nextcloud_overwrite_protocol }}"'
 | 
						|
 | 
						|
- name: "docker-compose: Set overwrite.cli.url using occ"
 | 
						|
  shell:
 | 
						|
    chdir: "{{ nextcloud_install_path }}/nextcloud/"
 | 
						|
    cmd: docker-compose exec -T -u www-data nextcloud-app /bin/bash -c './occ config:system:set overwrite.cli.url --value="{{ nextcloud_overwrite_cli_url }}"'
 | 
						|
 | 
						|
- name: "docker-compose: Set overwritehost using occ"
 | 
						|
  shell:
 | 
						|
    cmd: docker-compose exec -T -u www-data nextcloud-app /bin/bash -c './occ config:system:set overwritehost --value="{{ nextcloud_overwrite_host }}"'
 | 
						|
    chdir: "{{ nextcloud_install_path }}/nextcloud/"
 | 
						|
 | 
						|
- name: "Test whether Nextcloud is healthy from the outside"
 | 
						|
  when: not ansible_check_mode
 | 
						|
  become: false
 | 
						|
  uri:
 | 
						|
    url: "{{ nextcloud_overwrite_cli_url }}/login"
 | 
						|
    return_content: yes
 | 
						|
    timeout: 300
 | 
						|
    validate_certs: no
 | 
						|
  register: url_check
 | 
						|
  delegate_to: localhost
 | 
						|
  until: "'Nextcloud' in url_check.content"
 | 
						|
  retries: 5
 | 
						|
  delay: 10
 | 
						|
  tags: health
 | 
						|
 | 
						|
- debug:
 | 
						|
    var: url_check
 | 
						|
  tags: debug
 |