|
33 | 33 | # ssl_key => '/tmp/server.pem', |
34 | 34 | # } |
35 | 35 | define nginx::resource::vhost( |
36 | | - $ensure = 'present', |
| 36 | + $ensure = present, |
37 | 37 | $listen_ip = '*', |
38 | 38 | $listen_port = '80', |
39 | 39 | $ipv6_enable = false, |
|
63 | 63 | mode => '0644', |
64 | 64 | require => Package['nginx'] |
65 | 65 | } |
| 66 | + |
| 67 | + include nginx |
66 | 68 | include concat::setup |
67 | | - concat { "${nginx::config_dir}/sites-available/${name}.conf": |
68 | | - } |
69 | 69 |
|
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: { } |
76 | 93 | } |
77 | 94 |
|
| 95 | + |
| 96 | + concat { $file_real: } |
| 97 | + |
78 | 98 | # Add IPv6 Logic Check - Nginx service will not start if ipv6 is enabled |
79 | 99 | # and support does not exist for it in the kernel. |
80 | | - if ($ipv6_enable == 'true') and ($ipaddress6) { |
| 100 | + if ($ipv6_enable == true) and ($ipaddress6) { |
81 | 101 | warning('nginx: IPv6 support is not enabled or configured properly') |
82 | 102 | } |
83 | 103 |
|
|
91 | 111 | # Use the File Fragment Pattern to construct the configuration files. |
92 | 112 | # Create the base configuration file reference. |
93 | 113 | concat::fragment { "${name}+01.tmp": |
94 | | - order => '01', |
95 | | - content => template("${template_header}"), |
96 | 114 | ensure => $ensure, |
| 115 | + order => '01', |
| 116 | + content => template($template_header), |
97 | 117 | notify => $nginx::manage_service_autorestart, |
98 | | - target => "${nginx::config_dir}/sites-available/${name}.conf", |
| 118 | + target => $file_real, |
99 | 119 | } |
100 | 120 |
|
101 | 121 | # Create the default location reference for the vHost |
|
116 | 136 |
|
117 | 137 | # Create a proper file close stub. |
118 | 138 | concat::fragment { "${name}+69.tmp": |
119 | | - order => '69', |
120 | | - content => template("${template_footer}"), |
121 | 139 | ensure => $ensure, |
| 140 | + order => '69', |
| 141 | + content => template($template_footer), |
122 | 142 | notify => $nginx::manage_service_autorestart, |
123 | | - target => "${nginx::config_dir}/sites-available/${name}.conf", |
| 143 | + target => $file_real, |
124 | 144 | } |
125 | 145 |
|
126 | 146 | # Create SSL File Stubs if SSL is enabled |
127 | 147 | concat::fragment { "${name}+70-ssl.tmp": |
128 | | - order => '70', |
129 | | - content => template("${template_ssl_header}"), |
130 | 148 | ensure => $ssl, |
| 149 | + order => '70', |
| 150 | + content => template($template_ssl_header), |
131 | 151 | notify => $nginx::manage_service_autorestart, |
132 | | - target => "${nginx::config_dir}/sites-available/${name}.conf", |
| 152 | + target => $file_real, |
133 | 153 | } |
134 | 154 | concat::fragment { "${name}+99-ssl.tmp": |
135 | | - order => '99', |
136 | | - content => template("${template_footer}"), |
137 | 155 | ensure => $ssl, |
| 156 | + order => '99', |
| 157 | + content => template($template_footer), |
138 | 158 | notify => $nginx::manage_service_autorestart, |
139 | | - target => "${nginx::config_dir}/sites-available/${name}.conf", |
| 159 | + target => $file_real, |
140 | 160 | } |
141 | 161 | } |
0 commit comments