Skip to content

Commit 0ac1247

Browse files
committed
Merge pull request #34 from netmanagers/master
Modify nginx::resource::* to manage different distros
2 parents 65b3f42 + 60054cb commit 0ac1247

File tree

6 files changed

+76
-47
lines changed

6 files changed

+76
-47
lines changed

manifests/init.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@
147147
# Specified keepalive timeout. Default is 65(ms).
148148
#
149149
# [*client_max_body_size*]
150-
# Specified the max body size of client. Default is 10mb.
150+
# Specified the max body size of client. Default is 10mb.
151151
# Increase this param if your nginx is an upload server.
152152
#
153153
# [*service_status*]

manifests/params.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
$worker_connections = 1024
1919
$keepalive_timeout = 65
2020
$client_max_body_size = '10m'
21-
21+
2222
### Application related parameters
2323

2424
$package = $::operatingsystem ? {

manifests/resource/location.pp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
$template_proxy = 'nginx/vhost/vhost_location_proxy.erb',
4545
$template_directory = 'nginx/vhost/vhost_location_directory.erb',
4646
$template_redirect = 'nginx/vhost/vhost_location_redirect.erb',
47-
$location
47+
$location = $title,
4848
) {
4949
File {
5050
owner => 'root',
@@ -59,16 +59,21 @@
5959
default => file,
6060
}
6161

62+
$file_real = $::operatingsystem ? {
63+
/(?i:Debian|Ubuntu|Mint)/ => "${nginx::config_dir}/sites-available/${vhost}.conf",
64+
default => "${nginx::config_dir}/conf.d/${vhost}.conf",
65+
}
66+
6267
# Use proxy template if $proxy is defined, otherwise use directory template.
6368
if ($proxy != undef) {
64-
$content_real = template("${template_proxy}")
65-
$content_ssl_real = template("${template_ssl_proxy}")
69+
$content_real = template($template_proxy)
70+
$content_ssl_real = template($template_ssl_proxy)
6671
} else {
6772
if ($redirect != undef) {
68-
$content_real = template("${template_redirect}")
73+
$content_real = template($template_redirect)
6974
} else {
70-
$content_real = template("${template_directory}")
71-
$content_ssl_real = template("${template_directory}")
75+
$content_real = template($template_directory)
76+
$content_ssl_real = template($template_directory)
7277
}
7378
}
7479

@@ -91,10 +96,10 @@
9196

9297
## Create stubs for vHost File Fragment Pattern
9398
concat::fragment { "${vhost}+${location}+50.tmp":
94-
ensure => $ensure,
99+
ensure => $ensure_real,
95100
order => '50',
96101
content => $content_real,
97-
target => "${nginx::config_dir}/sites-available/${vhost}.conf",
102+
target => $file_real,
98103
}
99104

100105
if ($mixin_ssl) {
@@ -103,7 +108,7 @@
103108
ensure => $ssl,
104109
order => '80',
105110
content => $content_ssl_real,
106-
target => "${nginx::config_dir}/sites-available/${vhost}.conf",
111+
target => $file_real,
107112
}
108113
}
109114
}

manifests/resource/upstream.pp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,24 @@
2020
# ],
2121
# }
2222
define nginx::resource::upstream (
23+
$members,
2324
$ensure = 'present',
2425
$template_upstream = 'nginx/conf.d/upstream.erb',
25-
$members
2626
) {
2727
File {
2828
owner => 'root',
2929
group => 'root',
3030
mode => '0644',
3131
}
3232

33+
$real_file = $ensure ? {
34+
'absent' => absent,
35+
default => 'file',
36+
}
37+
3338
file { "${nginx::config_dir}/conf.d/${name}-upstream.conf":
34-
ensure => $ensure ? {
35-
'absent' => absent,
36-
default => 'file',
37-
},
38-
content => template("${template_upstream}"),
39+
ensure => $real_file,
40+
content => template($template_upstream),
3941
notify => $nginx::manage_service_autorestart,
4042
}
4143
}

manifests/resource/vhost.pp

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
# ssl_key => '/tmp/server.pem',
3434
# }
3535
define nginx::resource::vhost(
36-
$ensure = 'present',
36+
$ensure = present,
3737
$listen_ip = '*',
3838
$listen_port = '80',
3939
$ipv6_enable = false,
@@ -63,21 +63,41 @@
6363
mode => '0644',
6464
require => Package['nginx']
6565
}
66+
67+
include nginx
6668
include concat::setup
67-
concat { "${nginx::config_dir}/sites-available/${name}.conf":
68-
}
6969

70-
file { "${nginx::config_dir}/sites-enabled/${name}.conf":
71-
ensure => $ensure ? {
72-
'absent' => absent,
73-
default => 'link',
74-
},
75-
target => "${nginx::config_dir}/sites-available/${name}.conf",
70+
# Some OS specific settings:
71+
# On Debian/Ubuntu manages sites-enabled
72+
case $::operatingsystem {
73+
ubuntu,debian,mint: {
74+
$file_real = "${nginx::config_dir}/sites-available/${name}.conf"
75+
76+
$manage_file = $ensure ? {
77+
present => link,
78+
absent => absent,
79+
}
80+
81+
file { "${nginx::config_dir}/sites-enabled/${name}.conf":
82+
ensure => $manage_file,
83+
target => $file_real,
84+
require => [Package['nginx'], File[$file_real], ],
85+
notify => Service['nginx'],
86+
}
87+
}
88+
redhat,centos,scientific,fedora: {
89+
$file_real = "${nginx::config_dir}/conf.d/${name}.conf"
90+
# include nginx::redhat
91+
}
92+
default: { }
7693
}
7794

95+
96+
concat { $file_real: }
97+
7898
# Add IPv6 Logic Check - Nginx service will not start if ipv6 is enabled
7999
# and support does not exist for it in the kernel.
80-
if ($ipv6_enable == 'true') and ($ipaddress6) {
100+
if ($ipv6_enable == true) and ($ipaddress6) {
81101
warning('nginx: IPv6 support is not enabled or configured properly')
82102
}
83103

@@ -91,11 +111,11 @@
91111
# Use the File Fragment Pattern to construct the configuration files.
92112
# Create the base configuration file reference.
93113
concat::fragment { "${name}+01.tmp":
94-
order => '01',
95-
content => template("${template_header}"),
96114
ensure => $ensure,
115+
order => '01',
116+
content => template($template_header),
97117
notify => $nginx::manage_service_autorestart,
98-
target => "${nginx::config_dir}/sites-available/${name}.conf",
118+
target => $file_real,
99119
}
100120

101121
# Create the default location reference for the vHost
@@ -116,26 +136,26 @@
116136

117137
# Create a proper file close stub.
118138
concat::fragment { "${name}+69.tmp":
119-
order => '69',
120-
content => template("${template_footer}"),
121139
ensure => $ensure,
140+
order => '69',
141+
content => template($template_footer),
122142
notify => $nginx::manage_service_autorestart,
123-
target => "${nginx::config_dir}/sites-available/${name}.conf",
143+
target => $file_real,
124144
}
125145

126146
# Create SSL File Stubs if SSL is enabled
127147
concat::fragment { "${name}+70-ssl.tmp":
128-
order => '70',
129-
content => template("${template_ssl_header}"),
130148
ensure => $ssl,
149+
order => '70',
150+
content => template($template_ssl_header),
131151
notify => $nginx::manage_service_autorestart,
132-
target => "${nginx::config_dir}/sites-available/${name}.conf",
152+
target => $file_real,
133153
}
134154
concat::fragment { "${name}+99-ssl.tmp":
135-
order => '99',
136-
content => template("${template_footer}"),
137155
ensure => $ssl,
156+
order => '99',
157+
content => template($template_footer),
138158
notify => $nginx::manage_service_autorestart,
139-
target => "${nginx::config_dir}/sites-available/${name}.conf",
159+
target => $file_real,
140160
}
141161
}

manifests/vhost.pp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@
3737
include nginx::params
3838

3939
$real_owner = $owner ? {
40-
'' => "${nginx::config_file_owner}",
40+
'' => $nginx::config_file_owner,
4141
default => $owner,
4242
}
4343

4444
$real_groupowner = $groupowner ? {
45-
'' => "${nginx::config_file_group}",
45+
'' => $nginx::config_file_group,
4646
default => $groupowner,
4747
}
4848

@@ -58,15 +58,17 @@
5858
}
5959

6060
# Some OS specific settings:
61-
# On Debian/Ubuntu manages sites-enabled
61+
# On Debian/Ubuntu manages sites-enabled
6262
case $::operatingsystem {
6363
ubuntu,debian,mint: {
64-
file { "NginxVHostEnabled_$name":
64+
$manage_file = $enable ? {
65+
true => "${nginx::vdir}/${priority}-${name}.conf",
66+
false => absent,
67+
}
68+
69+
file { "NginxVHostEnabled_${name}":
70+
ensure => $manage_file,
6571
path => "/etc/nginx/sites-enabled/${priority}-${name}.conf",
66-
ensure => $enable ? {
67-
true => "${nginx::vdir}/${priority}-${name}.conf",
68-
false => absent,
69-
},
7072
require => Package['nginx'],
7173
notify => Service['nginx'],
7274
}

0 commit comments

Comments
 (0)