# Base class class nginx::base { # Setup packages package { "nginx": ensure => installed, } # Config folders, see http://projects.reductivelabs.com/issues/86 file { [ "/etc/nginx", "/etc/nginx/sites-available", "/etc/nginx/sites-enabled" ]: ensure => directory, owner => "root", group => "root", } # Caching file { [ '/var/cache', '/var/cache/nginx' ]: ensure => directory, } service { "nginx": enable => true, ensure => running, hasrestart => true, require => [ Package["nginx"], File['/var/cache/nginx'] ], } define site($ensure = present, $source = 'file') { # Proxy config file case $source { 'file': { file { "/etc/nginx/sites-available/$name": source => "puppet:///modules/site_nginx/$name", owner => "root", group => "root", mode => 0644, ensure => $ensure, notify => Service["nginx"], require => File["/etc/nginx/sites-available"], } } 'template': { file { "/etc/nginx/sites-available/$name": content => template("nginx/$name.erb"), owner => "root", group => "root", mode => 0644, ensure => $ensure, notify => Service["nginx"], require => File["/etc/nginx/sites-available"], } } 'none': { file { "/etc/nginx/sites-available/$name": owner => "root", group => "root", mode => 0644, ensure => $ensure, notify => Service["nginx"], require => File["/etc/nginx/sites-available"], } } } $link = $ensure ? { present => "/etc/nginx/sites-available/$name", default => absent, } # Symlink to enable proxy configuration file { "/etc/nginx/sites-enabled/$name": ensure => $link, require => File["/etc/nginx/sites-enabled"], notify => Service["nginx"], } } # Main configuration file { "/etc/nginx/nginx.conf": content => template("nginx/nginx.conf.erb"), owner => "root", group => "root", mode => 0644, ensure => present, notify => Service["nginx"], } }