Guest User

Untitled

a guest
Jul 16th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. define iptables::rule($ports, $protocol="tcp", $ensure="permit", $roles=undef,
  2. $sources=undef) {
  3. include iptables
  4.  
  5. # Validate $ensure
  6. case $ensure {
  7. "permit": { $target = "ACCEPT" }
  8. "reject": { $target = "REJECT" }
  9. "drop": { $target = "DROP" }
  10. default: { fail("Invalid value ensure => '$ensure' for Iptables::Rule[$name]. Must be permit, reject, or drop") }
  11. }
  12.  
  13. # Validate $protocol
  14. case $protocol {
  15. "tcp", "icmp", "udp": { }
  16. default: { fail("Invalid value protocol => '$protocol' for Iptables::Rule[$name]. Must be tcp, icmp, or udp") }
  17. }
  18.  
  19. # If no roles or sources are specified, default to 'any'
  20. if $roles == undef and $sources == undef {
  21. $any_source = true
  22. } else {
  23. $any_source = false
  24. }
  25.  
  26. file {
  27. "/etc/iptables.d/iptables.$name":
  28. ensure => file,
  29. content => template("iptables/rule.erb");
  30. }
  31. }
Add Comment
Please, Sign In to add comment