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.

250 lines
6.3 KiB

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
  1. ---
  2. # ***** Icinga2 *****
  3. - name: 'PGSQL | preseed IDO debconf variables'
  4. # When icinga2-ido-pgsql is installed for the first time:
  5. # - db `icinga2` is automatically created as `postgres` user
  6. # - user `nagios` for socket authentication is created
  7. # - user `nagios` is granted privilegies on db `icinga2`
  8. # - db `icinga2` is populated with DB IDO schema
  9. # - pgsql is enabled as default DB IDO
  10. debconf:
  11. name: 'icinga2-ido-pgsql'
  12. question: 'icinga2-ido-pgsql/{{ item[0] }}'
  13. vtype: '{{ item[1] }}'
  14. value: '{{ item[2] }}'
  15. loop:
  16. - [ 'dbconfig-install', 'boolean', 'true' ]
  17. - [ 'enable', 'boolean', 'true' ]
  18. - [ 'pgsql/authmethod-user', 'string', 'ident' ]
  19. - [ 'pgsql/authmethod-admin', 'string', 'ident' ]
  20. - [ 'pgsql/method', 'string', 'Unix socket' ]
  21. - [ 'db/dbname', 'string', 'icinga2' ]
  22. - [ 'db/app-user', 'string', 'nagios' ]
  23. - [ 'dbconfig-reinstall', 'boolean', 'true' ]
  24. - name: 'create icinga2 service role'
  25. include_role: name='service'
  26. vars:
  27. service_name: 'icinga2'
  28. service_packages:
  29. - 'icinga2'
  30. - 'icingacli'
  31. - 'icinga2-ido-pgsql'
  32. - 'monitoring-plugins'
  33. - 'nagios-plugins-contrib'
  34. - name: 'create directory for hosts configuration'
  35. file:
  36. path: '/etc/icinga2/conf.d/hosts/'
  37. state: 'directory'
  38. owner: 'nagios'
  39. group: 'nagios'
  40. mode: '0770'
  41. - name: 'customize icinga2 host conf.d'
  42. copy:
  43. src: 'icinga2/{{ item }}'
  44. dest: '/etc/icinga2/conf.d/{{ item }}'
  45. notify: 'reload icinga2'
  46. loop:
  47. - 'templates.conf'
  48. - 'services.conf'
  49. - 'ssh_services.conf'
  50. - name: 'create icinga2 ssh config dir'
  51. file:
  52. path: '/var/lib/nagios/.ssh'
  53. owner: 'nagios'
  54. group: 'nagios'
  55. mode: '0700'
  56. state: 'directory'
  57. tags:
  58. - 'ssh_certs'
  59. - name: 'upload user ssh ca'
  60. copy:
  61. content: |
  62. {% for ca in ssh_user_ca %}
  63. {{ ca }}
  64. {% endfor %}
  65. dest: '/var/lib/nagios/.ssh/user_ca.pub'
  66. tags:
  67. - 'ssh_certs'
  68. - name: 'upload host ssh ca'
  69. copy:
  70. content: |
  71. {% for ca in ssh_server_ca %}
  72. @cert-authority *.dmz.{{ domain }} {{ ca }}
  73. {% endfor %}
  74. dest: '/var/lib/nagios/.ssh/known_hosts'
  75. owner: 'nagios'
  76. group: 'nagios'
  77. tags:
  78. - 'ssh_certs'
  79. - name: 'generate and sign ssh user cert for icinga'
  80. import_role: name='ca_cert'
  81. vars:
  82. ca_cert_common_name: 'icinga'
  83. ca_cert_proto: 'ssh'
  84. ca_cert_client: true
  85. ca_cert_ssh_ca_path: '/var/lib/nagios/.ssh/user_ca.pub'
  86. ca_cert_ssh_key_path: '/var/lib/nagios/.ssh/id_ed25519'
  87. tags:
  88. - 'ssh_certs'
  89. - name: 'set private key ownership'
  90. file:
  91. path: '/var/lib/nagios/.ssh/id_ed25519'
  92. owner: 'nagios'
  93. group: 'nagios'
  94. tags:
  95. - 'ssh_certs'
  96. # ***** IcingaWeb2 *****
  97. - name: 'PGSQL | IcingaWeb2 tunings'
  98. block:
  99. - name: 'PGSQL | create IcingaWeb2 user preference DB'
  100. postgresql_db:
  101. name: 'icingaweb2'
  102. register: icingaweb2_db
  103. - name: 'PGSQL | create IcingaWeb2 socket authentication user'
  104. postgresql_user:
  105. db: 'icingaweb2'
  106. name: 'www-data'
  107. priv: 'ALL'
  108. - name: 'PGSQL | GRANT CONNECT to IDO'
  109. postgresql_privs:
  110. db: 'icinga2'
  111. privs: 'CONNECT'
  112. type: 'database'
  113. role: 'www-data'
  114. - name: 'PGSQL | GRANT SCHEMA USAGE on IDO'
  115. postgresql_privs:
  116. db: 'icinga2'
  117. privs: 'USAGE'
  118. type: 'schema'
  119. objs: 'public'
  120. role: 'www-data'
  121. - name: 'PGSQL | GRANT SELECT on all IDO tables (existing)'
  122. postgresql_privs:
  123. db: 'icinga2'
  124. privs: 'SELECT'
  125. type: 'table'
  126. schema: 'public'
  127. objs: 'ALL_IN_SCHEMA'
  128. role: 'www-data'
  129. - name: 'PGSQL | GRANT SELECT on all IDO tables (default privilege)'
  130. postgresql_privs:
  131. db: 'icinga2'
  132. privs: 'SELECT'
  133. type: 'default_privs'
  134. schema: 'public'
  135. objs: 'TABLES'
  136. role: 'www-data'
  137. target_roles: 'nagios'
  138. become: true
  139. become_method: 'su'
  140. become_user: 'postgres'
  141. - name: 'install IcingaWeb2 packages'
  142. apt:
  143. pkg:
  144. - 'icingaweb2'
  145. - 'icingaweb2-module-monitoring'
  146. - 'php-ldap'
  147. - 'php-pgsql'
  148. - 'php-intl'
  149. - 'php-imagick'
  150. - 'php-fpm'
  151. - 'rsync'
  152. state: 'present'
  153. update_cache: true
  154. cache_valid_time: 3600
  155. tags:
  156. - 'packages'
  157. - name: 'PGSQL | populate IcingaWeb2 user preference DB'
  158. shell: 'cat /usr/share/icingaweb2/etc/schema/pgsql.schema.sql | psql -d icingaweb2'
  159. become: true
  160. become_method: 'su'
  161. become_flags: '-p'
  162. become_user: 'www-data'
  163. when: icingaweb2_db.changed
  164. - name: 'LDAP | upload client root ca'
  165. copy:
  166. content: '{{ ldap_tls_server_ca }}'
  167. dest: '/etc/ldap/server_ca.crt'
  168. tags:
  169. - 'tls_int'
  170. - name: 'LDAP | configure client'
  171. copy:
  172. src: 'ldap.conf'
  173. dest: '/etc/ldap/ldap.conf'
  174. when: ldap_tls_enabled
  175. - name: 'LDAP | generate client service password'
  176. gen_passwd: 'length=32'
  177. register: 'icingaweb2_ldap_passwd'
  178. no_log: true
  179. tags:
  180. - 'service_password'
  181. - name: 'LDAP | set client service password on server'
  182. delegate_to: 'localhost'
  183. ldap_passwd:
  184. dn: 'cn={{ host_fqdn }},ou=Server,{{ ldap_basedn }}'
  185. passwd: '{{ icingaweb2_ldap_passwd.passwd }}'
  186. server_uri: 'ldap://{{ ldap_server }}'
  187. start_tls: '{{ ldap_tls_enabled }}'
  188. bind_dn: '{{ ldap_admin_dn }}'
  189. bind_pw: '{{ ldap_admin_pw }}'
  190. no_log: true
  191. tags:
  192. - 'service_password'
  193. - name: 'configure IcingaWeb2 (static files)'
  194. synchronize:
  195. src: 'icingaweb2'
  196. dest: '/etc'
  197. rsync_opts:
  198. - "--chmod=Du+rwx,Dg+rwx,Do-rwx,Fu+rw,Fg+rw,Fo-rwx"
  199. - "--chown=root:icingaweb2"
  200. - name: 'create enabledModules folder'
  201. file:
  202. path: '/etc/icingaweb2/enabledModules/'
  203. state: 'directory'
  204. owner: 'root'
  205. group: 'icingaweb2'
  206. mode: '0770'
  207. - name: 'enable IcingaWeb2 monitoring plugin'
  208. file:
  209. src: '/usr/share/icingaweb2/modules/monitoring'
  210. dest: '/etc/icingaweb2/enabledModules/monitoring'
  211. state: 'link'
  212. - name: 'configure IcingaWeb2 (templates)'
  213. template:
  214. src: 'icingaweb2/{{ item }}.j2'
  215. dest: '/etc/icingaweb2/{{ item }}'
  216. owner: 'root'
  217. group: 'icingaweb2'
  218. mode: '0660'
  219. loop:
  220. - 'resources.ini'
  221. - 'authentication.ini'
  222. - 'groups.ini'
  223. - name: 'NGINX | configure IcingaWeb2 locations'
  224. template:
  225. src: 'icinga.conf'
  226. dest: "/etc/nginx/locations/{{ icingaweb2_nginx_fqdn }}/service.conf"
  227. notify:
  228. - 'reload nginx'
  229. ...