chef-cookbooks / iptables

Development repository for Chef Cookbook iptables
https://supermarket.chef.io/cookbooks/iptables
Apache License 2.0
102 stars 141 forks source link

Template with multiple instructions #34

Closed Dreeg closed 8 years ago

Dreeg commented 9 years ago

Hi all,

I have to configure about 14 instructions of iptables. If I generate a single template and use iptables_rule, generate correctly file in /etc/sysconfig/iptables but all rules doesn't applied. While, if I write a single template file for every instruction, all work fine.

For ports management I can't create a single template file for every port. It wouldn't be an efficent configuration. How can I write a single (or few) template file(s)?

ivanovteo commented 9 years ago

To dynamically generate the rules, variables can be passed:

iptables_rule 'http' do
  action :enable
  variables ({:http_ports => ['8888','9999']})
end

with the following template:

<% @http_ports.each do |port| %>
-A INPUT -p tcp -m tcp --dport <%= port %> -j ACCEPT
<% end %>
lamont-granquist commented 8 years ago

closing via #51