streamhost.pp 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. # define: nginx::resource::streamhost
  2. #
  3. # This definition creates a virtual host
  4. #
  5. # Parameters:
  6. # [*ensure*] - Enables or disables the specified streamhost
  7. # (present|absent)
  8. # [*listen_ip*] - Default IP Address for NGINX to listen with this
  9. # streamhost on. Defaults to all interfaces (*)
  10. # [*listen_port*] - Default IP Port for NGINX to listen with this
  11. # streamhost on. Defaults to TCP 80
  12. # [*listen_options*] - Extra options for listen directive like
  13. # 'default' to catchall. Undef by default.
  14. # [*location_allow*] - Array: Locations to allow connections from.
  15. # [*location_deny*] - Array: Locations to deny connections from.
  16. # [*ipv6_enable*] - BOOL value to enable/disable IPv6 support
  17. # (false|true). Module will check to see if IPv6 support exists on your
  18. # system before enabling.
  19. # [*ipv6_listen_ip*] - Default IPv6 Address for NGINX to listen with
  20. # this streamhost on. Defaults to all interfaces (::)
  21. # [*ipv6_listen_port*] - Default IPv6 Port for NGINX to listen with this
  22. # streamhost on. Defaults to TCP 80
  23. # [*ipv6_listen_options*] - Extra options for listen directive like 'default'
  24. # to catchall. Template will allways add ipv6only=on. While issue
  25. # jfryman/puppet-nginx#30 is discussed, default value is 'default'.
  26. # [*add_header*] - Hash: Adds headers to the HTTP response when
  27. # response code is equal to 200, 204, 301, 302 or 304.
  28. # [*index_files*] - Default index files for NGINX to read when
  29. # traversing a directory
  30. # [*autoindex*] - Set it on 'on' or 'off 'to activate/deactivate
  31. # autoindex directory listing. Undef by default.
  32. # [*proxy*] - Proxy server(s) for the root location to connect
  33. # to. Accepts a single value, can be used in conjunction with
  34. # nginx::resource::upstream
  35. # [*proxy_read_timeout*] - Override the default the proxy read timeout value
  36. # of 90 seconds
  37. # [*proxy_redirect*] - Override the default proxy_redirect value of off.
  38. # [*resolver*] - Array: Configures name servers used to resolve
  39. # names of upstream servers into addresses.
  40. # [*server_name*] - List of streamhost names for which this streamhost will
  41. # respond. Default [$name].
  42. # [*raw_prepend*] - A single string, or an array of strings to
  43. # prepend to the server directive (after cfg prepend directives). NOTE:
  44. # YOU are responsible for a semicolon on each line that requires one.
  45. # [*raw_append*] - A single string, or an array of strings to
  46. # append to the server directive (after cfg append directives). NOTE:
  47. # YOU are responsible for a semicolon on each line that requires one.
  48. # [*owner*] - Defines owner of the .conf file
  49. # [*group*] - Defines group of the .conf file
  50. # [*mode*] - Defines mode of the .conf file
  51. # Default to return 503
  52. # Actions:
  53. #
  54. # Requires:
  55. #
  56. # Sample Usage:
  57. # nginx::resource::streamhost { 'test2.local':
  58. # ensure => present,
  59. # }
  60. define nginx::resource::streamhost (
  61. $ensure = 'present',
  62. $listen_ip = '*',
  63. $listen_port = '80',
  64. $listen_options = undef,
  65. $ipv6_enable = false,
  66. $ipv6_listen_ip = '::',
  67. $ipv6_listen_port = '80',
  68. $ipv6_listen_options = 'default ipv6only=on',
  69. $proxy = undef,
  70. $proxy_read_timeout = $::nginx::config::proxy_read_timeout,
  71. $proxy_connect_timeout = $::nginx::config::proxy_connect_timeout,
  72. $resolver = [],
  73. $server_name = [$name],
  74. $raw_prepend = undef,
  75. $raw_append = undef,
  76. $owner = $::nginx::config::global_owner,
  77. $group = $::nginx::config::global_group,
  78. $mode = $::nginx::config::global_mode,
  79. ) {
  80. validate_re($ensure, '^(present|absent)$',
  81. "${ensure} is not supported for ensure. Allowed values are 'present' and 'absent'.")
  82. if !(is_array($listen_ip) or is_string($listen_ip)) {
  83. fail('$listen_ip must be a string or array.')
  84. }
  85. if !is_integer($listen_port) {
  86. fail('$listen_port must be an integer.')
  87. }
  88. if ($listen_options != undef) {
  89. validate_string($listen_options)
  90. }
  91. validate_bool($ipv6_enable)
  92. if !(is_array($ipv6_listen_ip) or is_string($ipv6_listen_ip)) {
  93. fail('$ipv6_listen_ip must be a string or array.')
  94. }
  95. if !is_integer($ipv6_listen_port) {
  96. fail('$ipv6_listen_port must be an integer.')
  97. }
  98. validate_string($ipv6_listen_options)
  99. validate_string($proxy_read_timeout)
  100. validate_array($resolver)
  101. validate_array($server_name)
  102. validate_string($owner)
  103. validate_string($group)
  104. validate_re($mode, '^\d{4}$',
  105. "${mode} is not valid. It should be 4 digits (0644 by default).")
  106. # Variables
  107. $streamhost_dir = "${::nginx::config::conf_dir}/streams-available"
  108. $streamhost_enable_dir = "${::nginx::config::conf_dir}/streams-enabled"
  109. $streamhost_symlink_ensure = $ensure ? {
  110. 'absent' => absent,
  111. default => 'link',
  112. }
  113. $name_sanitized = regsubst($name, ' ', '_', 'G')
  114. $config_file = "${streamhost_dir}/${name_sanitized}.conf"
  115. File {
  116. ensure => $ensure ? {
  117. 'absent' => absent,
  118. default => 'file',
  119. },
  120. notify => Class['::nginx::service'],
  121. owner => $owner,
  122. group => $group,
  123. mode => $mode,
  124. }
  125. # Add IPv6 Logic Check - Nginx service will not start if ipv6 is enabled
  126. # and support does not exist for it in the kernel.
  127. if ($ipv6_enable == true) and (!$::ipaddress6) {
  128. warning('nginx: IPv6 support is not enabled or configured properly')
  129. }
  130. concat { $config_file:
  131. owner => $owner,
  132. group => $group,
  133. mode => $mode,
  134. notify => Class['::nginx::service'],
  135. }
  136. concat::fragment { "${name_sanitized}-header":
  137. target => $config_file,
  138. content => template('nginx/streamhost/streamhost.erb'),
  139. order => '001',
  140. }
  141. file{ "${name_sanitized}.conf symlink":
  142. ensure => $streamhost_symlink_ensure,
  143. path => "${streamhost_enable_dir}/${name_sanitized}.conf",
  144. target => $config_file,
  145. require => Concat[$config_file],
  146. notify => Class['::nginx::service'],
  147. }
  148. }