main.yml 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. ---
  2. # tasks file for nextcloud
  3. - name: Main... Set Nextcloud db_port to ProxySQL port instead of default MySQL
  4. set_fact:
  5. db_port: "6033"
  6. when: "'db_lbal_servers' in groups.keys()"
  7. - name: Main... Ovewrite Nextcloud db_host if no SQL_loadBalancer
  8. set_fact:
  9. db_host: "{{ groups['db_servers'][0] }}"
  10. when: "'db_lbal_servers' not in groups.keys()"
  11. #- name: Main... Set Nextcloud redis_host variable
  12. # set_fact:
  13. # redis_host: "{{ groups['redis_servers'][0] }}"
  14. # when: "'redis_servers' in groups.keys()"
  15. #- name: Main... Check if Nexctloud's gonna deployed on multiple web servers
  16. #debug: var=nc_multiple
  17. #"{{ groups['all'] | length }}"
  18. - name: Main... Show Selinux variable
  19. debug: var=ansible_selinux
  20. - include_tasks: "prep_os/{{ ansible_os_family }}.yml"
  21. - name: Main... Create shared directories (web & data)
  22. file:
  23. path: "{{ item }}"
  24. state: directory
  25. owner: "{{ nextcloud_websrv_user }}"
  26. group: "{{ nextcloud_websrv_group }}"
  27. mode: 0750
  28. with_items:
  29. - "{{ nc_data_dir }}"
  30. - "{{ http_webroot }}"
  31. ignore_errors: yes
  32. - name: Main... Mount shared directories
  33. include_tasks: "nc_storage.yml"
  34. #when: nc_multiple != ""
  35. when: (groups['web_servers'] | length) > 1
  36. #- name: Main... Check web directory
  37. # stat:
  38. # path: "{{ http_webroot }}"
  39. # register: is_http_webroot
  40. #- name: Main... Check Selinux
  41. # include_tasks: "prep_os/selinux.yml"
  42. # when:
  43. # - (ansible_os_family == "RedHat")
  44. # - (ansible_selinux.status == "enabled")
  45. - name: Main... Check if Nextcloud is already in the web repo
  46. stat:
  47. path: "{{ http_webroot }}/nextcloud/index.php"
  48. register: nc_nextcloud_downloaded
  49. delegate_to: "{{ groups['web_servers'][0] }}"
  50. run_once: true
  51. #- name: Main... Check is Set Nextcloud redis_host variable
  52. # set_fact:
  53. # nc_multiple: true
  54. # when: redis_host != ""
  55. #
  56. #- name: Main... is multiple nextcloud web servers ?
  57. # debug: var=nc_multiple
  58. - name: Main... Download and Install Nextcloud
  59. include_tasks: "nc_download.yml"
  60. args:
  61. apply:
  62. delegate_to: "{{ groups['web_servers'][0] }}"
  63. run_once: true
  64. when: (nc_nextcloud_downloaded.stat.isreg is undefined) or (not nc_nextcloud_downloaded.stat.isreg)
  65. - name: Main... Start {{ http_service_name }} service
  66. service:
  67. name: "{{ http_service_name }}"
  68. state: started
  69. - name: Main... Check Nextcloud status
  70. become_user: "{{ nextcloud_websrv_user }}"
  71. become: true
  72. shell: "{{ php_bin }} occ status --output=json"
  73. args:
  74. chdir: "{{ http_webroot }}/nextcloud"
  75. register: jsoncontent
  76. delegate_to: "{{ groups['web_servers'][0] }}"
  77. run_once: true
  78. - name: Main... Set Nextcloud variables status
  79. set_fact:
  80. nc_status: "{{ jsoncontent.stdout | from_json }}"
  81. delegate_to: "{{ groups['web_servers'][0] }}"
  82. run_once: true
  83. - name: Main... Check the nc_status content
  84. debug: var=nc_status
  85. delegate_to: "{{ groups['web_servers'][0] }}"
  86. run_once: true
  87. - name: Main... Install and deploy Nextcloud if needed
  88. include_tasks: nc_install.yml
  89. args:
  90. apply:
  91. delegate_to: "{{ groups['web_servers'][0] }}"
  92. run_once: true
  93. when: nc_status.installed|bool == false
  94. - name: Main... Setup nextcloud
  95. include_tasks: nc_setup.yml
  96. args:
  97. apply:
  98. delegate_to: "{{ groups['web_servers'][0] }}"
  99. run_once: true
  100. #when: nc_status.installed|bool == false
  101. - name: Main... Set Trusted Local Domain lists
  102. set_fact:
  103. list_zero:
  104. - "{{ nc_global_name | default() }}"
  105. list_one: "{{ groups['lbal_servers'] | default([]) }}"
  106. list_two: "{{ groups['web_servers'] }}"
  107. - name: Main... Merge the Trusted lists
  108. set_fact:
  109. trusted_dom: "{{ list_zero + list_one + list_two }}"
  110. - name: Main... Set a local redirect name
  111. set_fact:
  112. redirect_name: "{{ groups['web_servers'][0] }}"
  113. - name: Main... Set a global redirect name if loadbalancing
  114. set_fact:
  115. redirect_name: "{{ nc_global_name | default(nc.test) }}"
  116. when: groups['lbal_servers'] is defined and (groups['lbal_servers']|length>0)
  117. - name: Main... Set Trusted Local Domain
  118. become_user: "{{ nextcloud_websrv_user }}"
  119. become: true
  120. shell: "{{ php_bin }} occ config:system:set trusted_domains {{ occ_idx }} --value={{ item }}"
  121. args:
  122. chdir: "{{ http_webroot }}/nextcloud"
  123. loop: "{{ trusted_dom }}"
  124. loop_control:
  125. index_var: occ_idx
  126. pause: 2
  127. delegate_to: "{{ groups['web_servers'][0] }}"
  128. run_once: true
  129. - name: Main... Set Nextcloud overwrite url and host
  130. become_user: "{{ nextcloud_websrv_user }}"
  131. become: true
  132. shell: "{{ php_bin }} occ config:system:set {{ item.name }} --value={{ item.value }}"
  133. args:
  134. chdir: "{{ http_webroot }}/nextcloud"
  135. with_items:
  136. - { name: 'overwritehost', value: '{{ redirect_name }}' }
  137. - { name: 'overwrite.cli.url', value: 'https://{{ redirect_name }}' }
  138. delegate_to: "{{ groups['web_servers'][0] }}"
  139. run_once: true
  140. - name: Setup... Configure Cron
  141. cron:
  142. name: "Nextcloud Cronjob"
  143. minute: "*/{{ nc_cron_period }}"
  144. user: "{{ nextcloud_websrv_user }}"
  145. job: "{{ php_bin }} -f {{ http_webroot }}/nextcloud/cron.php"
  146. cron_file: "nextcloud"
  147. when: (nc_background_cron | bool)
  148. delegate_to: "{{ groups['web_servers'][0] }}"
  149. run_once: true
  150. - name: Main... Check Selinux
  151. include_tasks: "prep_os/selinux.yml"
  152. when:
  153. - (ansible_os_family == "RedHat")
  154. - (ansible_selinux.status == "enabled")
  155. - name: Main... Restart {{ http_service_name }} service
  156. service:
  157. name: "{{ http_service_name }}"
  158. state: restarted
  159. - name: Main... First run Cron
  160. become_user: "{{ nextcloud_websrv_user }}"
  161. become: true
  162. shell: "{{ php_bin }} -f cron.php"
  163. args:
  164. chdir: "{{ http_webroot }}/nextcloud"
  165. delegate_to: "{{ groups['web_servers'][0] }}"
  166. run_once: true