main.yml 906 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. ---
  2. - name: Update apt cache
  3. apt:
  4. update_cache: yes
  5. cache_valid_time: 3600
  6. when: ansible_os_family == "Debian"
  7. - name: Install required system packages
  8. apt:
  9. name: "{{ item }}"
  10. state: present
  11. loop:
  12. - apt-transport-https
  13. - ca-certificates
  14. - curl
  15. - software-properties-common
  16. - python3-pip
  17. - git
  18. - fail2ban
  19. - ufw
  20. - acl
  21. - name: Configure timezone
  22. timezone:
  23. name: "{{ timezone }}"
  24. - name: Configure fail2ban
  25. template:
  26. src: jail.local.j2
  27. dest: /etc/fail2ban/jail.local
  28. notify: restart fail2ban
  29. - name: Configure UFW
  30. ufw:
  31. rule: "{{ item.rule }}"
  32. port: "{{ item.port }}"
  33. proto: "{{ item.proto }}"
  34. loop:
  35. - { rule: 'allow', port: '22', proto: 'tcp' }
  36. - { rule: 'allow', port: '80', proto: 'tcp' }
  37. - { rule: 'allow', port: '443', proto: 'tcp' }
  38. - name: Enable UFW
  39. ufw:
  40. state: enabled
  41. policy: deny