Added common ansible role

This commit is contained in:
2020-01-03 15:02:16 +01:00
parent 5f34ead86e
commit d8176ea43c
10 changed files with 113 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
---
sshport: 22
openports_list:
- 22
#blacklist_ip_list:
+4
View File
@@ -0,0 +1,4 @@
---
- name: update the package list
apt: update_cache=yes
+19
View File
@@ -0,0 +1,19 @@
---
- name: ensure apticron packages are installed
apt:
pkg: "{{ packages }}"
state: latest
update_cache: yes
cache_valid_time: 600
vars:
packages:
- apticron
- name: configure apticron
template:
src: etc/apticron/apticron.conf.j2
dest: /etc/apticron/apticron.conf
owner: root
group: root
mode: 0644
+9
View File
@@ -0,0 +1,9 @@
---
- name: set up check disk space cron script
template:
src: etc/cron.hourly/check-disk-space.sh.j2
dest: /etc/cron.hourly/check-disk-space.sh
owner: root
group: root
mode: 0750
+11
View File
@@ -0,0 +1,11 @@
---
- name: install fail2ban
apt:
name: fail2ban
state: latest
update_cache: yes
- name: enable fail2ban
service:
name: fail2ban
enabled: yes
started: started
+17
View File
@@ -0,0 +1,17 @@
---
- include: apt.yml
tags:
- apt
- include: apticron.yml
tags:
- apticron
- include: disk-check.yml
tags:
- disk
- include: ufw.yml
tags:
- firewall
- include: fail2ban.yml
tags:
- firewall
- include: tools.yml
+19
View File
@@ -0,0 +1,19 @@
---
- name: ensure all tools packages are installed
apt:
pkg: "{{ packages }}"
state: latest
update_cache: yes
cache_valid_time: 600
vars:
packages:
- curl
- debsums
- iperf3
- mosh
- net-tools
- needrestart
- sqlite3
- sudo
- tmux
+8
View File
@@ -0,0 +1,8 @@
---
- name: allow ssh through firewall
ufw:
name: OpenSSH
rule: allow
- name: enable ufw firewall
command:
cmd: ufw enable
@@ -0,0 +1,6 @@
# apticron.conf
#
# Set EMAIL to a space separated list of addresses which will be notified of
# impending updates. By default the root account will be notified.
EMAIL="root@{{ ansible_domain }}"
@@ -0,0 +1,15 @@
#!/bin/sh
# Check disk space
CURRENT=$(df / --output=pcent | tail --lines=1 | cut --delimiter='%' --field=1)
THRESHOLD=90
ADMIN="root@{{ ansible_domain }}"
SUBJECT="[Disk Space Alert] The free space on {{ ansible_fqdn }} is critically low"
MESSAGE=
if [ "$CURRENT" -gt "$THRESHOLD" ]; then
mail -s "$SUBJECT" "$ADMIN" << EOF
Your root partition remaining free space is critically low. Used: $CURRENT%
EOF
fi