From 5aa84d6115949efe70135fd2a8d91b3902733402 Mon Sep 17 00:00:00 2001 From: fossilfranv Date: Wed, 5 Jan 2022 21:28:22 +0100 Subject: [PATCH] first commit --- playbook.yml | 122 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 playbook.yml diff --git a/playbook.yml b/playbook.yml new file mode 100644 index 0000000..d3ab1cb --- /dev/null +++ b/playbook.yml @@ -0,0 +1,122 @@ +################################################# +# DO Community Playbooks: Initial Server Setup +################################################# +--- +- hosts: all + become: true + vars_files: + - vars/default.yml + + tasks: +# - name: Install Prerequisites +# apt: name=aptitude update_cache=yes state=latest force_apt_get=yes + + #Sudo Group Setup + - name: Make sure we have a 'wheel' group + group: + name: "{{ create_user }}" + state: present + +# - name: Allow 'wheel' group to have passwordless sudo +# lineinfile: +# path: /etc/sudoers +# state: present +# regexp: '^%wheel' +# line: '%wheel ALL=(ALL) NOPASSWD: ALL' +# validate: '/usr/sbin/visudo -cf %s' + +# User + Key Setup + - name: Create a new regular user with sudo privileges + user: + name: "{{ create_user }}" + state: present + groups: "{{ create_user }}" + append: true + create_home: true + shell: /bin/bash + + - name: Set authorized key for remote user + authorized_key: + user: "{{ create_user }}" + state: present + key: "{{ copy_local_key }}" + +# - name: Disable password authentication for root +# lineinfile: +# path: /etc/ssh/sshd_config +# state: present +# regexp: '^#?PermitRootLogin' +# line: 'PermitRootLogin prohibit-password' + +# Install Packages + - name: Update apt + apt: update_cache=yes + +# - name: Install required system packages +# apt: name={{ sys_packages }} state=latest + +# - name: Upgrade installed apt packages +# apt: +# upgrade: dist +# register: upgrade +# retries: 15 +# delay: 5 +# until: upgrade is success + + + - name: Ensure that these software packages are installed + apt: + pkg: + - build-essential +# - fail2ban +# - needrestart +# - pwgen +# - resolvconf +# - unbound + - unzip + state: latest + + - name: Set ssh '{{ ssh_port }}' port number + lineinfile: + dest: /etc/ssh/sshd_config + regexp: 'Port ' + line: 'Port {{ ssh_port }}' + state: present + notify: + - restart sshd + + + - name: Allow ssh port '{{ ssh_port }}'. + ufw: + rule: allow + proto: tcp + port: '{{ ssh_port }}' + state: enabled + + + - name: set timezone + timezone: + name: "{{ tmzone }}" + +# UFW Setup + - name: UFW - Allow SSH connections + ufw: + rule: allow + name: OpenSSH + + - name: UFW - Deny all other incoming traffic by default + ufw: + state: enabled + policy: deny + direction: incoming + + + handlers: + - name: restart sshd + service: + name: sshd + state: restarted + debug: + msg: "Restarting sshd" +# when: reboot_required.stat.exists == false +