security.yml 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. - name: 'Install auto upgrades package'
  2. apt:
  3. pkg:
  4. - 'unattended-upgrades'
  5. state: 'present'
  6. when: with_auto_upgrade|bool
  7. tags:
  8. - 'security'
  9. - name: 'Reconfigure unattended-upgrades package'
  10. debconf:
  11. name: 'unattended-upgrades'
  12. question: 'unattended-upgrades/enable_auto_updates'
  13. value: 'true'
  14. vtype: 'boolean'
  15. notify:
  16. - 'Reconfigure unattended-upgrades'
  17. when: with_auto_upgrade|bool
  18. tags:
  19. - 'security'
  20. - name: 'Update unattended-upgrades configuration'
  21. template:
  22. src: '{{ item }}'
  23. dest: '/etc/apt/apt.conf.d/90unattended-upgrades-local'
  24. owner: 'root'
  25. group: 'root'
  26. mode: '0644'
  27. with_first_found:
  28. - 'apt/auto-upgrades.{{ ansible_lsb.codename }}.j2'
  29. - 'apt/auto-upgrades.j2'
  30. when: with_auto_upgrade|bool
  31. tags:
  32. - 'security'
  33. - name: 'Install logcheck packages'
  34. apt:
  35. pkg:
  36. - 'logcheck'
  37. - 'logcheck-database'
  38. state: 'present'
  39. when: with_logcheck|bool
  40. tags:
  41. - 'security'
  42. - name: 'Install local configuration files for logcheck'
  43. copy:
  44. src: 'logcheck/{{ item }}_local'
  45. dest: '/etc/logcheck/ignore.d.server/{{ item }}_local'
  46. owner: 'root'
  47. group: 'logcheck'
  48. mode: '0644'
  49. with_items:
  50. - 'amavisd-new'
  51. - 'ansible'
  52. - 'apache2'
  53. - 'bind'
  54. - 'dhclient'
  55. - 'dnsmasq'
  56. - 'dovecot'
  57. - 'dropbear'
  58. - 'ferm'
  59. - 'gammu'
  60. - 'git-daemon'
  61. - 'gogs'
  62. - 'influxd'
  63. - 'ipmi'
  64. - 'irqbalance'
  65. - 'kernel'
  66. - 'libpam-modules'
  67. - 'mon'
  68. - 'noip2'
  69. - 'ntp'
  70. - 'openvpn'
  71. - 'opendkim'
  72. - 'php'
  73. - 'postfix'
  74. - 'pure-ftpd'
  75. - 'pve-cluster'
  76. - 'redir'
  77. - 'rpc-mountd'
  78. - 'rrdcached'
  79. - 'rsyslog'
  80. - 'smartd'
  81. - 'spamd'
  82. - 'sshd'
  83. - 'svn'
  84. - 'sympa'
  85. - 'systemd'
  86. - 'zabbix-agentd'
  87. when: with_logcheck|bool
  88. tags:
  89. - 'security'
  90. - 'logcheck'
  91. - name: 'Update logcheck cron job'
  92. template:
  93. src: 'cron/logcheck.j2'
  94. dest: '/etc/cron.d/logcheck'
  95. owner: 'root'
  96. group: 'root'
  97. mode: '0644'
  98. when: with_logcheck|bool
  99. tags:
  100. - 'security'
  101. - 'logcheck'
  102. - name: 'Install rkhunter related packages'
  103. apt:
  104. pkg:
  105. - 'lsof'
  106. - 'unhide'
  107. - 'rkhunter'
  108. state: 'present'
  109. when: with_rkhunter|bool
  110. tags:
  111. - 'security'
  112. - name: 'Reconfigure rkhunter package'
  113. debconf:
  114. name: '{{ item.name }}'
  115. question: '{{ item.question }}'
  116. value: '{{ item.value }}'
  117. vtype: '{{ item.vtype }}'
  118. with_items:
  119. - { name: 'rkhunter', question: 'rkhunter/apt_autogen', value: 'true', vtype: 'boolean' }
  120. - { name: 'rkhunter', question: 'rkhunter/cron_daily_run', value: 'true', vtype: 'boolean' }
  121. - { name: 'rkhunter', question: 'rkhunter/cron_db_update', value: 'true', vtype: 'boolean' }
  122. notify:
  123. - 'Reconfigure rkhunter'
  124. when: with_rkhunter|bool
  125. tags:
  126. - 'security'
  127. - name: 'Update rkhunter configuration'
  128. template:
  129. src: 'rkhunter/{{ ansible_lsb.codename }}.conf.j2'
  130. dest: '/etc/rkhunter.conf'
  131. owner: 'root'
  132. group: 'root'
  133. mode: '0644'
  134. when: with_rkhunter|bool
  135. tags:
  136. - 'security'
  137. - name: 'Update chkrootkit configuration'
  138. template: src=chkrootkit/chkrootkit.conf.j2 dest=/etc/chkrootkit.conf owner=root group=root mode=0644
  139. when: with_chkrootkit|bool
  140. tags:
  141. - 'security'
  142. - name: 'Update fstab to hide pids from /proc'
  143. lineinfile:
  144. dest: '/etc/fstab'
  145. regexp: '(^proc\s+/proc\s+proc\s+)(\S+)(\s+[0-9]\s+[0-9])\s*$'
  146. line: '\1defaults,hidepid=2\3'
  147. backrefs: 'yes'
  148. notify:
  149. - 'Remount /proc'
  150. when: with_hideproc|bool and hideproc_gid|length == 0
  151. tags:
  152. - 'security'
  153. - name: 'Update fstab to hide pids from /proc with group id (gid)'
  154. lineinfile:
  155. dest: '/etc/fstab'
  156. regexp: '(^proc\s+/proc\s+proc\s+)(\S+)(\s+[0-9]\s+[0-9])\s*$'
  157. line: '\1defaults,hidepid=2,gid={{ hideproc_gid }}\3'
  158. backrefs: 'yes'
  159. notify:
  160. - 'Remount /proc'
  161. when: with_hideproc|bool and hideproc_gid|length > 0
  162. tags:
  163. - 'security'
  164. - name: 'Create Diffie-Helman parameters'
  165. command: 'openssl dhparam -2 -out /etc/ssl/private/dh{{ item }}.pem {{ item }}'
  166. args:
  167. creates: '/etc/ssl/private/dh{{ item }}.pem'
  168. with_items:
  169. - '2048'
  170. tags:
  171. - 'security'
  172. # vim: ft=yaml.ansible