init.pp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. # Class: nginx
  2. #
  3. # This module manages NGINX.
  4. #
  5. # Parameters:
  6. #
  7. # Actions:
  8. #
  9. # Requires:
  10. # puppetlabs-stdlib - https://github.com/puppetlabs/puppetlabs-stdlib
  11. #
  12. # Packaged NGINX
  13. # - RHEL: EPEL or custom package
  14. # - Debian/Ubuntu: Default Install or custom package
  15. # - SuSE: Default Install or custom package
  16. #
  17. # stdlib
  18. # - puppetlabs-stdlib module >= 0.1.6
  19. # - plugin sync enabled to obtain the anchor type
  20. #
  21. # Sample Usage:
  22. #
  23. # The module works with sensible defaults:
  24. #
  25. # node default {
  26. # include nginx
  27. # }
  28. class nginx (
  29. ### START Nginx Configuration ###
  30. $client_body_buffer_size = undef,
  31. $client_body_temp_path = undef,
  32. $client_max_body_size = undef,
  33. $events_use = undef,
  34. $fastcgi_cache_inactive = undef,
  35. $fastcgi_cache_key = undef,
  36. $fastcgi_cache_keys_zone = undef,
  37. $fastcgi_cache_levels = undef,
  38. $fastcgi_cache_max_size = undef,
  39. $fastcgi_cache_path = undef,
  40. $fastcgi_cache_use_stale = undef,
  41. $gzip = undef,
  42. $http_cfg_append = undef,
  43. $http_tcp_nodelay = undef,
  44. $http_tcp_nopush = undef,
  45. $keepalive_timeout = undef,
  46. $mail = undef,
  47. $multi_accept = undef,
  48. $names_hash_bucket_size = undef,
  49. $names_hash_max_size = undef,
  50. $proxy_buffers = undef,
  51. $proxy_buffer_size = undef,
  52. $proxy_cache_inactive = undef,
  53. $proxy_cache_keys_zone = undef,
  54. $proxy_cache_levels = undef,
  55. $proxy_cache_max_size = undef,
  56. $proxy_cache_path = undef,
  57. $proxy_use_temp_path = undef,
  58. $proxy_connect_timeout = undef,
  59. $proxy_headers_hash_bucket_size = undef,
  60. $proxy_http_version = undef,
  61. $proxy_read_timeout = undef,
  62. $proxy_redirect = undef,
  63. $proxy_send_timeout = undef,
  64. $proxy_set_header = undef,
  65. $proxy_hide_header = undef,
  66. $sendfile = undef,
  67. $server_tokens = undef,
  68. $spdy = undef,
  69. $types_hash_bucket_size = undef,
  70. $types_hash_max_size = undef,
  71. $worker_connections = undef,
  72. $worker_processes = undef,
  73. $worker_rlimit_nofile = undef,
  74. ### END Nginx Configuration
  75. ### START Module/App Configuration ###
  76. $confd_purge = undef,
  77. $conf_dir = undef,
  78. $daemon_user = undef,
  79. $global_owner = undef,
  80. $global_group = undef,
  81. $global_mode = undef,
  82. $logdir = undef,
  83. $log_format = undef,
  84. $http_access_log = undef,
  85. $nginx_error_log = undef,
  86. $pid = undef,
  87. $proxy_temp_path = undef,
  88. $root_group = undef,
  89. $run_dir = undef,
  90. $sites_available_owner = undef,
  91. $sites_available_group = undef,
  92. $sites_available_mode = undef,
  93. $super_user = undef,
  94. $temp_dir = undef,
  95. $vhost_purge = undef,
  96. # Primary Templates
  97. $conf_template = undef,
  98. $proxy_conf_template = undef,
  99. ### END Module/App Configuration ###
  100. ### START Package Configuration ###
  101. $package_ensure = present,
  102. $package_name = $::nginx::params::package_name,
  103. $package_source = 'nginx',
  104. $package_flavor = undef,
  105. $manage_repo = $::nginx::params::manage_repo,
  106. ### END Package Configuration ###
  107. ### START Service Configuation ###
  108. $configtest_enable = false,
  109. $service_ensure = running,
  110. $service_flags = undef,
  111. $service_restart = '/etc/init.d/nginx reload',
  112. $service_name = undef,
  113. $service_manage = true,
  114. ### END Service Configuration ###
  115. ### START Hiera Lookups ###
  116. $geo_mappings = {},
  117. $string_mappings = {},
  118. $nginx_locations = {},
  119. $nginx_mailhosts = {},
  120. $nginx_upstreams = {},
  121. $nginx_vhosts = {},
  122. $nginx_vhosts_defaults = {},
  123. ### END Hiera Lookups ###
  124. ) inherits ::nginx::params {
  125. ### DEPRECATION WARNING ###
  126. ###
  127. ### During the transition from the params pattern -> puppet-module-data,
  128. ### we need a graceful way to notify the consumer that the pattern is
  129. ### changing, and point them toward docs on how to transition.
  130. ###
  131. ### Once we hit 1.0, this whole block goes away.
  132. ###
  133. ### Please note: as a contributor to this module, no Pulls will be accepted
  134. ### that do add additional parameters to this class. Get on this puppet-module-data
  135. ### level!
  136. ### This block makes me sad, but what can you do.... we need to do this
  137. ### migration the Right Way(tm) -- JDF
  138. if $client_body_buffer_size or
  139. $client_body_temp_path or
  140. $client_max_body_size or
  141. $confd_purge or
  142. $conf_dir or
  143. $conf_template or
  144. $daemon_user or
  145. $events_use or
  146. $fastcgi_cache_inactive or
  147. $fastcgi_cache_key or
  148. $fastcgi_cache_keys_zone or
  149. $fastcgi_cache_levels or
  150. $fastcgi_cache_max_size or
  151. $fastcgi_cache_path or
  152. $fastcgi_cache_use_stale or
  153. $gzip or
  154. $http_access_log or
  155. $http_cfg_append or
  156. $http_tcp_nodelay or
  157. $http_tcp_nopush or
  158. $keepalive_timeout or
  159. $logdir or
  160. $log_format or
  161. $mail or
  162. $multi_accept or
  163. $names_hash_bucket_size or
  164. $names_hash_max_size or
  165. $nginx_error_log or
  166. $pid or
  167. $proxy_buffers or
  168. $proxy_buffer_size or
  169. $proxy_cache_inactive or
  170. $proxy_cache_keys_zone or
  171. $proxy_cache_levels or
  172. $proxy_cache_max_size or
  173. $proxy_cache_path or
  174. $proxy_use_temp_path or
  175. $proxy_conf_template or
  176. $proxy_connect_timeout or
  177. $proxy_headers_hash_bucket_size or
  178. $proxy_http_version or
  179. $proxy_read_timeout or
  180. $proxy_redirect or
  181. $proxy_send_timeout or
  182. $proxy_set_header or
  183. $proxy_hide_header or
  184. $proxy_temp_path or
  185. $run_dir or
  186. $sendfile or
  187. $server_tokens or
  188. $spdy or
  189. $super_user or
  190. $temp_dir or
  191. $types_hash_bucket_size or
  192. $types_hash_max_size or
  193. $vhost_purge or
  194. $worker_connections or
  195. $worker_processes or
  196. $worker_rlimit_nofile or
  197. $global_owner or
  198. $global_group or
  199. $global_mode or
  200. $sites_available_owner or
  201. $sites_available_group or
  202. $sites_available_mode {
  203. include ::nginx::notice::config
  204. }
  205. ### END DEPRECATION WARNING ###
  206. class { '::nginx::package':
  207. package_name => $package_name,
  208. package_source => $package_source,
  209. package_ensure => $package_ensure,
  210. package_flavor => $package_flavor,
  211. notify => Class['::nginx::service'],
  212. manage_repo => $manage_repo,
  213. }
  214. ## This `if` statement is here in the event a user cannot use
  215. ## Hiera based parameter overrides. Will not be here in 1.0 release
  216. if !defined(Class['::nginx::config']) {
  217. class { '::nginx::config':
  218. client_body_buffer_size => $client_body_buffer_size,
  219. client_body_temp_path => $client_body_temp_path,
  220. client_max_body_size => $client_max_body_size,
  221. confd_purge => $confd_purge,
  222. conf_dir => $conf_dir,
  223. conf_template => $conf_template,
  224. daemon_user => $daemon_user,
  225. events_use => $events_use,
  226. fastcgi_cache_inactive => $fastcgi_cache_inactive,
  227. fastcgi_cache_key => $fastcgi_cache_key,
  228. fastcgi_cache_keys_zone => $fastcgi_cache_keys_zone,
  229. fastcgi_cache_levels => $fastcgi_cache_levels,
  230. fastcgi_cache_max_size => $fastcgi_cache_max_size,
  231. fastcgi_cache_path => $fastcgi_cache_path,
  232. fastcgi_cache_use_stale => $fastcgi_cache_use_stale,
  233. gzip => $gzip,
  234. http_access_log => $http_access_log,
  235. http_cfg_append => $http_cfg_append,
  236. http_tcp_nodelay => $http_tcp_nodelay,
  237. http_tcp_nopush => $http_tcp_nopush,
  238. keepalive_timeout => $keepalive_timeout,
  239. log_dir => $logdir,
  240. log_format => $log_format,
  241. mail => $mail,
  242. multi_accept => $multi_accept,
  243. names_hash_bucket_size => $names_hash_bucket_size,
  244. names_hash_max_size => $names_hash_max_size,
  245. nginx_error_log => $nginx_error_log,
  246. pid => $pid,
  247. proxy_buffers => $proxy_buffers,
  248. proxy_buffer_size => $proxy_buffer_size,
  249. proxy_cache_inactive => $proxy_cache_inactive,
  250. proxy_cache_keys_zone => $proxy_cache_keys_zone,
  251. proxy_cache_levels => $proxy_cache_levels,
  252. proxy_cache_max_size => $proxy_cache_max_size,
  253. proxy_cache_path => $proxy_cache_path,
  254. proxy_use_temp_path => $proxy_use_temp_path,
  255. proxy_conf_template => $proxy_conf_template,
  256. proxy_connect_timeout => $proxy_connect_timeout,
  257. proxy_headers_hash_bucket_size => $proxy_headers_hash_bucket_size,
  258. proxy_http_version => $proxy_http_version,
  259. proxy_read_timeout => $proxy_read_timeout,
  260. proxy_redirect => $proxy_redirect,
  261. proxy_send_timeout => $proxy_send_timeout,
  262. proxy_set_header => $proxy_set_header,
  263. proxy_hide_header => $proxy_hide_header,
  264. proxy_temp_path => $proxy_temp_path,
  265. run_dir => $run_dir,
  266. sendfile => $sendfile,
  267. server_tokens => $server_tokens,
  268. spdy => $spdy,
  269. super_user => $super_user,
  270. temp_dir => $temp_dir,
  271. types_hash_bucket_size => $types_hash_bucket_size,
  272. types_hash_max_size => $types_hash_max_size,
  273. vhost_purge => $vhost_purge,
  274. worker_connections => $worker_connections,
  275. worker_processes => $worker_processes,
  276. worker_rlimit_nofile => $worker_rlimit_nofile,
  277. global_owner => $global_owner,
  278. global_group => $global_group,
  279. global_mode => $global_mode,
  280. sites_available_owner => $sites_available_owner,
  281. sites_available_group => $sites_available_group,
  282. sites_available_mode => $sites_available_mode,
  283. }
  284. }
  285. Class['::nginx::package'] -> Class['::nginx::config'] ~> Class['::nginx::service']
  286. class { '::nginx::service':
  287. configtest_enable => $configtest_enable,
  288. service_ensure => $service_ensure,
  289. service_restart => $service_restart,
  290. service_name => $service_name,
  291. service_flags => $service_flags,
  292. service_manage => $service_manage,
  293. }
  294. create_resources('nginx::resource::upstream', $nginx_upstreams)
  295. create_resources('nginx::resource::vhost', $nginx_vhosts, $nginx_vhosts_defaults)
  296. create_resources('nginx::resource::location', $nginx_locations)
  297. create_resources('nginx::resource::mailhost', $nginx_mailhosts)
  298. create_resources('nginx::resource::map', $string_mappings)
  299. create_resources('nginx::resource::geo', $geo_mappings)
  300. # Allow the end user to establish relationships to the "main" class
  301. # and preserve the relationship to the implementation classes through
  302. # a transitive relationship to the composite class.
  303. anchor{ 'nginx::begin':
  304. before => Class['::nginx::package'],
  305. notify => Class['::nginx::service'],
  306. }
  307. anchor { 'nginx::end':
  308. require => Class['::nginx::service'],
  309. }
  310. }