This repository contains an Ansible playbook for automated server provisioning, inspired by @Psycho0verload and Goneuland. It includes roles for setting up common server configurations, Docker, SSH, firewall, Git, and CrowdSec.
Note: This repository is intended to work with Debian 11 & 12 distributions. Using other distributions may result in errors due to the Debian-oriented apt repository.
group_vars/
all.yml
hosts.ini
playbook.yml
roles/
cleanup/
tasks/
main.yml
common/
tasks/
main.yml
crowdsec/
tasks/
main.yml
crowdsec_firewall_bouncer/
tasks/
main.yml
docker/
tasks/
main.yml
firewall/
tasks/
main.yml
git/
tasks/
main.yml
ssh/
tasks/
main.yml
The hosts.ini
file defines the inventory of servers to be managed:
[servers]
yourservername ansible_host=12.345.678.99 ansible_user=root ansible_become=true
The main playbook is defined in playbook.yml
and will execute all role tasks on every server which are defined in the hosts.ini
.
The common role performs basic server setup tasks such as updating packages, setting the timezone, and creating an admin user.
The ssh role configures SSH settings, including changing the SSH port, setting up key authentication, and disabling root password authentication.
The docker role installs Docker, its dependencies, and configures Docker to start on boot.
The firewall role installs and configures UFW with basic rules to secure the server.
The git role installs Git and configures global Git settings.
The crowdsec role sets up CrowdSec for intrusion detection and prevention, including the installation of required packages and configuration files.
The crowdsec_firewall_bouncer role installs and configures the CrowdSec firewall bouncer to work with UFW.
The cleanup role performs final cleanup tasks, such as removing unnecessary packages and enabling UFW.
The group_vars/all.yml
file defines global variables used across roles. Descriptions of each variable are available in the comments within the file.
To use this Ansible playbook, follow these steps:
-
Clone the Repository: Clone this repository to your local machine where Ansible is installed.
-
Configure Inventory: Copy the
hosts.ini.sample
file tohosts.ini
and edit it to include the details of the servers you want to manage. -
DNS Configuration: Ensure that the DNS A-Record for your domain is correctly set up.
-
Set Variables: Copy the
group_vars/all.yml.sample
file togroup_vars/all.yml
and update it with your desired configuration settings. -
Run the Playbook: Execute the playbook from your local machine (not on the remote server) using the following command:
ansible-playbook -i hosts.ini playbook.yml -kK
This will prompt you for the SSH password and the privilege escalation password (if required), and then proceed to configure the servers as specified in the playbook.
This project is licensed under the MIT License.