4

Ansible 如何修改 iptables 规则

 1 year ago
source link: https://www.lfhacks.com/tech/ansible-iptables/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Ansible 如何修改 iptables 规则

2022-05-31
阅读 1 分钟
748.jpg
扫一扫,转发文章 ansible-iptables.png

Ansible 如何修改 iptables?

假如我们想为一台主机添加 http 服务,那么需要增加一条 iptables 的规则,允许接收 tcp_80 的请求。

最直接的方法当然是使用 ansible.builtin.shell ,然后执行 iptables 命令

$ sudo iptables -I INPUT -p tcp --dport 80 -j ACCEPT

其实,ansible 提供了 ansible.builtin.iptables 模块用于修改 iptables

---- name: allow http service become: yes ansible.builtin.iptables: chain: INPUT protocol: tcp destination_port: "80" jump: ACCEPT state: present action: insert...

这个方法实现的效果跟方法一中的一样,不仅可读性好,而且多了一层 ansible 的保障。

注意 destination_port 的值加了双引号,因为必须明确的传递字符串,而不是数字类型。

为了保证阅读体验,本站不安放广告。但是,租用服务器和编写文章需要资金和时间的投入。

如果您觉得文章对您有用,请考虑捐助小站(金额不限),以期待更多原创文章。

wechatpay.pngalipay.png
cc-by-nc.gif

若无特别说明,本站文章均为原创,并采用 署名协议 CC-BY-NC 授权。
欢迎转载,惟请保留原文链接,且不得用于商业用途。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK