![Ansible UFW 允许传出,拒绝传入](https://linux22.com/image/1668623/Ansible%20UFW%20%E5%85%81%E8%AE%B8%E4%BC%A0%E5%87%BA%EF%BC%8C%E6%8B%92%E7%BB%9D%E4%BC%A0%E5%85%A5.png)
尝试通过 Ansible 推出 UFW。
- name: Install UFW Firwall
hosts: all
tasks:
- name: UFW enabled
community.general.ufw:
state: "enabled"
policy: "deny"
我希望传出规则允许一切,传入规则拒绝一切。我只是不知道该如何实现,有人能帮我吗?
答案1
好吧,这真的很简单。只需添加一个direction: outgoing
。所以完整的代码如下:
- name: Install UFW Firewall
hosts: all
tasks:
- name: Outgoing allow
community.general.ufw:
state: enabled
direction: outgoing
policy: allow
- name: Incoming deny
community.general.ufw:
state: enabled
direction: incoming
policy: deny