streamhost.pp 6.0 KB

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