An Ansible Playbook to initialize Debian and Ubuntu systems.
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.

94 lines
2.0KB

  1. ---
  2. - hosts: personal
  3. user: root
  4. tasks:
  5. - include_vars: vars/all.yml
  6. - name: Install essential and optional packages
  7. apt:
  8. name: "{{ item }}"
  9. state: present
  10. update_cache: yes
  11. with_items:
  12. - vim
  13. - byobu
  14. - screen
  15. - curl
  16. - unzip
  17. - ufw
  18. - htop
  19. - multitail
  20. - chrony
  21. - ca-certificates
  22. - unattended-upgrades
  23. - downtimed
  24. - name: Copy the templates over
  25. template:
  26. src: "{{ item.source }}"
  27. dest: "{{ item.destination }}"
  28. with_items:
  29. - { source: templates/vimrc.j2, destination: /etc/vim/vimrc }
  30. - { source: templates/vimrc.local.j2, destination: /root/.vimrc }
  31. - { source: templates/selected_editor.j2, destination: /root/.selected_editor }
  32. - { source: templates/bashrc.j2, destination: /root/.bashrc }
  33. - { source: templates/bashrc.j2, destination: /etc/skel/.bashrc }
  34. - name: Set vim as the default editor
  35. alternatives:
  36. name: editor
  37. path: /usr/bin/vim.basic
  38. - name: Set timezone
  39. timezone:
  40. name: "{{ timezone }}"
  41. - name: Generate locales
  42. locale_gen:
  43. name: en_US.UTF-8
  44. state: present
  45. with_items:
  46. - en_US.UTF-8
  47. - el_CY.UTF-8
  48. - name: Customize SSH
  49. lineinfile:
  50. path: /etc/ssh/sshd_config
  51. regexp: "{{ item.regexp }}"
  52. line: "{{ item.line }}"
  53. with_items:
  54. - { regexp: "^#?Port 22", line: "Port 22" }
  55. - { regexp: "^#?PermitRootLogin", line: "PermitRootLogin prohibit-password" }
  56. - { regexp: "^#?PasswordAuthentication", line: "PasswordAuthentication yes" }
  57. notify:
  58. - Restart SSH
  59. - name: Configure UFW
  60. ufw:
  61. rule: allow
  62. proto: tcp
  63. direction: in
  64. to_port: "{{ item }}"
  65. dest: any
  66. src: any
  67. with_items:
  68. - 22
  69. - 80
  70. - 443
  71. - "{{ custom_ssh_port }}"
  72. notify:
  73. - Enable UFW
  74. handlers:
  75. - name: Restart SSH
  76. service:
  77. name: ssh
  78. state: restarted
  79. - name: Enable UFW
  80. ufw:
  81. state: enabled