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.

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