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.

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