geo.pp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # define: nginx::resource::geo
  2. #
  3. # This definition creates a new geo mapping entry for NGINX
  4. #
  5. # Parameters:
  6. # [*networks*] - Hash of geo lookup keys and resultant values
  7. # [*default*] - Sets the resulting value if the source value fails to
  8. # match any of the variants.
  9. # [*ensure*] - Enables or disables the specified location
  10. # [*ranges*] - Indicates that lookup keys (network addresses) are
  11. # specified as ranges.
  12. # [*address*] - Nginx defaults to using $remote_addr for testing.
  13. # This allows you to override that with another variable
  14. # name (automatically prefixed with $)
  15. # [*delete*] - deletes the specified network (see: geo module docs)
  16. # [*proxy_recursive*] - Changes the behavior of address acquisition when
  17. # specifying trusted proxies via 'proxies' directive
  18. # [*proxies*] - Hash of network->value mappings.
  19. # Actions:
  20. #
  21. # Requires:
  22. #
  23. # Sample Usage:
  24. #
  25. # nginx::resource::geo { 'client_network':
  26. # ensure => present,
  27. # ranges => false,
  28. # default => extra,
  29. # proxy_recursive => false,
  30. # proxies => [ '192.168.99.99' ],
  31. # networks => {
  32. # '10.0.0.0/8' => 'intra',
  33. # '172.16.0.0/12' => 'intra',
  34. # '192.168.0.0/16' => 'intra',
  35. # }
  36. # }
  37. #
  38. # Sample Hiera usage:
  39. #
  40. # nginx::geo_mappings:
  41. # client_network:
  42. # ensure: present
  43. # ranges: false
  44. # default: 'extra'
  45. # proxy_recursive: false
  46. # proxies:
  47. # - 192.168.99.99
  48. # networks:
  49. # '10.0.0.0/8': 'intra'
  50. # '172.16.0.0/12': 'intra'
  51. # '192.168.0.0/16': 'intra'
  52. define nginx::resource::geo (
  53. $networks,
  54. $default = undef,
  55. $ensure = 'present',
  56. $ranges = false,
  57. $address = undef,
  58. $delete = undef,
  59. $proxies = undef,
  60. $proxy_recursive = undef
  61. ) {
  62. validate_hash($networks)
  63. validate_bool($ranges)
  64. validate_re($ensure, '^(present|absent)$',
  65. "Invalid ensure value '${ensure}'. Expected 'present' or 'absent'")
  66. if ($default != undef) { validate_string($default) }
  67. if ($address != undef) { validate_string($address) }
  68. if ($delete != undef) { validate_string($delete) }
  69. if ($proxies != undef) { validate_array($proxies) }
  70. if ($proxy_recursive != undef) { validate_bool($proxy_recursive) }
  71. $root_group = $::nginx::config::root_group
  72. $ensure_real = $ensure ? {
  73. 'absent' => 'absent',
  74. default => 'file',
  75. }
  76. File {
  77. owner => 'root',
  78. group => $root_group,
  79. mode => '0644',
  80. }
  81. file { "${::nginx::config::conf_dir}/conf.d/${name}-geo.conf":
  82. ensure => $ensure_real,
  83. content => template('nginx/conf.d/geo.erb'),
  84. notify => Class['::nginx::service'],
  85. }
  86. }