mailhost.pp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. # define: nginx::resource::mailhost
  2. #
  3. # This definition creates a virtual host
  4. #
  5. # Parameters:
  6. # [*ensure*] - Enables or disables the specified mailhost (present|absent)
  7. # [*listen_ip*] - Default IP Address for NGINX to listen with this vHost on. Defaults to all interfaces (*)
  8. # [*listen_port*] - Default IP Port for NGINX to listen with this vHost on. Defaults to TCP 80
  9. # [*listen_options*] - Extra options for listen directive like 'default' to catchall. Undef by default.
  10. # [*ipv6_enable*] - BOOL value to enable/disable IPv6 support (false|true). Module will check to see if IPv6
  11. # support exists on your system before enabling.
  12. # [*ipv6_listen_ip*] - Default IPv6 Address for NGINX to listen with this vHost on. Defaults to all interfaces (::)
  13. # [*ipv6_listen_port*] - Default IPv6 Port for NGINX to listen with this vHost on. Defaults to TCP 80
  14. # [*ipv6_listen_options*] - Extra options for listen directive like 'default' to catchall. Template will allways add ipv6only=on.
  15. # While issue jfryman/puppet-nginx#30 is discussed, default value is 'default'.
  16. # [*index_files*] - Default index files for NGINX to read when traversing a directory
  17. # [*ssl*] - Indicates whether to setup SSL bindings for this mailhost.
  18. # [*ssl_cert*] - Pre-generated SSL Certificate file to reference for SSL Support. This is not generated by this module.
  19. # [*ssl_key*] - Pre-generated SSL Key file to reference for SSL Support. This is not generated by this module.
  20. # [*ssl_port*] - Default IP Port for NGINX to listen with this SSL vHost on. Defaults to TCP 443
  21. # [*starttls*] - enable STARTTLS support: (on|off|only)
  22. # [*protocol*] - Mail protocol to use: (imap|pop3|smtp)
  23. # [*auth_http*] - With this directive you can set the URL to the external HTTP-like server for authorization.
  24. # [*xclient*] - wheter to use xclient for smtp (on|off)
  25. # [*server_name*] - List of mailhostnames for which this mailhost will respond. Default [$name].
  26. #
  27. # Actions:
  28. #
  29. # Requires:
  30. #
  31. # Sample Usage:
  32. # nginx::resource::mailhost { 'domain1.example':
  33. # ensure => present,
  34. # auth_http => 'server2.example/cgi-bin/auth',
  35. # protocol => 'smtp',
  36. # listen_port => 587,
  37. # ssl_port => 465,
  38. # starttls => 'only',
  39. # xclient => 'off',
  40. # ssl => 'true',
  41. # ssl_cert => '/tmp/server.crt',
  42. # ssl_key => '/tmp/server.pem',
  43. # }
  44. define nginx::resource::mailhost (
  45. $ensure = 'enable',
  46. $listen_ip = '*',
  47. $listen_port,
  48. $listen_options = undef,
  49. $ipv6_enable = false,
  50. $ipv6_listen_ip = '::',
  51. $ipv6_listen_port = '80',
  52. $ipv6_listen_options = 'default',
  53. $ssl = false,
  54. $ssl_cert = undef,
  55. $ssl_key = undef,
  56. $ssl_port = undef,
  57. $starttls = 'off',
  58. $protocol = undef,
  59. $auth_http = undef,
  60. $xclient = 'on',
  61. $server_name = [$name]) {
  62. File {
  63. owner => 'root',
  64. group => 'root',
  65. mode => '0644',
  66. }
  67. # Add IPv6 Logic Check - Nginx service will not start if ipv6 is enabled
  68. # and support does not exist for it in the kernel.
  69. if ($ipv6_enable and !$::ipaddress6) {
  70. warning('nginx: IPv6 support is not enabled or configured properly')
  71. }
  72. # Check to see if SSL Certificates are properly defined.
  73. if ($ssl or $starttls == 'on' or $starttls == 'only') {
  74. if ($ssl_cert == undef) or ($ssl_key == undef) {
  75. fail('nginx: SSL certificate/key (ssl_cert/ssl_cert) and/or SSL Private must be defined and exist on the target system(s)')
  76. }
  77. }
  78. # Use the File Fragment Pattern to construct the configuration files.
  79. # Create the base configuration file reference.
  80. if ($listen_port != $ssl_port) {
  81. file { "${nginx::config::nx_temp_dir}/nginx.mail.d/${name}-001":
  82. ensure => $ensure ? {
  83. 'absent' => absent,
  84. default => 'file',
  85. },
  86. content => template('nginx/mailhost/mailhost.erb'),
  87. notify => Class['nginx::service'],
  88. }
  89. }
  90. # Create SSL File Stubs if SSL is enabled
  91. if ($ssl) {
  92. file { "${nginx::config::nx_temp_dir}/nginx.mail.d/${name}-700-ssl":
  93. ensure => $ensure ? {
  94. 'absent' => absent,
  95. default => 'file',
  96. },
  97. content => template('nginx/mailhost/mailhost_ssl.erb'),
  98. notify => Class['nginx::service'],
  99. }
  100. }
  101. }