geo.pp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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::geos:
  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. include nginx::params
  72. $root_group = $nginx::params::root_group
  73. $ensure_real = $ensure ? {
  74. 'absent' => 'absent',
  75. default => 'file',
  76. }
  77. File {
  78. owner => 'root',
  79. group => $root_group,
  80. mode => '0644',
  81. }
  82. file { "${nginx::config::conf_dir}/conf.d/${name}-geo.conf":
  83. ensure => $ensure_real,
  84. content => template('nginx/conf.d/geo.erb'),
  85. notify => Class['nginx::service'],
  86. }
  87. }