Playbooks to a new Lilik
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

291 lines
8.6 KiB

  1. - name: 'install requirements'
  2. apt:
  3. pkg:
  4. - 'sudo'
  5. - 'bzip2'
  6. #- 'ffmpeg'
  7. - 'postgresql'
  8. - 'postgresql-contrib'
  9. - 'python3-psycopg2'
  10. - 'ca-certificates'
  11. state: 'present'
  12. update_cache: true
  13. cache_valid_time: 3600
  14. tags:
  15. - 'packages'
  16. - name: 'install php'
  17. import_role: name='service'
  18. vars:
  19. service_name: 'php7.4-fpm'
  20. service_packages:
  21. - 'php7.4-fpm'
  22. - 'php7.4-common'
  23. - 'php7.4-xml'
  24. - 'php7.4-gd'
  25. - 'php7.4-json'
  26. - 'php7.4-mbstring'
  27. - 'php7.4-zip'
  28. - 'php7.4-pgsql'
  29. - 'php7.4-ldap'
  30. - 'php7.4-curl'
  31. - 'php7.4-intl'
  32. - 'php7.4-bz2'
  33. - 'php7.4-redis'
  34. - 'php7.4-apcu'
  35. - 'php-imagick'
  36. - block:
  37. - name: 'create nextcloud DB'
  38. postgresql_db:
  39. name: 'nextcloud'
  40. - name: 'create nextcloud DB user'
  41. postgresql_user:
  42. name: 'www-data'
  43. db: 'nextcloud'
  44. priv: 'ALL'
  45. become: true
  46. become_method: 'su'
  47. become_user: 'postgres'
  48. - name: 'configure php-fpm'
  49. lineinfile:
  50. path: '/etc/php/7.4/fpm/pool.d/www.conf'
  51. line: '{{ item.line }}'
  52. regexp: '{{ item.regexp }}'
  53. loop:
  54. - { line: 'env[PATH] = /usr/local/bin:/usr/bin:/bin', regexp: '^;?env\[PATH\] = ' }
  55. - { line: 'env[TEMP] = /tmp', regexp: '^;?env\[TEMP\] = ' }
  56. - { line: 'env[TMP] = /tmp', regexp: '^;?env\[TMP\] = ' }
  57. - { line: 'env[TMPDIR] = /tmp', regexp: '^;?env\[TMPDIR\] = ' }
  58. - { line: 'pm = dynamic', regexp: '^;?pm = ' }
  59. - { line: 'pm.max_children = 120', regexp: '^;?pm.max_children = ' }
  60. - { line: 'pm.start_servers = 12', regexp: '^;?pm.start server = ' }
  61. - { line: 'pm.min_spare_servers = 6', regexp: '^;?pm.min_spare_servers = ' }
  62. - { line: 'pm.max_spare_servers = 18', regexp: '^;?pm.max_spare_servers = ' }
  63. notify: 'restart php7.4-fpm'
  64. - name: 'configure php.ini'
  65. lineinfile:
  66. path: '/etc/php/7.4/fpm/php.ini'
  67. line: '{{ item.line }}'
  68. regexp: '{{ item.regexp }}'
  69. loop:
  70. - { line: 'memory_limit = 512M', regexp: '^memory_limit =' }
  71. - { line: 'opcache.enable=1', regexp: '^[;]?opcache_enable=' }
  72. - { line: 'opcache.interned_strings_buffer=8', regexp: '^;?opcache.interned_strings_buffer=' }
  73. - { line: 'opcache.max_accelerated_files=10000', regexp: '^;?opcache.max_accelerated_files=' }
  74. - { line: 'opcache.memory_consumption=128', regexp: '^;?opcache.memory_consumption=' }
  75. - { line: 'opcache.save_comments=1', regexp: '^;?opcache.save_comments=' }
  76. - { line: 'opcache.revalidate_freq=1', regexp: '^;?opcache.revalidate_freq=' }
  77. notify: 'restart php7.4-fpm'
  78. - name: 'download nextcloud'
  79. get_url:
  80. url: 'https://download.nextcloud.com/server/releases/nextcloud-{{ nextcloud_version }}.tar.bz2'
  81. dest: '/opt/nextcloud.tar.bz2'
  82. register: 'nextcloud_new_download'
  83. tags:
  84. - 'packages'
  85. - name: 'unpack nextcloud'
  86. unarchive:
  87. remote_src: true
  88. src: '/opt/nextcloud.tar.bz2'
  89. dest: '/opt'
  90. owner: 'www-data'
  91. group: 'www-data'
  92. mode: '0750'
  93. when: nextcloud_new_download.changed
  94. tags:
  95. - 'packages'
  96. - name: 'create nextcloud data folder'
  97. file:
  98. path: '/opt/nextcloud_data'
  99. owner: 'www-data'
  100. group: 'www-data'
  101. state: 'directory'
  102. - name: 'create nginx configuration'
  103. template:
  104. src: 'nextcloud.conf.j2'
  105. dest: '/etc/nginx/locations/{{ nextcloud_nginx_fqdn }}/nextcloud.conf'
  106. notify: 'reload nginx'
  107. - import_tasks: 'occ.yaml'
  108. vars:
  109. occ_args: '--no-warnings status --output json'
  110. ignore_changes: true
  111. - name: 'read installation status'
  112. set_fact:
  113. nextcloud_installed: '{{ occ_out.installed }}'
  114. - block:
  115. - name: 'create random root password'
  116. gen_passwd: length=20
  117. register: 'nextcloud_password'
  118. no_log: true
  119. - name: 'set initial root password'
  120. set_fact:
  121. nextcloud_initial_root_password: '{{ nextcloud_password.passwd }}'
  122. no_log: true
  123. - name: 'store root password plaintext'
  124. copy:
  125. content: '{{ nextcloud_initial_root_password }}'
  126. dest: '/etc/nextcloud.secret'
  127. mode: '0700'
  128. no_log: true
  129. diff: false
  130. - name: 'emit warning for initial_root_password not set'
  131. fail:
  132. msg: >-
  133. Warning! First Install and `initial_root_password` not provided.
  134. Random password generated and stored in /etc/nextcloud.secret.
  135. **WIPE AS SOON AS POSSIBLE**
  136. failed_when: false
  137. when: (nextcloud_initial_root_password is not defined) and (not nextcloud_installed)
  138. - name: 'install nextcloud'
  139. include_tasks: 'occ.yaml'
  140. vars:
  141. occ_args: >-
  142. maintenance:install
  143. --database 'pgsql'
  144. --database-name 'nextcloud'
  145. --database-host '/var/run/postgresql'
  146. --database-user 'www-data'
  147. --database-pass ''
  148. --admin-pass '{{ nextcloud_initial_root_password }}'
  149. --data-dir '/opt/nextcloud_data'
  150. --no-interaction
  151. nojson: true
  152. when: not nextcloud_installed
  153. - name: 'set trusted_domains'
  154. occ:
  155. command: 'config:system:set'
  156. key: 'trusted_domains {{ idx }}'
  157. value: '{{ item }}'
  158. loop: '{{ [ "localhost", nextcloud_nginx_fqdn ] + nextcloud_nginx_alternate_fqdns }}'
  159. loop_control:
  160. index_var: idx
  161. - name: 'update tls ldap server ca'
  162. copy:
  163. content: '{{ ldap_tls_server_ca }}'
  164. dest: '/etc/ldap/server_ca.crt'
  165. tags:
  166. - 'tls_int'
  167. - name: 'configure ldap client'
  168. copy:
  169. src: 'ldap.conf'
  170. dest: '/etc/ldap/ldap.conf'
  171. when: ldap_tls_enabled
  172. - name: 'enable user_ldap'
  173. occ:
  174. command: 'config:app:set'
  175. key: 'user_ldap enabled'
  176. value: 'yes'
  177. register: nextcloud_ldap_was_disabled
  178. tags:
  179. - 'service_password'
  180. - name: 'insall app user_ldap'
  181. import_tasks: 'occ.yaml'
  182. vars:
  183. occ_args: 'app:enable user_ldap'
  184. nojson: true
  185. ignore_changes: true
  186. - name: 'configure user_ldap'
  187. occ:
  188. command: 'config:app:set'
  189. key: 'user_ldap s01{{ item.key }}'
  190. value: '{{ item.value }}'
  191. loop: '{{ ldap_settings|dict2items }}'
  192. vars:
  193. ldap_settings:
  194. has_memberof_filter_support: '0'
  195. use_memberof_to_detect_membership: '0'
  196. ldap_host: '{{ ldap_server }}'
  197. ldap_port: '389'
  198. ldap_dn: 'cn={{ host_fqdn }},ou=Server,{{ ldap_basedn }}'
  199. ldap_base: 'ou=People,{{ ldap_basedn }}'
  200. ldap_base_users: 'ou=People,{{ ldap_basedn }}'
  201. ldap_base_groups: 'ou=Group,{{ ldap_basedn }}'
  202. ldap_login_filter: '(&(cn=%uid)(authorizedService=nextcloud))'
  203. ldap_user_filter: '(authorizedService=nextcloud)'
  204. ldap_userlist_filter: '(authorizedService=nextcloud)'
  205. ldap_group_filter: '(objectClass=groupOfNames)'
  206. ldap_group_display_name: 'description'
  207. ldap_group_member_assoc_attribute: 'member'
  208. ldap_attributes_for_user_search: 'cn'
  209. ldap_attributes_for_group_search: 'cn'
  210. ldap_display_name: 'sn'
  211. ldap_email_attr: 'mail'
  212. ldap_tls: '{{ 1 if ldap_tls_enabled else 0 }}'
  213. ldap_experienced_admin: '1'
  214. ldap_configuration_active: '1'
  215. ldap_expert_username_attr: 'cn'
  216. ldap_paging_size: '0'
  217. tags:
  218. - 'ldap'
  219. - name: 'generate nextcloud ldap password'
  220. gen_passwd: 'length=32'
  221. register: 'nextcloud_ldap_passwd'
  222. no_log: true
  223. when:
  224. - ldap_admin_dn is defined
  225. - ldap_admin_pw is defined
  226. tags:
  227. - 'service_password'
  228. - name: 'set nextcloud ldap password in ldap'
  229. delegate_to: 'localhost'
  230. ldap_passwd:
  231. dn: 'cn={{ host_fqdn }},ou=Server,{{ ldap_basedn }}'
  232. passwd: '{{ nextcloud_ldap_passwd.passwd }}'
  233. server_uri: 'ldap://{{ ldap_server }}'
  234. start_tls: '{{ ldap_tls_enabled }}'
  235. bind_dn: '{{ ldap_admin_dn }}'
  236. bind_pw: '{{ ldap_admin_pw }}'
  237. when: nextcloud_ldap_passwd.changed
  238. register: nextcloud_ldap_passwd_result
  239. tags:
  240. - 'service_password'
  241. - name: 'configure nextcloud ldap password with occ'
  242. import_tasks: 'occ.yaml'
  243. vars:
  244. occ_args: 'ldap:set-config s01 ldapAgentPassword {{ nextcloud_ldap_passwd.passwd }}'
  245. nojson: true
  246. no_log: true
  247. when: nextcloud_ldap_passwd_result.changed
  248. tags:
  249. - 'service_password'
  250. - name: 'MONITORING | add HTTP service'
  251. block:
  252. - name: 'MONITORING | add service to monitoring entry'
  253. set_fact:
  254. monitoring_entry: >
  255. {{ monitoring_entry | default({}) | combine({
  256. 'address': ansible_host,
  257. 'vhosts_uri': { nextcloud_nginx_fqdn: {'/': { 'content': 'nextcloud.com'}} },
  258. }, recursive=true) }}
  259. - name: 'MONITORING | update monitoring facts'
  260. set_fact:
  261. monitoring_facts: >
  262. {{ hostvars[monitoring_host]['monitoring_facts']
  263. | default({})
  264. | combine({host_fqdn: monitoring_entry}) }}
  265. delegate_facts: true
  266. delegate_to: '{{ monitoring_host }}'
  267. tags:
  268. - 'monitoring'
  269. ...