Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support map blocks #258

Closed
tmont opened this issue Feb 15, 2014 · 3 comments
Closed

Support map blocks #258

tmont opened this issue Feb 15, 2014 · 3 comments

Comments

@tmont
Copy link

tmont commented Feb 15, 2014

There doesn't seem to be a way to accomplish outputting something like this in nginx.conf:

map $http_accept $foo {
  default /foo.html;
  ~application/json /foo.json;
}

Using http_cfg_append puts an extra semicolon after the closing }.

@tmont
Copy link
Author

tmont commented Feb 15, 2014

This is the extraordinarily ghetto way I hacked around it:

diff --git a/manifests/config.pp b/manifests/config.pp
index 4aae9e2..c2c2054 100644
--- a/manifests/config.pp
+++ b/manifests/config.pp
@@ -35,6 +35,7 @@ class nginx::config(
   $nginx_error_log        = $nginx::params::nx_nginx_error_log,
   $http_access_log        = $nginx::params::nx_http_access_log,
   $proxy_buffer_size      = $nginx::params::nx_proxy_buffer_size,
+  $blocks                 = [],
   $gzip                   = $nginx::params::nx_gzip,
 ) inherits nginx::params {

diff --git a/manifests/init.pp b/manifests/init.pp
index 4bc00eb..e7b4387 100644
--- a/manifests/init.pp
+++ b/manifests/init.pp
@@ -59,6 +59,7 @@ class nginx (
   $nginx_upstreams        = {},
   $nginx_locations        = {},
   $manage_repo            = $nginx::params::manage_repo,
+  $blocks                 = [],
 ) inherits nginx::params {

   include stdlib
@@ -136,6 +137,7 @@ class nginx (
     nginx_error_log        => $nginx_error_log,
     http_access_log        => $http_access_log,
     gzip                   => $gzip,
+    blocks                 => $blocks,
     require                => Class['nginx::package'],
     notify                 => Class['nginx::service'],
   }
diff --git a/templates/conf.d/nginx.conf.erb b/templates/conf.d/nginx.conf.erb
index 1b8502e..8c0fcf1 100644
--- a/templates/conf.d/nginx.conf.erb
+++ b/templates/conf.d/nginx.conf.erb
@@ -39,6 +39,8 @@ http {
   proxy_cache_path    <%= @proxy_cache_path %> levels=<%= @proxy_cache_levels %> keys
 <% end -%>

+  <% Array(@blocks).each do |blockValue| %> <%= blockValue %><% end %>
+
 <% if @http_cfg_append -%><% @http_cfg_append.sort_by{|k,v| k}.each do |key,value| -%
   <%= key %> <%= value %>;
 <% end -%>

And then my nginx declaration looked like this:

class { 'nginx':
    blocks => [
'map $http_accept $error_doc {
    default /error.html;
    ~application/json /error.json;
  }']
}

@3flex
Copy link
Contributor

3flex commented Jul 21, 2014

Does #337 add what you need? If so you can close this issue.

@tmont
Copy link
Author

tmont commented Jul 21, 2014

@3flex Yeah, that looks like it should work. Closing.

@tmont tmont closed this as completed Jul 21, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants