Skip to content

Instantly share code, notes, and snippets.

@wtnb75
Created February 3, 2014 15:51
Show Gist options
  • Save wtnb75/8786429 to your computer and use it in GitHub Desktop.
Save wtnb75/8786429 to your computer and use it in GitHub Desktop.
Chef definitions/iptables.rb
define :iptables_open_tcp, :port => -1 do
if params[:port]>0 then
bash "iptables-#{params[:port]}" do
code <<-EOH
sed -i.bak -e '/--dport 22/a\-A INPUT -m state --state NEW -m tcp -p tcp --dport #{params[:port]} -j ACCEPT' /etc/sysconfig/iptables
EOH
not_if "grep -q -- \"--dport #{params[:port]} \" /etc/sysconfig/iptables"
end
service "iptables-restart-#{params[:port]}" do
service_name "iptables"
action :restart
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment