我正在尝试使用puppet master 3.1.1来pipe理各种服务器上的iptables。 我的本地木偶代理是2.7.19 ,服务器OS是CentOS 5.4 。
/etc/puppet/modules/mycompany/manifests/config/iptables.pp
class base::iptables ( { { $identity_environment = $::identity_environment } if ($identity_environment == "production") { $start_iptables = "true" $run_iptables = "running" } elsif ($identity_environment == "development") { $start_iptables = "false" $run_iptables = "stopped" } if ($run_iptables != "stopped") { file { "/etc/sysconfig/iptables": ensure => file, owner => root, group => root, mode => 644, source => "puppet://path_to_my_conf", require => File["/etc/resolv.conf"], } service { "iptables": subscribe => File["/etc/sysconfig/iptables"], enable => "$start_iptables", ensure => "$run_iptables", status => "[[ `iptables -L -n | egrep -v '(Chain|target)' | grep '^[A-Za-z]' | wc -l` != 0 ]]", } } else { service { "iptables": enable =>"$start_iptables", ensure =>"$run_iptables", } } }
当我在开发服务器上运行puppet时:
puppet agent --verbose --no-daemonize --onetime --debug | grep iptable
发生以下情况:
debug:Puppet :: Type :: Service :: ProviderRedhat:执行'/ sbin / chkconfig iptables'debug:Serviceiptables:执行'/ sbin / service iptables stop'debug:Puppet :: Type :: Service :: ProviderRedhat:Executing'/ sbin / chkconfig iptables'通知:/ stage [main] / base :: iptables / service [iptables] /确保:确保已将'running'改为'stopped'debug:/ Stage [main] / Base :: Iptables / Service [iptables ]:容器类[Base :: Iptables]将传播我的刷新事件debug:Serviceip6tables:执行'/ sbin / service ip6tables status'debug:Puppet :: Type :: Service :: ProviderRedhat:执行'/ sbin / chkconfig ip6tables' debug:Class [Base :: Iptables]:容器Stage [main]将传播我的刷新事件
用service iptables status
手动检查显示服务确实在运行,是傀儡停止服务,然后以某种方式启动它,由于“刷新”?
我试图根据这个类似的问题改变我的清单,但无济于事,
service { "iptables": ensure => "stopped", hasstatus => "true", status => "true" }
导致同样的事情 – 傀儡检查,然后停止iptables,但是服务被打开了。
我不知道这是否可以与已经在较新的木偶版本中修复的logging在案的竞争状态错误相关联,我没有select更新或实施适当的方法,例如puppetlab的防火墙模块 。
更新[20140724]
经过一些很好的反馈,我在/etc/init.d/iptables脚本中做了一些debugging/日志logging。 来找出傀儡运行时,没有呼叫启动服务正在做,但操作系统仍然报告iptables运行,即使傀儡停止它。
我的倾向是看看iptables模块本身。 果然,如果我删除了iptables模块,然后再运行木偶,模块将被重新加载。
更新[20140729]
下面列出了我的解决scheme作为答案。 我将打开一个新的问题,继续对此进行故障排除CentOS 6。
我想在这里留下这个作为我的问题的答案,因为它为我工作。 如果你正在运行CentOS 5.4,这将工作,并有效地确保iptables模块从内核卸载。 我会问一个新的问题,特别是与我继续与CentOS 6和puppet合作的问题。
exec { "chkconfig_iptables": onlyif => "/sbin/chkconfig --level 3 iptables", command => "/sbin/chkconfig --level 3 iptables off", before => exec["kill_iptables"] } exec { "kill_iptables": onlyif => "/sbin/lsmod | grep ip_tables", command => "/sbin/service iptables stop;/sbin/modprobe -f -r ip_tables" }