有没有办法在ansible上使用ufw来指定涉及两个网络接口的微调规则以及通过它们的流量方向?
等效的命令是:
ufw route allow in on wg0 out on eth0
ufw route allow in on eth0 out on wg0从这里的文档https://docs.ansible.com/ansible/latest/collections/community/general/ufw_module.html中,我可以看到有人只能指定一次网络接口,请参见他们的示例:
- name: Allow incoming access to eth0 from 1.2.3.5 port 5469 to 1.2.3.4 port 5469
community.general.ufw:
rule: allow
interface: eth0
direction: in
proto: udp
src: 1.2.3.5
from_port: '5469'
dest: 1.2.3.4
to_port: '5469'请参阅这些参数interface和direction。dest字段在示例中与IP地址一起使用,但在ufw的字段列表中不可用,或者看起来不像有人可以将其与网络接口一起使用。
我设法使用shell解决了上面的问题
- name: Route traffic using network interfaces
shell: |
ufw route allow in on wg0 out on eth0
ufw route allow in on eth0 out on wg0
args:
executable: /bin/bash然而,这不是幂等的,因为我看到任务总是在我多次运行剧本时执行。
作为替代解决方案,如果Ansible ufw不允许实现这些复杂的规则,我如何才能使上述任务幂等呢?
发布于 2021-09-17 10:20:42
它现在由选项"interface_in“"interface_out”支持。
https://stackoverflow.com/questions/66998978
复制相似问题