--- # tasks file for nextcloud - name: Main... Set Nextcloud db_port to ProxySQL port instead of default MySQL set_fact: db_port: "6033" when: "'db_lbal_servers' in groups.keys()" - name: Main... Ovewrite Nextcloud db_host if no SQL_loadBalancer set_fact: db_host: "{{ groups['db_servers'][0] }}" when: "'db_lbal_servers' not in groups.keys()" #- name: Main... Set Nextcloud redis_host variable # set_fact: # redis_host: "{{ groups['redis_servers'][0] }}" # when: "'redis_servers' in groups.keys()" #- name: Main... Check if Nexctloud's gonna deployed on multiple web servers #debug: var=nc_multiple #"{{ groups['all'] | length }}" - name: Main... Show Selinux variable debug: var=ansible_selinux - include_tasks: "prep_os/{{ ansible_os_family }}.yml" - name: Main... Create shared directories (web & data) file: path: "{{ item }}" state: directory owner: "{{ nextcloud_websrv_user }}" group: "{{ nextcloud_websrv_group }}" mode: 0750 with_items: - "{{ nc_data_dir }}" - "{{ http_webroot }}" ignore_errors: yes - name: Main... Mount shared directories include_tasks: "nc_storage.yml" #when: nc_multiple != "" when: (groups['web_servers'] | length) > 1 #- name: Main... Check web directory # stat: # path: "{{ http_webroot }}" # register: is_http_webroot #- name: Main... Check Selinux # include_tasks: "prep_os/selinux.yml" # when: # - (ansible_os_family == "RedHat") # - (ansible_selinux.status == "enabled") - name: Main... Check if Nextcloud is already in the web repo stat: path: "{{ http_webroot }}/nextcloud/index.php" register: nc_nextcloud_downloaded delegate_to: "{{ groups['web_servers'][0] }}" run_once: true #- name: Main... Check is Set Nextcloud redis_host variable # set_fact: # nc_multiple: true # when: redis_host != "" # #- name: Main... is multiple nextcloud web servers ? # debug: var=nc_multiple - name: Main... Download and Install Nextcloud include_tasks: "nc_download.yml" args: apply: delegate_to: "{{ groups['web_servers'][0] }}" run_once: true when: (nc_nextcloud_downloaded.stat.isreg is undefined) or (not nc_nextcloud_downloaded.stat.isreg) - name: Main... Start {{ http_service_name }} service service: name: "{{ http_service_name }}" state: started - name: Main... Check Nextcloud status become_user: "{{ nextcloud_websrv_user }}" become: true shell: "{{ php_bin }} occ status --output=json" args: chdir: "{{ http_webroot }}/nextcloud" register: jsoncontent delegate_to: "{{ groups['web_servers'][0] }}" run_once: true - name: Main... Set Nextcloud variables status set_fact: nc_status: "{{ jsoncontent.stdout | from_json }}" delegate_to: "{{ groups['web_servers'][0] }}" run_once: true - name: Main... Check the nc_status content debug: var=nc_status delegate_to: "{{ groups['web_servers'][0] }}" run_once: true - name: Main... Install and deploy Nextcloud if needed include_tasks: nc_install.yml args: apply: delegate_to: "{{ groups['web_servers'][0] }}" run_once: true when: nc_status.installed|bool == false - name: Main... Setup nextcloud include_tasks: nc_setup.yml args: apply: delegate_to: "{{ groups['web_servers'][0] }}" run_once: true #when: nc_status.installed|bool == false - name: Main... Set Trusted Local Domain lists set_fact: list_zero: - "{{ nc_global_name | default() }}" list_one: "{{ groups['lbal_servers'] | default([]) }}" list_two: "{{ groups['web_servers'] }}" - name: Main... Merge the Trusted lists set_fact: trusted_dom: "{{ list_zero + list_one + list_two }}" - name: Main... Set a local redirect name set_fact: redirect_name: "{{ groups['web_servers'][0] }}" - name: Main... Set a global redirect name if loadbalancing set_fact: redirect_name: "{{ nc_global_name | default(nc.test) }}" when: groups['lbal_servers'] is defined and (groups['lbal_servers']|length>0) - name: Main... Set Trusted Local Domain become_user: "{{ nextcloud_websrv_user }}" become: true shell: "{{ php_bin }} occ config:system:set trusted_domains {{ occ_idx }} --value={{ item }}" args: chdir: "{{ http_webroot }}/nextcloud" loop: "{{ trusted_dom }}" loop_control: index_var: occ_idx pause: 2 delegate_to: "{{ groups['web_servers'][0] }}" run_once: true - name: Main... Set Nextcloud overwrite url and host become_user: "{{ nextcloud_websrv_user }}" become: true shell: "{{ php_bin }} occ config:system:set {{ item.name }} --value={{ item.value }}" args: chdir: "{{ http_webroot }}/nextcloud" with_items: - { name: 'overwritehost', value: '{{ redirect_name }}' } - { name: 'overwrite.cli.url', value: 'https://{{ redirect_name }}' } delegate_to: "{{ groups['web_servers'][0] }}" run_once: true - name: Setup... Configure Cron cron: name: "Nextcloud Cronjob" minute: "*/{{ nc_cron_period }}" user: "{{ nextcloud_websrv_user }}" job: "{{ php_bin }} -f {{ http_webroot }}/nextcloud/cron.php" cron_file: "nextcloud" when: (nc_background_cron | bool) delegate_to: "{{ groups['web_servers'][0] }}" run_once: true - name: Main... Check Selinux include_tasks: "prep_os/selinux.yml" when: - (ansible_os_family == "RedHat") - (ansible_selinux.status == "enabled") - name: Main... Restart {{ http_service_name }} service service: name: "{{ http_service_name }}" state: restarted - name: Main... First run Cron become_user: "{{ nextcloud_websrv_user }}" become: true shell: "{{ php_bin }} -f cron.php" args: chdir: "{{ http_webroot }}/nextcloud" delegate_to: "{{ groups['web_servers'][0] }}" run_once: true