--- ######### # Run command line installation. # the web server must be running by now in order to launch the installation - name: Trigger all pending handlers meta: flush_handlers - name: "[NC] - Setting directory ownership & permissions for the data folder" file: path: "{{ nextcloud_data_dir }}" mode: "u=rwX,g=rX,o-rwx" recurse: yes state: directory owner: "{{ nextcloud_websrv_user }}" group: "{{ nextcloud_websrv_group }}" - name: "[NC] - generate {{ nextcloud_admin_name }} password:" set_fact: nextcloud_admin_pwd="{{ lookup( 'password', 'nextcloud_instances/'+ nextcloud_instance_name +'/web_admin.pwd length=10' ) }}" when: nextcloud_admin_pwd is not defined - name: "[NC] - Set temporary permissions for command line installation." file: path: "{{ nextcloud_webroot }}" state: directory recurse: yes owner: "{{ nextcloud_websrv_user }}" group: "{{ nextcloud_websrv_group }}" - block: - name: "[NC] - removing possibly old or incomplete config.php" file: path: "{{ nextcloud_webroot }}/config/config.php" state: absent - name: "[NC] - Run occ installation command" become_user: "{{ nextcloud_websrv_user }}" become_flags: "{{ ansible_become_flags | default(omit) }}" become: yes command: > php occ maintenance:install --database={{ nextcloud_tmp_backend }} --database-host={{ nextcloud_db_host }} --database-name={{ nextcloud_db_name }} --database-user={{ nextcloud_db_admin }} --database-pass={{ nextcloud_db_pwd }} --admin-user={{ nextcloud_admin_name }} --admin-pass={{ nextcloud_admin_pwd }} --data-dir={{ nextcloud_data_dir }} args: chdir: "{{ nextcloud_webroot }}" creates: "{{ nextcloud_webroot }}/config/config.php" vars: # mariadb is equal to mysql for occ nextcloud_tmp_backend: "{{ 'mysql' if nextcloud_db_backend == 'mariadb' else nextcloud_db_backend }}" notify: reload http - name: "[NC] - Verify config.php - check filesize" stat: path="{{ nextcloud_webroot }}/config/config.php" register: nc_installation_confsize failed_when: nc_installation_confsize.stat.size is undefined or nc_installation_confsize.stat.size <= 100 - name: "[NC] - Verify config.php - php syntax check" command: "php -l {{ nextcloud_webroot }}/config/config.php" register: nc_installation_confphp changed_when: False failed_when: - nc_installation_confphp.rc is defined - nc_installation_confphp.rc != 0 rescue: # - name: Unfix su issue with occ # include_tasks: tasks/unfix_su.yml # when: ansible_become_method == "su" - name: "[NC] - removing config.php when occ fail" file: path: "{{ nextcloud_webroot }}/config/config.php" state: absent failed_when: True - name: "[NC] - Set Trusted Domains" become_user: "{{ nextcloud_websrv_user }}" become_flags: "{{ ansible_become_flags | default(omit) }}" become: yes command: php occ config:system:set trusted_domains {{ item.0 }} --value="{{ item.1 | ipwrap }}" args: chdir: "{{ nextcloud_webroot }}" with_indexed_items: "{{ nextcloud_trusted_domain }}" changed_when: true - name: "[NC] - Set Trusted Proxies" become_user: "{{ nextcloud_websrv_user }}" become_flags: "{{ ansible_become_flags | default(omit) }}" become: yes command: php occ config:system:set trusted_proxies {{ item.0 }} --value="{{ item.1 }}" args: chdir: "{{ nextcloud_webroot }}" with_indexed_items: "{{ nextcloud_trusted_proxies }}" changed_when: true - name: "[NC] - Set Nextcloud settings in config.php" become_user: "{{ nextcloud_websrv_user }}" become_flags: "{{ ansible_become_flags | default(omit) }}" become: yes command: php occ config:system:set {{ item.name }} --value="{{ item.value }}" args: chdir: "{{ nextcloud_webroot }}" with_items: - "{{ nextcloud_config_settings }}" changed_when: true - name: "[NC] - Set Redis Server" become_user: "{{ nextcloud_websrv_user }}" become_flags: "{{ ansible_become_flags | default(omit) }}" become: yes command: php occ config:system:set {{ item.name }} --value="{{ item.value }}" args: chdir: "{{ nextcloud_webroot }}" with_items: - "{{ nextcloud_redis_settings }}" when: (nextcloud_install_redis_server | bool) - name: "[NC] - Install Cronjob" cron: name: "Nextcloud Cronjob" minute: "*/15" user: "{{ nextcloud_websrv_user }}" job: "php {{ nextcloud_webroot }}/cron.php" cron_file: "nextcloud" when: (nextcloud_background_cron | bool) - name: "[NC] - Set Cron method to Crontab" become_user: "{{ nextcloud_websrv_user }}" become_flags: "{{ ansible_become_flags | default(omit) }}" become: yes command: php occ background:cron args: chdir: "{{ nextcloud_webroot }}" when: (nextcloud_background_cron | bool) - name: "[NC] - Set Custom Mimetype" copy: dest: "{{ nextcloud_webroot }}/config/mimetypemapping.json" src: files/nextcloud_custom_mimetypemapping.json - name: "[NC] - Ensure Nextcloud directories are 0750" command: find {{ nextcloud_data_dir }} -type d -exec chmod -c 0750 {} \; register: nc_installation_chmod_result changed_when: "nc_installation_chmod_result.stdout != \"\"" - name: "[NC] - Ensure Nextcloud files are 0640" command: find {{ nextcloud_data_dir }} -type f -exec chmod -c 0640 {} \; register: nc_installation_chmod_result changed_when: "nc_installation_chmod_result.stdout != \"\"" - name: "[NC] - Setting stronger directory ownership" file: path: "{{ nextcloud_webroot }}/{{ item }}/" recurse: yes owner: "{{ nextcloud_websrv_user }}" group: "{{ nextcloud_websrv_group }}" state: directory with_items: - apps - assets - config - themes - updater