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.

277 lines
7.2 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. - 'apt.conf'
  50. - name: 'disable local host conf.d'
  51. file:
  52. path: '/etc/icinga2/conf.d/hosts.conf'
  53. state: 'absent'
  54. notify: 'reload icinga2'
  55. - name: 'create icinga2 ssh config dir'
  56. file:
  57. path: '/var/lib/nagios/.ssh'
  58. owner: 'nagios'
  59. group: 'nagios'
  60. mode: '0700'
  61. state: 'directory'
  62. tags:
  63. - 'ssh_certs'
  64. - name: 'upload user ssh ca'
  65. copy:
  66. content: |
  67. {% for ca in ssh_user_ca %}
  68. {{ ca }}
  69. {% endfor %}
  70. dest: '/var/lib/nagios/.ssh/user_ca.pub'
  71. tags:
  72. - 'ssh_certs'
  73. - name: 'upload host ssh ca'
  74. copy:
  75. content: |
  76. {% for ca in ssh_server_ca %}
  77. @cert-authority *.dmz.{{ domain }} {{ ca }}
  78. {% endfor %}
  79. dest: '/var/lib/nagios/.ssh/known_hosts'
  80. owner: 'nagios'
  81. group: 'nagios'
  82. tags:
  83. - 'ssh_certs'
  84. - name: 'generate and sign ssh user cert for icinga'
  85. import_role: name='ca_cert'
  86. vars:
  87. ca_cert_common_name: 'icinga'
  88. ca_cert_proto: 'ssh'
  89. ca_cert_client: true
  90. ca_cert_ssh_ca_path: '/var/lib/nagios/.ssh/user_ca.pub'
  91. ca_cert_ssh_key_path: '/var/lib/nagios/.ssh/id_ed25519'
  92. tags:
  93. - 'ssh_certs'
  94. - name: 'set private key ownership'
  95. file:
  96. path: '/var/lib/nagios/.ssh/id_ed25519'
  97. owner: 'nagios'
  98. group: 'nagios'
  99. tags:
  100. - 'ssh_certs'
  101. # ***** IcingaWeb2 *****
  102. - name: 'PGSQL | IcingaWeb2 tunings'
  103. block:
  104. - name: 'PGSQL | create IcingaWeb2 user preference DB'
  105. postgresql_db:
  106. name: 'icingaweb2'
  107. register: icingaweb2_db
  108. - name: 'PGSQL | create IcingaWeb2 socket authentication user'
  109. postgresql_user:
  110. db: 'icingaweb2'
  111. name: 'www-data'
  112. priv: 'ALL'
  113. - name: 'PGSQL | GRANT CONNECT to IDO'
  114. postgresql_privs:
  115. db: 'icinga2'
  116. privs: 'CONNECT'
  117. type: 'database'
  118. role: 'www-data'
  119. - name: 'PGSQL | GRANT SCHEMA USAGE on IDO'
  120. postgresql_privs:
  121. db: 'icinga2'
  122. privs: 'USAGE'
  123. type: 'schema'
  124. objs: 'public'
  125. role: 'www-data'
  126. - name: 'PGSQL | GRANT SELECT on all IDO tables (existing)'
  127. postgresql_privs:
  128. db: 'icinga2'
  129. privs: 'SELECT'
  130. type: 'table'
  131. schema: 'public'
  132. objs: 'ALL_IN_SCHEMA'
  133. role: 'www-data'
  134. - name: 'PGSQL | GRANT SELECT on all IDO tables (default privilege)'
  135. postgresql_privs:
  136. db: 'icinga2'
  137. privs: 'SELECT'
  138. type: 'default_privs'
  139. schema: 'public'
  140. objs: 'TABLES'
  141. role: 'www-data'
  142. target_roles: 'nagios'
  143. become: true
  144. become_method: 'su'
  145. become_user: 'postgres'
  146. - name: 'install IcingaWeb2 packages'
  147. apt:
  148. pkg:
  149. - 'icingaweb2'
  150. - 'icingaweb2-module-monitoring'
  151. - 'php-ldap'
  152. - 'php-pgsql'
  153. - 'php-intl'
  154. - 'php-imagick'
  155. - 'php-fpm'
  156. - 'rsync'
  157. state: 'present'
  158. update_cache: true
  159. cache_valid_time: 3600
  160. tags:
  161. - 'packages'
  162. - name: 'PGSQL | populate IcingaWeb2 user preference DB'
  163. shell: 'cat /usr/share/icingaweb2/etc/schema/pgsql.schema.sql | psql -d icingaweb2'
  164. become: true
  165. become_method: 'su'
  166. become_flags: '-p'
  167. become_user: 'www-data'
  168. when: icingaweb2_db.changed
  169. - name: 'LDAP | upload client root ca'
  170. copy:
  171. content: '{{ ldap_tls_server_ca }}'
  172. dest: '/etc/ldap/server_ca.crt'
  173. tags:
  174. - 'tls_int'
  175. - name: 'LDAP | configure client'
  176. copy:
  177. src: 'ldap.conf'
  178. dest: '/etc/ldap/ldap.conf'
  179. when: ldap_tls_enabled
  180. - name: 'LDAP | generate client service password'
  181. gen_passwd: 'length=32'
  182. register: 'icingaweb2_ldap_passwd'
  183. no_log: true
  184. tags:
  185. - 'service_password'
  186. - name: 'LDAP | set client service password on server'
  187. delegate_to: 'localhost'
  188. ldap_passwd:
  189. dn: 'cn={{ host_fqdn }},ou=Server,{{ ldap_basedn }}'
  190. passwd: '{{ icingaweb2_ldap_passwd.passwd }}'
  191. server_uri: 'ldap://{{ ldap_server }}'
  192. start_tls: '{{ ldap_tls_enabled }}'
  193. bind_dn: '{{ ldap_admin_dn }}'
  194. bind_pw: '{{ ldap_admin_pw }}'
  195. no_log: true
  196. tags:
  197. - 'service_password'
  198. - name: 'configure IcingaWeb2 (static files)'
  199. synchronize:
  200. src: 'icingaweb2'
  201. dest: '/etc'
  202. rsync_opts:
  203. - "--chmod=Du+rwx,Dg+rwx,Do-rwx,Fu+rw,Fg+rw,Fo-rwx"
  204. - "--chown=root:icingaweb2"
  205. - name: 'create enabledModules folder'
  206. file:
  207. path: '/etc/icingaweb2/enabledModules/'
  208. state: 'directory'
  209. owner: 'root'
  210. group: 'icingaweb2'
  211. mode: '0770'
  212. - name: 'enable IcingaWeb2 monitoring plugin'
  213. file:
  214. src: '/usr/share/icingaweb2/modules/monitoring'
  215. dest: '/etc/icingaweb2/enabledModules/monitoring'
  216. state: 'link'
  217. - name: 'configure IcingaWeb2 (templates)'
  218. template:
  219. src: 'icingaweb2/{{ item }}.j2'
  220. dest: '/etc/icingaweb2/{{ item }}'
  221. owner: 'root'
  222. group: 'icingaweb2'
  223. mode: '0660'
  224. loop:
  225. - 'resources.ini'
  226. - 'authentication.ini'
  227. - 'groups.ini'
  228. - name: 'NGINX | configure IcingaWeb2 locations'
  229. template:
  230. src: 'icinga.conf'
  231. dest: "/etc/nginx/locations/{{ icingaweb2_nginx_fqdn }}/service.conf"
  232. notify:
  233. - 'reload nginx'
  234. - name: 'MONITORING | add HTTP service'
  235. block:
  236. - name: 'MONITORING | add service to monitoring entry'
  237. set_fact:
  238. monitoring_entry: >
  239. {{ monitoring_entry | default({}) | combine({
  240. 'address': ansible_host,
  241. 'vhosts_uri': { icingaweb2_nginx_fqdn: {'/icingaweb2': { 'onredirect': 'ok' }} },
  242. }, recursive=true) }}
  243. - name: 'MONITORING | update monitoring facts'
  244. set_fact:
  245. monitoring_facts: >
  246. {{ hostvars[monitoring_host]['monitoring_facts']
  247. | default({})
  248. | combine({host_fqdn: monitoring_entry}) }}
  249. delegate_facts: true
  250. delegate_to: '{{ monitoring_host }}'
  251. tags:
  252. - 'monitoring'
  253. ...