Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install fail2ban using ansible?

I want to use install fail2ban across a range of servers using ansible, ansible is already installed and set up (someone else done this) but my main problem is trying to understand how to create a playbook (which if I'm correct will install fail2ban across the range of servers).

Oh I am also using the jail.conf file from a previous machine which I installed fail2ban on manually as I want the configuration (such as time to ban people, who's on the whitelist etc) to be the same across all the servers!

This is my first ever post so if I've forgotten anything please be gentle!

like image 787
tobyapp Avatar asked Oct 27 '25 05:10

tobyapp


1 Answers

I'm assuming Ubuntu/Debian here but you can alter this for other OSes.

$ cat roles/fail2ban/tasks/main.yml
- name: install fail2ban package
  apt: pkg=fail2ban state=present
  when: ansible_distribution=='Debian' or ansible_distribution=='Ubuntu'
  sudo: yes
- name: copy fail2ban local config
  file: src=jail.local dest=/etc/fail2ban/jail.local owner=root group=root mode=0644
  sudo: yes

$ cat roles/fail2ban/files/jail.local
# put your config here
like image 158
tedder42 Avatar answered Oct 30 '25 15:10

tedder42



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!