Skip to content

Commit 9bd63d3

Browse files
author
James Fryman
committed
Introducing Puppet Module Tool
1 parent d11d574 commit 9bd63d3

File tree

13 files changed

+452
-372
lines changed

13 files changed

+452
-372
lines changed

data/common.yaml

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
---
2+
nginx::config::temp_dir: /tmp
3+
nginx::config::run_dir: /var/nginx
4+
nginx::config::conf_template: nginx/conf.d/nginx.conf.erb
5+
nginx::config::proxy_conf_template: nginx/conf.d/proxy.conf.erb
6+
nginx::config::confd_purge: false
7+
nginx::config::vhost_purge: false
8+
nginx::config::worker_processes: 1
9+
nginx::config::worker_connections: 1024
10+
nginx::config::worker_rlimit_nofile: 1024
11+
nginx::config::types_hash_max_size: 1024
12+
nginx::config::types_hash_bucket_size: 512
13+
nginx::config::names_hash_bucket_size: 64
14+
nginx::config::names_hash_max_size: 512
15+
nginx::config::multi_accept: off
16+
nginx::config::events_use: false
17+
nginx::config::sendfile: on
18+
nginx::config::keepalive_timeout: 65
19+
nginx::config::http_tcp_nodelay: on
20+
nginx::config::http_tcp_nopush: off
21+
nginx::config::gzip: on
22+
nginx::config::server_tokens: on
23+
nginx::config::spdy: off
24+
nginx::config::ssl_stapling: off
25+
nginx::config::proxy_redirect: off
26+
nginx::config::proxy_set_header:
27+
- 'Host $host'
28+
- 'X-Real-IP $remote_addr'
29+
- 'X-Forwarded-For $proxy_add_x_forwarded_for'
30+
nginx::config::proxy_cache_path: false
31+
nginx::config::proxy_cache_levels: 1
32+
nginx::config::proxy_cache_keys_zone: 'd2:100m'
33+
nginx::config::proxy_cache_max_size: 500m
34+
nginx::config::proxy_cache_inactive: 20m
35+
nginx::config::fastcgi_cache_path: false
36+
nginx::config::fastcgi_cache_levels: 1
37+
nginx::config::fastcgi_cache_keys_zone: 'd3:100m'
38+
nginx::config::fastcgi_cache_max_size: 500m
39+
nginx::config::fastcgi_cache_inactive: 20m
40+
nginx::config::fastcgi_cache_key: false
41+
nginx::config::fastcgi_cache_use_stale: false
42+
nginx::config::client_body_temp_path: /var/nginx/client_body_temp
43+
nginx::config::client_body_buffer_size: 128k
44+
nginx::config::client_max_body_size: 10m
45+
nginx::config::proxy_temp_path: /var/nginx/proxy_temp
46+
nginx::config::proxy_connect_timeout: 90
47+
nginx::config::proxy_send_timeout: 90
48+
nginx::config::proxy_read_timeout: 90
49+
nginx::config::proxy_buffers: '32 4k'
50+
nginx::config::proxy_http_version: 1.0
51+
nginx::config::proxy_buffer_size: 8k
52+
nginx::config::proxy_headers_hash_bucket_size: 64
53+
nginx::config::logdir: /var/log/nginx
54+
55+
# Service restart after Nginx 0.7.53 could also be just
56+
# "/path/to/nginx/bin -s HUP" Some init scripts do a configtest, some don't.
57+
# If configtest_enable it's true then service restart will take
58+
# $nx_service_restart value, forcing configtest.
59+
nginx::config::configtest_enable: false
60+
nginx::config::service_restart: '/etc/init.d/nginx configtest && /etc/init.d/nginx restart'
61+
nginx::config::service_ensure: running
62+
63+
nginx::config::mail: false
64+
65+
nginx::config::http_cfg_append: false
66+
nginx::config::nginx_error_log: /var/log/nginx/error.log
67+
nginx::config::http_access_log: /var/log/nginx/access.log
68+
69+
# package name depends on distribution, e.g. for Debian nginx-full | nginx-light
70+
nginx::config::package_name: nginx
71+
nginx::config::package_ensure: present
72+
nginx::config::package_source: nginx
73+
nginx::config::manage_repo: true
74+
75+
nginx::config::root_group: root
76+
# Specific owner for sites-available directory
77+
nginx::config::sites_available_owner: root
78+
nginx::config::sites_available_group: root
79+
nginx::config::sites_available_mode: '0644'
80+
81+
# Owner for all other files
82+
nginx::config::global_owner: root
83+
nginx::config::global_group: root
84+
nginx::config::global_mode: '0644'
85+
86+
nginx::config::pid: /var/run/nginx.pid
87+
88+
nginx::config::conf_dir: /etc/nginx
89+
90+
nginx::config::super_user: true
91+
nginx::config::daemon_user: nginx

data/hiera.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
--
2+
:hierarchy:
3+
- osfamily/%{::osfamily}
4+
- kernelversion/%{::kernelversion}
5+
- kernel/%{::kernel}
6+
- common

data/kernelversion/Joyent.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
nginx::config::conf_dir: /opt/local/etc/nginx
3+
nginx::config::daemon_user: www

data/osfamily/Archlinux.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
nginx::config::pid: false
3+
nginx::config::daemon_user: http

data/osfamily/Debian.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
nginx::config::daemon_user: www-data

data/osfamily/FreeBSD.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
nginx::config::conf_dir: /usr/local/etc/nginx
3+
nginx::config::daemon_user: www
4+
nginx::config::root_group: wheel

data/osfamily/Solaris.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
nginx::config::daemon_user: webservd

docs/hiera.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Usage of Hiera
2+
3+
This module takes advantage of the `puppet-module-data` pattern as introduced
4+
by R.I. Pinnear to allow for a significant amount of flexibility with base
5+
configuration of the module. This is to reduce the amount of clutter starting
6+
to gather in `params.pp`, and provide a foundation for future enhancements.
7+
8+
## Upgrading
9+
10+
If you happen to be here because of some silly deprecation notice, it is
11+
probably because a manifest is declaring attributes for the Nginx Class.
12+
Upgrading should be easy!
13+
14+
* Step 1: Make sure you have Hiera configured. https://docs.puppetlabs.com/hiera/1/puppet.html#puppet-3-and-newer
15+
* Step 2: Move any declared parameters to hiera.
16+
* Step 3: Profit!
17+
18+
For example:
19+
20+
```
21+
class { 'nginx':
22+
logdir => '/data/nginx/logs',
23+
}
24+
```
25+
26+
should become in your hiera configs:
27+
28+
```
29+
nginx::config::logdir: /data/nginx/logs
30+
```
31+
32+
Please note: This module takes advantage of Puppet 3 data module bindings.
33+
Be aware of any gotchas that accompany this. Take a look at https://docs.puppetlabs.com/hiera/1/puppet.html#limitations

manifests/config.pp

Lines changed: 142 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -14,70 +14,149 @@
1414
#
1515
# This class file is not called directly
1616
class nginx::config(
17-
$client_body_buffer_size = $nginx::params::nx_client_body_buffer_size,
18-
$client_body_temp_path = $nginx::params::nx_client_body_temp_path,
19-
$client_max_body_size = $nginx::params::nx_client_max_body_size,
20-
$confd_purge = $nginx::params::nx_confd_purge,
21-
$conf_dir = $nginx::params::nx_conf_dir,
22-
$conf_template = $nginx::params::nx_conf_template,
23-
$daemon_user = $nginx::params::nx_daemon_user,
24-
$events_use = $nginx::params::nx_events_use,
25-
$fastcgi_cache_inactive = $nginx::params::nx_fastcgi_cache_inactive,
26-
$fastcgi_cache_key = $nginx::params::nx_fastcgi_cache_key,
27-
$fastcgi_cache_keys_zone = $nginx::params::nx_fastcgi_cache_keys_zone,
28-
$fastcgi_cache_levels = $nginx::params::nx_fastcgi_cache_levels,
29-
$fastcgi_cache_max_size = $nginx::params::nx_fastcgi_cache_max_size,
30-
$fastcgi_cache_path = $nginx::params::nx_fastcgi_cache_path,
31-
$fastcgi_cache_use_stale = $nginx::params::nx_fastcgi_cache_use_stale,
32-
$gzip = $nginx::params::nx_gzip,
33-
$http_access_log = $nginx::params::nx_http_access_log,
34-
$http_cfg_append = $nginx::params::nx_http_cfg_append,
35-
$http_tcp_nodelay = $nginx::params::nx_http_tcp_nodelay,
36-
$http_tcp_nopush = $nginx::params::nx_http_tcp_nopush,
37-
$keepalive_timeout = $nginx::params::nx_keepalive_timeout,
38-
$logdir = $nginx::params::nx_logdir,
39-
$mail = $nginx::params::nx_mail,
40-
$multi_accept = $nginx::params::nx_multi_accept,
41-
$names_hash_bucket_size = $nginx::params::nx_names_hash_bucket_size,
42-
$names_hash_max_size = $nginx::params::nx_names_hash_max_size,
43-
$nginx_error_log = $nginx::params::nx_nginx_error_log,
44-
$pid = $nginx::params::nx_pid,
45-
$proxy_buffers = $nginx::params::nx_proxy_buffers,
46-
$proxy_buffer_size = $nginx::params::nx_proxy_buffer_size,
47-
$proxy_cache_inactive = $nginx::params::nx_proxy_cache_inactive,
48-
$proxy_cache_keys_zone = $nginx::params::nx_proxy_cache_keys_zone,
49-
$proxy_cache_levels = $nginx::params::nx_proxy_cache_levels,
50-
$proxy_cache_max_size = $nginx::params::nx_proxy_cache_max_size,
51-
$proxy_cache_path = $nginx::params::nx_proxy_cache_path,
52-
$proxy_conf_template = $nginx::params::nx_proxy_conf_template,
53-
$proxy_connect_timeout = $nginx::params::nx_proxy_connect_timeout,
54-
$proxy_headers_hash_bucket_size = $nginx::params::nx_proxy_headers_hash_bucket_size,
55-
$proxy_http_version = $nginx::params::nx_proxy_http_version,
56-
$proxy_read_timeout = $nginx::params::nx_proxy_read_timeout,
57-
$proxy_redirect = $nginx::params::nx_proxy_redirect,
58-
$proxy_send_timeout = $nginx::params::nx_proxy_send_timeout,
59-
$proxy_set_header = $nginx::params::nx_proxy_set_header,
60-
$proxy_temp_path = $nginx::params::nx_proxy_temp_path,
61-
$run_dir = $nginx::params::nx_run_dir,
62-
$sendfile = $nginx::params::nx_sendfile,
63-
$server_tokens = $nginx::params::nx_server_tokens,
64-
$spdy = $nginx::params::nx_spdy,
65-
$super_user = $nginx::params::nx_super_user,
66-
$temp_dir = $nginx::params::nx_temp_dir,
67-
$types_hash_bucket_size = $nginx::params::nx_types_hash_bucket_size,
68-
$types_hash_max_size = $nginx::params::nx_types_hash_max_size,
69-
$vhost_purge = $nginx::params::nx_vhost_purge,
70-
$worker_connections = $nginx::params::nx_worker_connections,
71-
$worker_processes = $nginx::params::nx_worker_processes,
72-
$worker_rlimit_nofile = $nginx::params::nx_worker_rlimit_nofile,
73-
$global_owner = $nginx::params::global_owner,
74-
$global_group = $nginx::params::global_group,
75-
$global_mode = $nginx::params::global_mode,
76-
$sites_available_owner = $nginx::params::sites_available_owner,
77-
$sites_available_group = $nginx::params::sites_available_group,
78-
$sites_available_mode = $nginx::params::sites_available_mode,
79-
) inherits nginx::params {
17+
$client_body_buffer_size = undef,
18+
$client_body_temp_path = undef,
19+
$client_max_body_size = undef,
20+
$confd_purge = undef,
21+
$conf_dir = undef,
22+
$conf_template = undef,
23+
$daemon_user = undef,
24+
$events_use = undef,
25+
$fastcgi_cache_inactive = undef,
26+
$fastcgi_cache_key = undef,
27+
$fastcgi_cache_keys_zone = undef,
28+
$fastcgi_cache_levels = undef,
29+
$fastcgi_cache_max_size = undef,
30+
$fastcgi_cache_path = undef,
31+
$fastcgi_cache_use_stale = undef,
32+
$gzip = undef,
33+
$http_access_log = undef,
34+
$http_cfg_append = undef,
35+
$http_tcp_nodelay = undef,
36+
$http_tcp_nopush = undef,
37+
$keepalive_timeout = undef,
38+
$logdir = undef,
39+
$mail = undef,
40+
$multi_accept = undef,
41+
$names_hash_bucket_size = undef,
42+
$names_hash_max_size = undef,
43+
$nginx_error_log = undef,
44+
$pid = undef,
45+
$proxy_buffers = undef,
46+
$proxy_buffer_size = undef,
47+
$proxy_cache_inactive = undef,
48+
$proxy_cache_keys_zone = undef,
49+
$proxy_cache_levels = undef,
50+
$proxy_cache_max_size = undef,
51+
$proxy_cache_path = undef,
52+
$proxy_conf_template = undef,
53+
$proxy_connect_timeout = undef,
54+
$proxy_headers_hash_bucket_size = undef,
55+
$proxy_http_version = undef,
56+
$proxy_read_timeout = undef,
57+
$proxy_redirect = undef,
58+
$proxy_send_timeout = undef,
59+
$proxy_set_header = undef,
60+
$proxy_temp_path = undef,
61+
$run_dir = undef,
62+
$sendfile = undef,
63+
$server_tokens = undef,
64+
$spdy = undef,
65+
$super_user = undef,
66+
$temp_dir = undef,
67+
$types_hash_bucket_size = undef,
68+
$types_hash_max_size = undef,
69+
$vhost_purge = undef,
70+
$worker_connections = undef,
71+
$worker_processes = undef,
72+
$worker_rlimit_nofile = undef,
73+
$global_owner = undef,
74+
$global_group = undef,
75+
$global_mode = undef,
76+
$sites_available_owner = undef,
77+
$sites_available_group = undef,
78+
$sites_available_mode = undef,
79+
) {
8080

81+
### Validations ###
82+
if (!is_string($worker_processes)) and (!is_integer($worker_processes)) {
83+
fail('$worker_processes must be an integer or have value "auto".')
84+
}
85+
if (!is_integer($worker_connections)) {
86+
fail('$worker_connections must be an integer.')
87+
}
88+
if (!is_integer($worker_rlimit_nofile)) {
89+
fail('$worker_rlimit_nofile must be an integer.')
90+
}
91+
if (!is_string($events_use)) and ($events_use != false) {
92+
fail('$events_use must be a string or false.')
93+
}
94+
validate_string($multi_accept)
95+
validate_string($package_name)
96+
validate_string($package_ensure)
97+
validate_string($package_source)
98+
validate_array($proxy_set_header)
99+
validate_string($proxy_http_version)
100+
validate_bool($confd_purge)
101+
validate_bool($vhost_purge)
102+
if ($proxy_cache_path != false) {
103+
validate_string($proxy_cache_path)
104+
}
105+
validate_re($proxy_cache_levels, '^[12](:[12])*$')
106+
validate_string($proxy_cache_keys_zone)
107+
validate_string($proxy_cache_max_size)
108+
validate_string($proxy_cache_inactive)
109+
110+
if ($fastcgi_cache_path != false) {
111+
validate_string($fastcgi_cache_path)
112+
}
113+
validate_re($fastcgi_cache_levels, '^[12](:[12])*$')
114+
validate_string($fastcgi_cache_keys_zone)
115+
validate_string($fastcgi_cache_max_size)
116+
validate_string($fastcgi_cache_inactive)
117+
if ($fastcgi_cache_key != false) {
118+
validate_string($fastcgi_cache_key)
119+
}
120+
if ($fastcgi_cache_use_stale != false) {
121+
validate_string($fastcgi_cache_use_stale)
122+
}
123+
124+
validate_bool($configtest_enable)
125+
validate_string($service_restart)
126+
validate_bool($mail)
127+
validate_string($server_tokens)
128+
validate_string($client_max_body_size)
129+
if (!is_integer($names_hash_bucket_size)) {
130+
fail('$names_hash_bucket_size must be an integer.')
131+
}
132+
if (!is_integer($names_hash_max_size)) {
133+
fail('$names_hash_max_size must be an integer.')
134+
}
135+
validate_string($proxy_buffers)
136+
validate_string($proxy_buffer_size)
137+
if ($http_cfg_append != false) {
138+
if !(is_hash($http_cfg_append) or is_array($http_cfg_append)) {
139+
fail('$http_cfg_append must be either a hash or array')
140+
}
141+
}
142+
143+
validate_string($nginx_error_log)
144+
validate_string($http_access_log)
145+
validate_hash($nginx_upstreams)
146+
validate_hash($nginx_vhosts)
147+
validate_hash($nginx_vhosts_defaults)
148+
validate_hash($nginx_locations)
149+
validate_hash($nginx_mailhosts)
150+
validate_bool($manage_repo)
151+
validate_string($proxy_headers_hash_bucket_size)
152+
validate_bool($super_user)
153+
154+
validate_hash($string_mappings)
155+
validate_hash($geo_mappings)
156+
### END VALIDATIONS ###
157+
158+
159+
### CONFIGURATION ###
81160
File {
82161
owner => $global_owner,
83162
group => $global_group,

0 commit comments

Comments
 (0)