“Preparing a new server with the minimum secure configuration before deploying applications on it.”
This playbook sets up a secure Ubuntu server with a new User, SSH key-based authentication, sudo Privileges, Essential packages, and a Firewall.
- Creating a non-root user
- Adding SSH keys for login
- Giving the user sudo privileges
- Installing basic tools (git, curl, vim, ufw, etc.)
- Securing SSH (disable root password login)
- Enabling a firewall`
- Ansible installed on your control machine
- Target server(s) accessible via SSH
- Your SSH key available at: ~/.ssh/id_rsa.pub
project/
│── playbook.yml # Main Ansible playbook
│── vars/
│ └── default.yml # Variables file
│── inventory # (Optional) Ansible inventory
│── README.md # Documentation
-
Obtain the playbook
git clone https://github.com/xrootms/Ansible-Playbook-Initial-Server-Setup.git
-
Customize options
- Edit
vars/default.ymlto update the username or system packages as needed.
- Edit
-
Update your inventory
- Add your server details to the
inventoryfile.
- Add your server details to the
-
Run the playbook
ansible-playbook -l [target] -i [inventory_file] -u [remote_user] playbook.yml
- Login as the new user:
ssh user@your_server_ip - Confirm sudo works without a password:
sudo ls /root - Check UFW firewall rules:
sudo ufw status
✅ Now your server is ready, secure, and manageable with Ansible.