如何使用ansible安装fail2ban?

tob*_*app 2 ansible fail2ban

我想在一系列使用 ansible 的服务器上使用 install fail2ban,ansible 已经安装并设置(其他人这样做了)但我的主要问题是试图了解如何创建一个剧本(如果我是正确的,将安装fail2ban跨服务器范围)。

哦,我还使用了之前机器上的 jail.conf 文件,我手动安装了 fail2ban,因为我希望配置(例如禁止人员的时间,白名单上的人员等)在所有服务器上都相同!

这是我第一次发帖,所以如果我忘记了什么,请保持温柔!

ted*_*r42 5

我在这里假设是 Ubuntu/Debian,但您可以为其他操作系统更改此设置。

$ 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
Run Code Online (Sandbox Code Playgroud)