大网数据广告活动
服务器运维问答

Safe way to deploy iptables using ansible

· 52CE 我爱测

I would like to deploy iptables rules in a "safe" way using ansible where for safe I think at something like the shorewall command safe-restart . So I'm looking for a workflow like this: install the new rules; wait for 30 seconds…

问题原文

原帖链接 · Enrico Polesel · CC BY-SA 4.0

I would like to deploy iptables rules in a "safe" way using ansible where for safe I think at something like the shorewall command safe-restart.

So I'm looking for a workflow like this:

  1. install the new rules;
  2. wait for 30 seconds for a confirmation from the user (or, in our case, from the machine executing the playbook);
  3. if the user confirms then make them permanent, otherwise restore the old rules.

My goal is to avoid losing control of my machines because of a wrong firewall configuration (that may, for example, block SSH).

已采纳解答

原帖链接 · poige · CC BY-SA 4.0

Since ansible is agentless it means it would need to open new connection (or re-use existent if configured properly) to host in order to restore the state.

If on the current step changes to firewall would not allow the next connection to succeed there's no way to recover obviously.

Thus it means you have to put testing-recovery task on the host itself which would try to apply new rules and then wait to see if next step of playbook has been succeeded (typically you need at least SSH accessible, so testing step of playbook could be just killing that script before it restores previous ruleset). It also can do some self-originating testing of course.

Summary: plant a script that would not only apply the rules but also would withdraw them back in case those rules would cause connectivity regression.

Straight-forward approach using iptables-apply:

  1. Run it detached (with screen or tmux or whatever) with new ruleset
  2. Kill it in the following play step before it rolled back firewall to the previous ruleset

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-06-13)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。