Refs #8025 Rol debian-base. Task install, nrpe, fail2ban fix, refactor handlers

This commit is contained in:
Xavi Lleó 2024-10-10 13:21:32 +02:00
parent d14b123219
commit 33586c7f96
8 changed files with 30 additions and 16 deletions

View File

@ -26,7 +26,6 @@ base_packages:
- bash-completion - bash-completion
- screen - screen
- aptitude - aptitude
- vim
- tree - tree
- btop - btop
- ncdu - ncdu

View File

@ -5,6 +5,9 @@ fail2ban:
bantime: 600 bantime: 600
maxretry: 4 maxretry: 4
ignore: "127.0.0.0/8 {{ dc_net }}" ignore: "127.0.0.0/8 {{ dc_net }}"
fail2ban_base_packages:
- fail2ban
- rsyslog
vn_host: vn_host:
url: http://apt.verdnatura.es/pool/main/v/vn-host url: http://apt.verdnatura.es/pool/main/v/vn-host
package: vn-host_2.0.2_all.deb package: vn-host_2.0.2_all.deb

View File

@ -1,10 +1,7 @@
- name: Install fail2ban packages - name: Install fail2ban and rsyslog packages
apt: apt:
name: fail2ban name: "{{ fail2ban_base_packages }}"
state: present state: present
loop:
- fail2ban
- rsyslog
- name: Configure fail2ban service - name: Configure fail2ban service
template: template:
src: jail.local src: jail.local

View File

@ -1,5 +1,4 @@
- name: Install base packages - name: Install base packages
apt: apt:
name: "{{ item }}" name: "{{ base_packages }}"
state: present state: present
loop: "{{ base_packages }}"

View File

@ -20,3 +20,5 @@
tags: vim tags: vim
- import_tasks: nrpe.yml - import_tasks: nrpe.yml
tags: nrpe tags: nrpe
- import_tasks: fail2ban.yml
tags: fail2ban

View File

@ -1,12 +1,8 @@
- name: Install NRPE packages - name: Install NRPE packages
apt: apt:
name: "{{ item }}" name: "{{ nagios_packages }}"
state: present state: present
install_recommends: no install_recommends: no
loop:
- nagios-nrpe-server
- nagios-plugins-contrib
- monitoring-plugins-basic
- name: Set NRPE generic configuration - name: Set NRPE generic configuration
template: template:
src: nrpe.cfg src: nrpe.cfg

View File

@ -0,0 +1,4 @@
- name: restart sshd
systemd:
name: sshd
state: restarted

View File

@ -1,10 +1,24 @@
- name: Generate a new SSH key pair
openssh_keypair:
path: /etc/ssh/ssh_host_rsa_key
type: rsa
size: 4096
register: new_pair
- name: Configure sshd_config settings
lineinfile:
path: /etc/ssh/sshd_config
regexp: "{{ item.regexp }}"
line: "{{ item.line }}"
loop:
- { regexp: '^#ListenAddress 0.0.0.0', line: 'ListenAddress 0.0.0.0' }
- { regexp: '^#SyslogFacility AUTH', line: 'SyslogFacility AUTH' }
- name: Delete old host SSH keys - name: Delete old host SSH keys
file: file:
path: "{{ item }}" path: "{{ item }}"
state: absent state: absent
with_items: with_items:
- /etc/ssh/ssh_host_ecdsa_key - /etc/ssh/ssh_host_ecdsa_key
- /etc/ssh/ssh_host_ecdsa_key.pub
- /etc/ssh/ssh_host_ed25519_key - /etc/ssh/ssh_host_ed25519_key
- /etc/ssh/ssh_host_rsa_key - /etc/ssh/ssh_host_ed25519_key.pub
- name: Regenerate host SSH keys when: new_pair is succeeded
command: dpkg-reconfigure openssh-server