/udemx-homework

Debian based server with automation

Primary LanguagePython

Ansible Playbook to Configure Debian 11 Server

This playbook automates the configuration of a Debian 11 server.

Some handy links:

Prerequisites

VirtualBox:

Link how to install it.

Vagrant:

$ sudo apt-get install vagrant

Pip package manager:

$ sudo apt-get install python-pip

Ansible:

$ pip install ansible

NOTE: Latest version of Ansible mostly accessible via pip. So You need to install with it!

Docker, if you want to create your own image:

Docker installation.

The project performs the following tasks:

  • Create a VM via Vagrant.
  • Changes the root password
  • Updates and upgrades all apt packages
  • Installs tools:
    1. sudo
    2. Midnight Commander
    3. htop
    4. nginx
    5. iptables
    6. AdoptOpenJDK 8
    7. OpenJDK 11
    8. git
  • Sets the default Java version to 8
  • Changes the SSH port to 2222
  • Enables PEM-based authentication and block password authentication.
  • Installs fail2ban and configures it to ban IPs after 3 failed SSH login attempts
  • Installs mariadb container from docker-hub
  • Installs a simple flask application from docker-hub

Usage

Modify ansible.cfg and inventory.ini files for your setup!

Run the following command inside the same directory as the Vagrantfile:

$ vagrant up

Then run the playbook from the same folder as the sites.yml:

$ ansible-playbook sites.yml

IMPORTANT NOTE: Once you run the playbooks you have to forward guest's port 2222 to host's port 2222, because the playbook modify the default ssh port!!!

Scripts for the given tasks:

1. Creating MySQL Dump.

Set to run daily at 2 am using the cron job scheduling utility.

$ crontab -e

Then add this line to the file 0 2 * * * ~/mysql_dump.sh

2. Lists the three most recently modified files in the /var/log directory.

3. Lists all the files that have been modified in the last five days in the /var/log/* directories.

4. Reads the 15-minute load average from the /proc/loadavg file.

5. Replaces a string.

:wq :) :) :)