sous-chefs / nginx

Development repository for the nginx cookbook
https://supermarket.chef.io/cookbooks/nginx
Apache License 2.0
551 stars 810 forks source link

nginx_site `template` attribute isn't very useful #585

Closed Fuuzetsu closed 3 years ago

Fuuzetsu commented 3 years ago

:person_frowning: Problem Statement

There seems to be no nice way to not use the default provider templates for nginx_site while at the same time having any custom templates included in nginx sites. This is because templates only looks in the cookbook template location, not in the local recipe.

:grey_question: Possible Solution

:arrow_heading_up: Describe alternatives you've considered

Currently I'm writing stuff to /etc/nginx/conf.http.d via template manually, and creating list-custom.conf file in there listing each of these.

This is pretty manual and awful.

bmhughes commented 3 years ago
  1. Are you setting the cookbook property as well as the template one to override the template? As i'm doing this in my wrapper and it works as expected, picking the template up from the wrapper cookbook instead of this one. Unless i'm misunderstanding what you mean.

  2. What use cases are these configuration files that you wish to include? The cookbook and default nginx.conf config template creates and includes a generic conf.d directory if that suits your use case. I'm not saying it can't be added but the idea with this cookbook was that the included templates would probably be overriden for all but the simplest use cases so that may be the better route.

bmhughes commented 3 years ago

I've added a test kitchen case for overriding the template as it works as expected, the resource syntax needs to be like so:

nginx_site 'foo' do
  mode '0644'
  cookbook 'test' # <-- Cookbook to source from
  template 'override-site-template.erb' # <-- Template from above cookbook
  variables(
    'upstream' => {
      'bar' => {
        'server' => 'localhost:1234',
      },
    }
  )
  action :create
end
Fuuzetsu commented 3 years ago

I think cookbook attribute is exactly what I need. I will try it tomorrow and report back.

Fuuzetsu commented 3 years ago

I tried it today and it worked great. Thank you. I guess I should read more closely what attributes are available, sorry for the noise.