Skip to content
This repository has been archived by the owner on Aug 13, 2024. It is now read-only.

Make it possible to add generic config blocks in sites and configs #2

Merged
merged 1 commit into from
Feb 4, 2014

Conversation

NBZ4live
Copy link
Contributor

@NBZ4live NBZ4live commented Feb 2, 2014

Sometimes you have to deal with configuration blocks like:

http {
...
upstream default {
server 127.0.0.1:8080 weight=10;
server 127.0.0.1:9090 weight=20;
...
}
...
server {
...
if ( condition ) {
...
}
...
location / {
...
}
...
}
}

This commits make it possible to add such blocks to the /etc/nginx/conf.d/.conf files generated by this role and to the /etc/nginx/sites-enabled/.conf

@jdauphant
Copy link
Owner

We could simplify and use syntax like :
https://gist.github.com/jdauphant/8777228

What do you think ?

@NBZ4live
Copy link
Contributor Author

NBZ4live commented Feb 3, 2014

It will work if you wrap it with quotation marks like

nginx_sites:
...
     - "location / {
          try_files $uri $uri/ /index.html;
       }"

but than the line breaks will be ignored and if you have multiple lines inside the block you will get something like:

geo $geo { default 0; 127.0.0.1/32 0; 192.168.178.121/32 0; };

If you have huge blocks, this will be not very good to read.

But I agree that the blocks solution is not the best. It can't handle block hierarchies and looks not the best way in the config. I'm thinking about utilizing macros in the future, but we still should find a way to separate simple lines and blocks in the var files for better consistency.

@jdauphant
Copy link
Owner

It's works without wrap in "" for me.
For the syntax you can cheat like in your template :

{% for v in item.server.vars %}
   {{ v.replace(";",";\n   ").replace("{","{\n      ") }}{% if v.find('{') == -1%} ;{% endif %} 
{% endfor %}

Now you have a beautiful output.

@NBZ4live
Copy link
Contributor Author

NBZ4live commented Feb 3, 2014

Ok done. Works pretty well now.

I squashed the previous commits.

@jdauphant
Copy link
Owner

Perfect :)

jdauphant added a commit that referenced this pull request Feb 4, 2014
Make it possible to add generic config blocks in sites and configs
@jdauphant jdauphant merged commit bf0cea7 into jdauphant:master Feb 4, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants