Guest User

Untitled

a guest
Jan 29th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.52 KB | None | 0 0
  1. ---
  2. - hosts: all
  3.  
  4. vars:
  5. UBUNTU_COMMON_ROOT_PASSWORD: 'xxxxx'
  6. UBUNTU_COMMON_DEPLOY_PASSWORD: 'xxxxx'
  7. UBUNTU_COMMON_LOGWATCH_EMAIL: user@example.com
  8. ubuntu_common_deploy_user_name: deploy
  9. ubuntu_common_deploy_public_keys:
  10. - ~/.ssh/id_rsa.pub
  11.  
  12. ubuntu_common_required_packages:
  13. - ufw
  14. - fail2ban
  15. - unattended-upgrades
  16. - logwatch
  17.  
  18. ubuntu_common_optional_packages:
  19. - mosh
  20. - vim
  21.  
  22. ubuntu_common_ssh_port: 22
  23. ubuntu_common_mosh_from_port: 60000
  24. ubuntu_common_mosh_to_port: 60010
  25.  
  26. tasks:
  27. - name: Change root password
  28. user: name=root password="{{ UBUNTU_COMMON_ROOT_PASSWORD }}"
  29.  
  30. - name: Add deploy user
  31. user: name={{ ubuntu_common_deploy_user_name }} password="{{ UBUNTU_COMMON_DEPLOY_PASSWORD }}" shell=/bin/bash
  32.  
  33. - name: Add authorized keys for deploy user
  34. authorized_key: user={{ ubuntu_common_deploy_user_name }} key="{{ lookup('file', item) }}"
  35. with_items: ubuntu_common_deploy_public_keys
  36.  
  37. - name: Add deploy user to sudoers
  38. lineinfile: dest=/etc/sudoers
  39. regexp="{{ ubuntu_common_deploy_user_name }} ALL"
  40. line="{{ ubuntu_common_deploy_user_name }} ALL=(ALL) ALL"
  41. state=present
  42.  
  43. - name: Update APT package cache
  44. apt: update_cache=yes cache_valid_time=3600
  45.  
  46. - name: Upgrade APT to the latest packages
  47. apt: upgrade=safe
  48.  
  49. - name: Install required packages
  50. apt: state=installed pkg={{ item }}
  51. with_items: ubuntu_common_required_packages
  52.  
  53. - name: Install optional packages
  54. apt: state=installed pkg={{ item }}
  55. with_items: ubuntu_common_optional_packages
  56.  
  57. - name: Adjust APT update intervals
  58. copy: src=apt_periodic dest=/etc/apt/apt.conf.d/10periodic
  59.  
  60. - name: Setup ufw
  61. ufw: state=enabled policy=deny
  62.  
  63. - name: Allow ssh traffic
  64. ufw: rule=allow port={{ ubuntu_common_ssh_port }} proto=tcp
  65.  
  66. - name: Allow mosh traffic
  67. ufw: rule=allow proto=udp port={{ ubuntu_common_mosh_from_port }}:{{ ubuntu_common_mosh_to_port }}
  68. when: "'mosh' in ubuntu_common_optional_packages"
  69.  
  70. - name: Set up Postfix to relay mail
  71. debconf: name=postfix
  72. question='{{ item.question }}'
  73. value='{{ item.value }}'
  74. vtype='{{ item.vtype }}'
  75. with_items:
  76. - { question: 'postfix/mailname', value: '{{ ansible_fqdn }}', vtype: 'string' }
  77. - { question: 'postfix/main_mailer_type', value: 'Internet Site', vtype: 'string' }
  78.  
  79. - name: Email log summary daily
  80. lineinfile: dest=/etc/cron.daily/00logwatch
  81. regexp="^/usr/sbin/logwatch"
  82. line="/usr/sbin/logwatch --output mail --mailto {{ UBUNTU_COMMON_LOGWATCH_EMAIL }} --detail high"
  83. state=present create=yes
  84.  
  85. - name: Change ssh port
  86. lineinfile: dest=/etc/ssh/sshd_config
  87. regexp="^Port\s"
  88. line="Port {{ ubuntu_common_ssh_port }}"
  89. state=present
  90. notify: Restart ssh
  91.  
  92. - name: Disallow password authentication
  93. lineinfile: dest=/etc/ssh/sshd_config
  94. regexp="^PasswordAuthentication"
  95. line="PasswordAuthentication no"
  96. state=present
  97. notify: Restart ssh
  98.  
  99. - name: Disallow root SSH access
  100. lineinfile: dest=/etc/ssh/sshd_config
  101. regexp="^PermitRootLogin"
  102. line="PermitRootLogin no"
  103. state=present
  104. notify: Restart ssh
  105.  
  106. handlers:
  107. - name: Restart ssh
  108. service: name=ssh state=restarted
Add Comment
Please, Sign In to add comment