upstream.pp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # define: nginx::resource::upstream
  2. #
  3. # This definition creates a new upstream proxy entry for NGINX
  4. #
  5. # Parameters:
  6. # [*members*] - Array of member URIs for NGINX to connect to. Must follow valid NGINX syntax.
  7. # [*ensure*] - Enables or disables the specified location (present|absent)
  8. # [*upstream_cfg_prepend*] - It expects a hash with custom directives to put before anything else inside upstream
  9. #
  10. # Actions:
  11. #
  12. # Requires:
  13. #
  14. # Sample Usage:
  15. # nginx::resource::upstream { 'proxypass':
  16. # ensure => present,
  17. # members => [
  18. # 'localhost:3000',
  19. # 'localhost:3001',
  20. # 'localhost:3002',
  21. # ],
  22. # }
  23. #
  24. # Custom config example to use ip_hash, and 20 keepalive connections
  25. # create a hash with any extra custom config you want.
  26. # $my_config = {
  27. # 'ip_hash' => '',
  28. # 'keepalive' => '20',
  29. # }
  30. # nginx::resource::upstream { 'proxypass':
  31. # ensure => present,
  32. # members => [
  33. # 'localhost:3000',
  34. # 'localhost:3001',
  35. # 'localhost:3002',
  36. # ],
  37. # upstream_cfg_prepend => $my_config,
  38. # }
  39. define nginx::resource::upstream (
  40. $members,
  41. $ensure = 'present',
  42. $upstream_cfg_prepend = undef,
  43. ) {
  44. File {
  45. owner => 'root',
  46. group => 'root',
  47. mode => '0644',
  48. }
  49. file { "/etc/nginx/conf.d/${name}-upstream.conf":
  50. ensure => $ensure ? {
  51. 'absent' => absent,
  52. default => 'file',
  53. },
  54. content => template('nginx/conf.d/upstream.erb'),
  55. notify => Class['nginx::service'],
  56. }
  57. }